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:
- Draw geometric shapes on images using OpenCV
- Find and Draw Contours using OpenCV | Python
- Python | Draw rectangular shape and extract objects using OpenCV
- Python PIL | ImageDraw.Draw.arc()
- Draw Kuwait Flag using MATLAB
- Draw Sudan Flag using MATLAB
- Draw Indian Flag using matlab
- Python PIL | ImageDraw.Draw.line()
- Python PIL | ImageDraw.Draw.text()
- Python PIL |ImageDraw.Draw.multiline_text()
- Python PIL | ImageDraw.Draw.rectangle()
- Python PIL | ImageDraw.Draw.pieslice()
- Python PIL | ImageDraw.Draw.multiline_textsize()
- Python PIL | ImageDraw.Draw.chord()
- Python PIL | ImageDraw.Draw.ellipse()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.