how to use hough circles in cv2 with python?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 03:23:56

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

import cv2.cv as cv

and change your function call to

circles = cv2.HoughCircles(gray,cv.CV_HOUGH_GRADIENT)
Saurav

In my case, I am using opencv 3.0.0 and it worked the following way:

circles = cv2.HoughCircles(gray_im, cv2.HOUGH_GRADIENT, 2, 10, np.array([]), 20, 60, m/10)[0]  

i.e. instead of cv2.cv.CV_HOUGH_GRADIENT, I have used just cv2.HOUGH_GRADIENT.

if you use OpenCV 3, then use this code :

img = cv2.imread("act_circle.png")
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT) # change here
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!