Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';模块';对象没有属性';霍夫梯度;,cv.HOUGH_梯度不解决问题_Python_Opencv_Attributeerror - Fatal编程技术网

Python 属性错误:';模块';对象没有属性';霍夫梯度;,cv.HOUGH_梯度不解决问题

Python 属性错误:';模块';对象没有属性';霍夫梯度;,cv.HOUGH_梯度不解决问题,python,opencv,attributeerror,Python,Opencv,Attributeerror,尝试运行以下代码时出现属性错误: import cv2 import cv2.cv as cv import numpy as np def main(): img = cv2.imread('images/g1.jpg',0); print(img) img = cv2.medianBlur(img,5) cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR) circles = cv2.HoughCircle

尝试运行以下代码时出现属性错误:

import cv2
import cv2.cv as cv
import numpy as np 


def main():
    img = cv2.imread('images/g1.jpg',0);

    print(img)

    img = cv2.medianBlur(img,5)
    cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)

    circles = cv2.HoughCircles(img, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)

    circles = np.uint16(np.around(circles))
    for i in circles[0,:]:
        # draw the outer circle
        cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
        # draw the center of the circle
        cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)

    cv2.imshow('detected circles',cimg)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
我试图找到这个问题的解决方案,并在中用
cv
替换
cv2

circles = cv2.HoughCircles(img, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)

然而,我仍然得到了错误

问题在于属性是

cv.CV_HOUGH_GRADIENT
所以你需要这样做

circles = cv2.HoughCircles(img, cv.CV_HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)
新的答案是

圆=cv2。霍夫圆(img,cv2。霍夫梯度,1,20,参数1=50,参数2=30,最小半径=0,最大半径=0)