

I used a trick to make the computation more regular. I tweaked it quite a bit, but I think it does basically the same thing. Mask = cv2.dilate(mask, kernel, iterations=3)Ĭlosing = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)Ĭontours = cv2.findContours(py(), cv2.RETR_EXTERNAL,Ĭontours.sort(key=lambda x:cv2.Here is a go at the implementation of your algorithm.

Mask = cv2.erode(mask, kernel, iterations=6) #In this case the text Q0X could be identified as circles but it is not. #Use erosion and dilation combination to eliminate false positives. # mask = cv2.adaptiveThreshold(image_ori,255,cv2.ADAPTIVE_THRESH_MEAN_C,\ Mask = cv2.inRange(image_color, lower_bound, upper_bound) Image_ori = cv2.cvtColor(image_color,cv2.COLOR_BGR2GRAY) The circles appear smaller because I have used erosion for 6 iterations and dilation only for 3 iterations.

Here is the results I got using contours. Because it is more robust and generalises well to different images. If there is no necessity to use Hough circles, I would suggest you to use contours instead. Things you could do to improve are ,preprocess using gaussianblur, use adaptivethreshold instead of just threshold. So its important to read the docs.Īnd about your problem, If you have specific necessity to use Houghcircles go ahead and fine tune it.

If you set these two, you can improve your results. You can clearly see that the circles in your image have fixed radius and have min distance separating them. MaxRadius: Maximum size of the radius (in pixels). MinRadius: Minimum size of the radius (in pixels). More circles will potentially be returned. The smaller the threshold is, the more circles will beĭetected (including false circles). Param2: Accumulator threshold value for the cv2.HOUGH_GRADIENT method. Param1: Gradient value used to handle edge detection in the Yuen et al. MinDist is too large, then some circles may not be detected at all. Same neighborhood as the original may be (falsely) detected. If the minDist is too small, multiple circles in the MinDist: Minimum distance between the center (x, y) coordinates of detected circles. It will take you a long time to solve this if you try to vary the parameters without understanding what they does. Please, how should i change the parameters? Imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) Now it runs but with bad performanceĪnd this is my code: from imutils.perspective import four_point_transform I tried to change its parameters but it gets errors when i increase param2 above 50 and maxRadius also gets errors when its value is smaller than 100. I'm trying to detect small circles in this cropped image using houghcircles().
