[英]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? 有谁知道这个隐藏参数在哪里?
Thanks 谢谢
CV_HOUGH_GRADIENT
belongs to the cv
module, so you'll need to import that: CV_HOUGH_GRADIENT
属于cv
模块,因此您需要导入:
import cv2.cv as cv
and change your function call to 并将您的函数调用更改为
circles = cv2.HoughCircles(gray,cv.CV_HOUGH_GRADIENT)
In my case, I am using opencv 3.0.0 and it worked the following way: 就我而言,我使用的是opencv 3.0.0,它的工作方式如下:
circles = cv2.HoughCircles(gray_im, cv2.HOUGH_GRADIENT, 2, 10, np.array([]), 20, 60, m/10)[0]
ie instead of cv2.cv.CV_HOUGH_GRADIENT
, I have used just cv2.HOUGH_GRADIENT
. 即,而不是
cv2.cv.CV_HOUGH_GRADIENT
,我只使用了cv2.HOUGH_GRADIENT
。
if you use OpenCV 3, then use this code : 如果您使用OpenCV 3,则使用此代码:
img = cv2.imread("act_circle.png")
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT) # change here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.