0

I have the following image in which I've detected the borders, representing 7 circles. In my opinion, it is fairly easy to identify the circles on it, but I am having trouble detecting all circles with the opencv Hough transform. Here it is what I've tried:

img = cv2.imread('sample.png',0)
edges = cv2.Canny(img,20,120)
circles = cv2.HoughCircles(edges,cv2.HOUGH_GRADIENT,1,100,
                                param2=40,minRadius=0,maxRadius=250)

I either get the central circle, the outer one or a lot of circles, depending on the parameters I input on the function. Do you guys have a set of parameters that would output all the circles?

Thanks in advance circle borders

  • 1
    I’ve been having a look at cv2.HoughCircles and struggling - the implementation doesn’t seem to like an image where I’ve already done the canny edge detect - try feeding it a continuous gray-scale image and see if it does better. Also try the scikit hough circles implementation. – DisappointedByUnaccountableMod Jun 01 '20 at 21:46
  • From what I have seen, it does not like concentric circles. It works best on non-concentric circles of a limited range of radii. Why don't you get the contours of the white circles and then fit circles to each one. – fmw42 Jun 01 '20 at 22:18
  • Great tip, the scikit-image implementation looks much better. I've managed to get all the circles I needed. Thank you very much – Fernando Bordignon Jun 02 '20 at 00:37
  • I see five circles. –  Jun 02 '20 at 08:44
  • 1
    houghCircles in opencv performs a canny edge detection itself, as discussed in https://stackoverflow.com/questions/20698613/detect-semicircle-in-opencv/20706100#20706100 so maybe better adapt the code (open source) to accept mask input as well. Or, if you know the number of circles, implement a simple ransac circle detection. – Micka Jun 02 '20 at 18:48

1 Answers1

0

Solved with this example from scikit-image adjusting canny thresholds to match the posted image and also the radii range. Thanks to @barny