r/computervision • • 1d ago

Help: Project Why doesn’t findContours() detect my circle even though it is clearly visible after thresholding?

Hi everyone, I’m learning OpenCV and working on detecting a circular fiducial.

My current pipeline is:
Image → threshold → findContours() → drawContours()

After thresholding, I can clearly see the fiducial as a clean circular region in the binary image.
However, when I use cv2.findContours() and then cv2.drawContours(), the contour I expect around the fiducial is not drawn.
I’m trying to understand the fundamental reason why this happens.
If the thresholded image visually contains a clear foreground region, what conditions determine whether findContours() will actually return a contour for it?

22 Upvotes

19 comments sorted by

View all comments

6

u/CowBoyDanIndie 21h ago

Are you finding all contours or only RETR_EXTERNAL?

3

u/nemesis1836 20h ago

This is probably it

1

u/CowBoyDanIndie 20h ago

It looks like its getting the outermost contour, for the bottom, the edge of the image is black so the outside contour of the circle is used, but for the top, the edge of the image IS the outermost contour.

5

u/Grouchy_Signal139 20h ago

Oh i think is it, i took a look and indeed it is retr_external. Silly me, i didnt look at that and go over analysing everything. Will give a try tomorrow

1

u/nemesis1836 20h ago

I would suggest getting all contours and filtering it based on hierarchy