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.