Prerequisite: Geometric shapes using OpenCV
Given three vertices of a triangle, write a Python program to find the centroid of the triangle and then draw the triangle with its centroid on a black window using OpenCV.
Input: (100, 200) (50, 50) (300, 100) Output: (150, 116)
Create a black window with three color channels with resolution 400 x 300. Draw three lines which are passing through the given points using the inbuilt line function of the OpenCV. It will create a triangle on the black window. Find the centroid of the triangle using the following simple formula.
Draw this centroid on the black window using circle function of OpenCV with zero thickness.
Below is the implementation of the above approach:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Draw geometric shapes on images using OpenCV
- Find and Draw Contours using OpenCV | Python
- Draw a rectangular shape and extract objects using Python's OpenCV
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- ML - Nearest Centroid Classifier
- Transition from OpenCV 2 to OpenCV 3.x
- Draw Spiraling Triangle using Turtle in Python
- Draw a triangle using Arcade in Python
- Python | Create video using multiple images using OpenCV
- Image resizing using Seam carving using OpenCV in Python
- Draw Circle in Python using Turtle
- Draw Sweden Flag using matlab
- How to draw Japan flag using MATLAB
- Draw Kuwait Flag using MATLAB
- Draw Sudan Flag using MATLAB
- Draw Indian Flag using matlab
- Draw Control Flow Graph using pycfg | Python
- Draw a unstructured triangular grid as lines or markers in Python using Matplotlib
- Draw Cube and Cuboid in Python using Turtle
- Draw Shape inside Shape in Python Using Turtle
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.