gpt4 book ai didi

python - AttributeError: 'module' object has no attribute 'HOUGH_GRADIENT' , cv.HOUGH_GRADIENT 没有解决这个问题

转载 作者:太空宇宙 更新时间:2023-11-03 13:16:26 24 4
gpt4 key购买 nike

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

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)

关于python - AttributeError: 'module' object has no attribute 'HOUGH_GRADIENT' , cv.HOUGH_GRADIENT 没有解决这个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28569316/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com