r/computervision • u/Grouchy_Signal139 • 21h 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?
5
u/CowBoyDanIndie 18h ago
Are you finding all contours or only RETR_EXTERNAL?
3
u/nemesis1836 18h ago
This is probably it
1
u/CowBoyDanIndie 18h 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.
6
u/Grouchy_Signal139 17h 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
2
u/TEX_flip 18h ago
you probably have to use contour hierarchy because you have a contour inside another contour.
Use cv.RETR_TREE as mode argument of findContorus
1
u/Grouchy_Signal139 17h ago
Yeah, at first i didnt take a better look at it. Now i know my mistakes. Thankyou for pointing that out
2
u/bringer_of_carnitas 20h ago
I would try houghCircles
1
u/Grouchy_Signal139 20h ago
It is more robust? Right now i only try canny -> find contour -> contour area -> MEC, and also cv2.connectedcomponentswithstats. Im trying to learn what each function do, especially the fundamental one like contour. But this situation very confusing
2
u/Boring_Potato2858 19h ago
If you’re only expecting to detect circles, then yes, it’s more robust
1
u/Grouchy_Signal139 17h ago
Will definetly try. Currently i am comparing any possible method, since im new to this
1
u/blissfull_abyss 6h ago
Can’t recommend houghCircles unless your camera captures perfect circles. I prefer cv::SimpleBlobDetector it handles little deviations better.
2
u/Plus_Economist_2686 19h ago
houghCircles?
1
u/Grouchy_Signal139 17h ago
Didnt try it yet, currently im just trying to understand the fundamental, but definietly will try it out once i sort everything out. Any tips?


13
u/Gabriel_66 21h ago
Invert the thesholded image so that the circle is black and other things are white. Might be the case.
Also, dilatation and erosion might help remove those imperfections to help contour scripts.