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
image = cv2.imread("GoldenSpike.png",0)
output = cv2.imread("GoldenSpike.png",1)
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,
param1=100,param2=90,minRadius=i,maxRadius=maxR)
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()