I am trying to use findcontours() function in OpenCV on the image below.
findContours(img, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE, cvPoint(0,0) );
When I do this query: contours.size()
it returns 18, so that seems 2 contour for each circle. The circles are as you can see 1-pixel thick, how is it 2 contours? Is it one for outer and one for inner, if so, how can I force this function to detect just one contour for each circle? I thought a contour was defined as a connected sequence of pixels, 1 pixel thick.
I can't confirm this, but i think the algorithm used by this function does something equivalent to computing the gradient for each function. Which means that there will be a contour found on the outer edge and one on the inner edge, just like you suggested. To confirm this, You can try to use an input image where the circles have been filled with white (elimininating the inner contour)
you can also test with different parameters on the findContours function
For example, try using CV_RETR_EXTERNAL instead of CV_RETR_TREE I assume the inner circle is nested within the outer one, so this should force it to return only the outer ones
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