python中圆检测为什么出现如下错误?
import cv2import numpy as np
cap = cv2.VideoCapture(0)
while(True):
ret, frame=cap.read()
gray_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(gray_img, 5)
circles = cv2.HoughCircles(img,cv2.cv.CV_HOUGH_GRADIENT,
1,410,param1=100,param2=30,minRadius=15,maxRadius=25)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv2.circle(frame,(i[0],i[1]),i[2],(0,255,0),2)
cv2.circle(frame,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow("HoughCirlces", frame)
if cv2.waitKey(97) == ord('a'):
break
cv2.destroyAllWindows()
cap.release()
回答:
circles = cv2.HoughCircles(img,cv2.cv.CV_HOUGH_GRADIENT, 1,410,param1=100,param2=30,minRadius=15,maxRadius=25)
中minRadius,与maxRadius限制太苛刻,一旦未捕获到圆,circles为空,后面运算会出错。
改为minRadius=0,maxRadius=0
以上是 python中圆检测为什么出现如下错误? 的全部内容, 来源链接: utcz.com/a/163424.html