Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print all coordinates inside the Contour opencv

Tags:

opencv

contour

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

like image 669
kcc__ Avatar asked Dec 27 '22 02:12

kcc__


2 Answers

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.

like image 64
baci Avatar answered Dec 28 '22 20:12

baci


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.

like image 23
cyriel Avatar answered Dec 28 '22 19:12

cyriel