Shan Shan - 1 year ago 290
Python Question

how to use hough circles in cv2 with python?

I have the following code and I want to detect the circle.

img = cv2.imread("act_circle.png")
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray,cv2.CV_HOUGH_GRADIENT)

it looks like it does not have the attribute and the error is the following

'module' object has no attribute 'CV_HOUGH_GRADIENT'

Does anybody know where this hidden parameters is?


jam jam
Answer Source

CV_HOUGH_GRADIENT belongs to the cv module, so you'll need to import that:

import as cv

and change your function call to

circles = cv2.HoughCircles(gray,cv.CV_HOUGH_GRADIENT)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download