Circle detection with HoughCircles v3.1.0

asked 2016-10-15 08:02:45 -0500

MatsW gravatar image

I'm experimenting with the sample code at , but I'm can't figure out how to use HoughCircles to detect circles in a fairly simple test. I've created I png-file with Paint containing 3 black circles (see below). 2 with approximately the same center, and one with an offset. The input file is only black&white. But when I run the demo I can see that it can't detect the outmost circle at all, it detects the second circle, and the third circle is detected but with slightly incorrect radius and center.

1) Any clue why it can't detect the outermost circle ? 2) Any clue why the 3rd circle is offset?

I've also seen that HoughCircles() has a parameter

minDist – Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed.

The odd thing is that this sort of says that several circles with the same center but different radius can't be detected, thus invalidating my testcase. Is it so?

image description

edit retag flag offensive close merge delete


I've also tested the shoe-image in link text , but have not been able to reproduce the result shown in the Wiki-article

MatsW gravatar imageMatsW ( 2016-10-15 10:41:25 -0500 )edit

cv::HoughCircles uses gradients for detecting. In a b/w image there are not that much gradients. You could blur your b/w image before HoughCircles.

Finding coaxial circles is difficult, because minDist (Minimum distance between centers) must be greater than 0 and with a small value you get a lot of found circles for a single real circle.

Currently I have made a pull request where you can specify the maximum number of circles returned. If you know the number, you can set minDist to 1 or smaller and maxCircles to 3, but it is possible that you get 2 circles for one real circle and non for the other one, so try it out and give me some feedback.

matman gravatar imagematman ( 2016-10-16 05:14:10 -0500 )edit