Repository navigation
Description
System information (version)
- OpenCV => 4.0.1 (precompiled binary distributed by homebrew)
- Operating System / Platform => macOS Mojave 10.14.4
- Compiler => clang 10.0.0
Detailed description
When running HoughCircles on a series of images, it usually works well, but sometimes it will return a single value of [0,0,0] instead of the actual result. I receive an empty vector back on images where no circles are found, so I suspect that a circle was indeed detected, but there was an internal bug. Unless there is an (undocumented) reason, HoughCircles should return the actual result instead of [0,0,0].
I am calling HoughCircles with a 480x640 CV_8UC1 image (either generated or loaded from a PNG using IMREAD_GRAYSCALE). Full source code is attached, but the call to HoughCircles is as follows:
HoughCircles(img, results, HOUGH_GRADIENT, 2, 5, 185, 100, 20, 100);
The same issue is reported here:
https://stackoverflow.com/questions/53001840/opencv-houghcircles-occasionally-returning-0-0-0
This one seems similar also, except that it returns [10,0,0,0]:
https://stackoverflow.com/questions/49675692/opencv-houghcircles-returns-invalid-circle-parameters
Steps to reproduce
- Download hough_bug.cpp.txt
- Rename the file to hough_bug.cpp
- Compile hough_bug.cpp against OpenCV 4.0.1 to create a binary named
hough_bug. - Run
./hough_bugto generate a series of 1000 images, 26 of which demonstrate the issue (for me). The random seed is fixed so the program will create the same series of images each time you run it. - Run
./hough_bug *.pngto test the images generated in the previous step. Again, 26 of the images will demonstrate the issue. This proves that circle() and GaussianBlur() are not causing the issue.
The console output from an example run is attached:
hough_bug_output.txt
This image demonstrates the bug - returning [0,0,0] instead of a list of valid circles.

HoughCircles returns an empty list for this image, since no circles were found (this is expected with these parameters).

HoughCircles returns a list of 2 circles that were detected in this image.

Activity
alalek commentedon Apr 26, 2019
Please capture passed input to HoughCircles (image + parameters + code (types of parameters)).
Without reproducer it is almost impossible to fix issue.
knumat commentedon Apr 29, 2019
@alalek It took a bit longer than I expected to create a simple example program to demonstrate this issue. Could you take a look at the updated description and let me know if you have any idea what could be causing this? Thanks for the help!
alalek commentedon Apr 29, 2019
@knumat Thank you for the reproducer!
Could you try this patch: #14452?
knumat commentedon Apr 30, 2019
@alalek Thanks for the super-fast turn around on this! I built OpenCV 4.0.1 from source, and applying this patch resolves the issue for me. Now HoughCircles returns an empty list for the images that previously returned a list with a single [0,0,0] element.
Quick question... I noticed that this patch will be applied to the
3.4branch. Will this patch also be applied to themasterbranch so that it is included in the next 4.x release? (I'm not clear about the merge/release strategy on the opencv project.)Thanks again for the help on this!
alalek commentedon Apr 30, 2019
We will merge changes from 3.4 into master regularly (weekly/bi-weekly).