Find Co-ordinates of Contours using OpenCV | Python
In this article, we will learn how to find the co-ordinates of Contours with the help of OpenCV. Contours are defined as the line joining all the points along the boundary of an image that are having the same intensity. Contours come handy in shape analysis, finding the size of the object of interest, and object detection.
We will be using OpenCV
findContour() function that helps in extracting the contours from the image.
The Co-ordinates of each vertices of a contour is hidden in the contour itself. In this approach, we will be using numpy library to convert all the co-ordinates of a contour into a linear array. This linear array would contain the x and y co-ordinates of each contour. The key point here is that the first co-ordinate in the array would always be the co-ordinate of the topmost vertex and hence could help in detection of orientation of an image.
In the following code, we will be using an image named ‘test.jpg’ to find contours and print the co-ordinates of the vertices on the image itself.