Skip to content

HoughCircles sometimes returns [0,0,0] #14432

Closed

Description

@knumat
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
  1. Download hough_bug.cpp.txt
  2. Rename the file to hough_bug.cpp
  3. Compile hough_bug.cpp against OpenCV 4.0.1 to create a binary named hough_bug.
  4. Run ./hough_bug to 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.
  5. Run ./hough_bug *.png to 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.
000-bug

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

HoughCircles returns a list of 2 circles that were detected in this image.
002-found-two-circles

Activity

  1. alalek commented on Apr 26, 2019

    @alalek
    Member

    Please capture passed input to HoughCircles (image + parameters + code (types of parameters)).
    Without reproducer it is almost impossible to fix issue.

  2. knumat commented on Apr 29, 2019

    @knumat
    Author

    @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!

  3. alalek commented on Apr 29, 2019

    @alalek
    Member

    @knumat Thank you for the reproducer!
    Could you try this patch: #14452?

  4. knumat commented on Apr 30, 2019

    @knumat
    Author

    @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.4 branch. Will this patch also be applied to the master branch 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!

  5. alalek commented on Apr 30, 2019

    @alalek
    Member

    We will merge changes from 3.4 into master regularly (weekly/bi-weekly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcategory: imgprocconfirmed

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions