Skip to content Skip to sidebar Skip to footer

Trying To Detect All The Circles With Houghcircles In Opencv (python)

I am following this tutorial: https://www.pyimagesearch.com/2014/07/21/detecting-circles-images-using-opencv-hough-circles/ I was playing around with the parameters ( even those yo

Solution 1:

First of all you can not expect HoughCircles to detect all circles in different type of situations. It is not an AI. It has different parameters according to get desired results. You can check here to learn more about those parameters.

HoughCircles is a contour based function so you should be sure the contours are being detected properly. In your example I am sure bad contour results will come up because of the lighting problem. Metal materials cause light explosion in image processing and this affects finding contours badly.

What you should do:

  • Solve the lighting problem
  • Be sure about the HoughCircle parameters to get desired output
  • Instead of using HoughCircle you can detect each contour and their mass center ( moments help you to find their mass center). Then you can measure each length of contour points to that mass center if all equal then its a circle.

Solution 2:

Hough transform works best on monochromatic/binary image, so you may want to preprocess it with some sort of threshold function. Parameter values for the function are very important for proper recognition.

Is this the best way to do circle detection with openCV or is there a more accurate way of doing it ? Also why is my code not detecting every circles ?

there's also findContours function https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#gadf1ad6a0b82947fa1fe3c3d497f260e0 which, to my liking, is more robust and general; you may want to give it a try

Post a Comment for "Trying To Detect All The Circles With Houghcircles In Opencv (python)"