I Would like an explanation of the parameters for opencv's
I'm new to image processing in general and I have recently started using opencv. I'm struggling to find circles. I obtained the image below by converting a source image to greyscale then performing a binary threshold.
To my eye, the leftmost images are almost perfect circles. I have seen demonstrations where, what I assume are very noisy and distorted circles have been identified by opencv's hough transform.
Assuming the image displayed above is saved as "binaryresult.png". If I run the following code I get circles that are poorly placed. I'd like to understand the
HoughCircles function's parameters so that I can better detect circles.
import cv2 import numpy as np image = cv2.imread("binaryresult.png") image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) circles = cv2.HoughCircles(image, cv2.cv.CV_HOUGH_GRADIENT, 2, 32, param1=200, param2=100) # ensure at least some circles were found if circles is not None: # convert the (x, y) coordinates and radius of the circles to integers circles = np.round(circles[0, :]).astype("int") # loop over the (x, y) coordinates and radius of the circles for (x, y, r) in circles: # draw the circle in the output image, then draw a rectangle # corresponding to the centre of the circle cv2.circle(output, (x, y), r, (0, 255, 0), 4) cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1) # show the output image cv2.imshow("output", np.hstack([image])) cv2.waitKey(0)