# Can anyone explain about "cv2.HoughCircles" method parameter in Simple language?

I’m using OpenCV python library to find circles from concentric circle and successfully found all the circles but not able to understand the parameter of the “cv2.HoughCircles” method. I also hardcoded the range for “MinRadius” and “MaxRadius”. I just want to define the range for the radius based on the given image. I also go through the official document for “cv2.HoughCircles”
here
but this is also not understandale for me. Any help would be much appreciated!

Here is an image to find the circle:

Here is my python code:

``````import numpy as np
import cv2
cv2.imshow("Original image", image)
cv2.waitKey()

blurred = cv2.GaussianBlur(image,(11,11),0)

cv2.imshow("Blurred image", blurred)
cv2.waitKey()
previous=0;
i=4
for maxR in range(9,425,9):
# Finds circles in a grayscale image using the Hough transform
circles = cv2.HoughCircles(blurred, cv2.HOUGH_GRADIENT, 1, 100,
i+=4
# cv2.HoughCircles function has a lot of parameters, so you can find more about it in documentation
# or you can use cv2.HoughCircles? in jupyter nootebook to get that

# Check to see if there is any detection
if circles is not None:
# If there are some detections, convert radius and x,y(center) coordinates to integer
circles = np.round(circles[0, :]).astype("int")

for (x, y, r) in circles:
# Draw the circle in the output image
cv2.circle(output, (x, y), r, (0,255,0), 1)
# Draw a rectangle(center) in the output image
cv2.rectangle(output, (x - 2, y - 2), (x + 2, y + 2), (0,255,0), -1)

cv2.imshow("Detections",output)
cv2.imwrite("CirclesDetection.jpg",output)
cv2.waitKey()
``````

According to the documentation, the `method` parameter has to be HOUGH_GRADIENT.

So `HoughCircles` detects the contours using the Canny operator, and for each point `p` and radius `r` it computes the sum of the contour pixels for a given circle `pc`:

``````Circ_Hough(p,r)=SUM(Canny(pc)==1 where d(p,pc=r))
# p - central pixel of a circle, r - radius, pc - pixels on the circle
``````

Now, the `param1` parameter is the canny threshold `maxval`. It means that the gradient value higher than `param1` is always considered a contour pixel. For more detailed explanation see this tutorial.
You can check the effect of this parameter by running only the canny operator on the image:

``````cny = cv2.canny(image,param1/2,param1)
cv2.imshow("canny",cny)
``````

The `param2`is the circle detection threshold. It means that for a point to be considered as a circle center, `Circ_Hough(p,r)>param2`. If `param2` is too low, you’ll have false detections, if it’s too high, some good detections will be discarded.