简体   繁体   中英

OpenCV: HoughCircles returns invalid circle parameters

I'm using "OpenCV Version: 3.4.0" with Python 3.6 and the Spyder IDE (Spyder 3.2.4) on Anaconda Navigator.

When I call HoughCircles() with these parameters, it returns invalid circle data:

=====================================================================
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.8, 30, 10, 310,minRadius = 35, maxRadius = 255)

len(circles): 4
circles: [[10.][ 0.][ 0.][ 0.]]
=====================================================================

When I call HoughCircles() with these parameters, it returns valid circle data:

=====================================================================
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.8, 30, 10, 300,minRadius = 35, maxRadius = 255)

len(circles): 1
circles: [[[319.5 571.5 251. ]]]
=====================================================================

Why does HoughCircles() returns invalid data under some circumstances? Shouldn't the function return some type of error code, or maybe "None"?

I ran into something similar in C++ where HoughCircles() would return a list with a single [0,0,0] in it for certain images. The root cause was a bug in the RemoveOverlaps() method in OpenCV. Here is the bug report that I wrote:
https://github.com/opencv/opencv/issues/14432

This same issue also appears to affect Python, as described in this question:
OpenCV HoughCircles occasionally returning [0. 0. 0.]

You might try manually building a version of OpenCV with the patch applied to see if that helps (or a future release like 3.4.7 or 4.2.0). However, since you are getting [[10][0][0][0]] instead of [[[0 0 0]]], I think you are probably running into a different bug than I was. If so, I would suggest filing a new bug report about it.

Finally, whenever posting about computer vision, it is a good idea to include the image file that you are testing with, as it will be impossible to reproduce the issue without it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM