I am working with image contour detection. I can easily print the contour coordinates but I am interested in printing the coordinates of all the pixels inside the contour. for example if I get a contour of 4 x 4 pixel than i want to print not just the contour but all the coordiantes of the pixels it encloses in opencv
1- use findContours to extract the contours of your image. (convert your image to grayscale, apply binary threshold and canny edge detection before, for better results.)
2- select a contour (filter by area, shape, moments etc.)
3- use pointPolygonTest for all points, to check and save if they are inside the specified contour.
I'm not sure what you are trying to do:
- draw filled contour
- get coordinates of contour and all points inside it
If you are interested only in drawing just use drawContour
function and set parameter thickness
to -1
. It will draw contour and all points inside it.
I'm not sure whether in opencv it's possible to just get all points lying inside some contour - you can write this on your own or just draw filled contour and get all non-black points from image (just use simple loop). It's not very effective solution, but should work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With