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.
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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course