Contour Detection with Custom Seeds using Python – OpenCV
This article discusses how we can dynamically detect contours by clicking on the Image and assign different colors to different parts of the image. Contours are a very useful tool for shape analysis and object detection and recognition. This program uses OpenCV, Numpy, and Matplotlib libraries. It also uses a built-in OpenCV Watershed algorithm to detect contours.
- Python and OpenCV must be installed on the local machine.
- Install Jupyter Notebook for easy debugging.
- Here, Matplotlib’s colormap is used to get different colors. In the example given below, we will be using tab10. You can choose different colormaps. Refer to this site for different colors.
- Run the program.
- Click on the image where you want to make contours.
- Select a different color for a different part of the image by pressing numbers from zero to nine. (One number for one color)
Below is the Implementation.
This code will open two windows. One with the original image and one black. Clicking on the original image will create small circles on it and the contours will show on the black image. (Press numbers from 0-9 to change colors and produce a different contour plot.)
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