Given the three vertices of a triangle, write a Python program to find the centroid of a triangle, and then draw a triangle with its centroid in a black window using OpenCV.
Examples:
Input: (100, 200) (50, 50) (300, 100) Output: (150, 116)
Required Libraries:
OpenCV Numpy
Fit:
Create a black window with three color channels at 400x 300. Draw three lines that go through the specified points using the built-in OpenCV lines feature. This will create a triangle on the black window. Find the center of gravity of a triangle using the following simple formula.
Draw this centroid on a black window using the circle OpenCV with zero thickness.
Below is the implementation of the above approach:
# image - window title |
Exit:
(150, 116)