How do I tune the parameters of cv2.houghcircle() function of OpenCV-python to get the best results?
- Mayank Singh Soni
- May 5, 2017
- 1 min read
I am using OpenCV-Python 3.2 package with Python 3.6 but i am unable to get the desired result.
My task is to detect the circles from an image for that i use HoughCircle Algorithm but output is not appropriate.
My Code:
//python program
import cv2
import numpy as np
planets = cv2.imread('solar.jpg')
gray_img = cv2.cvtColor(planets, cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(gray_img, 5)
#img = cv2.GaussianBlur(gray_img, (3, 3), 0)
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 120,
param1=179, param2=28, minRadius=50,
maxRadius=141)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(planets,(i[0], i[1]), i[2],(0, 255, 0), 2)
# draw the center of the circle
cv2.circle(planets,(i[0], i[1]), 2, (0, 0, 255), 3)
cv2.imwrite("planets_circles.jpg", planets)
cv2.imshow("HoughCirlces", planets)
cv2.waitKey()
cv2.destroyAllWindows()
My Output:

My Input:

Comments