我正试图在网络摄像头上使用Opencv和Python获取hough线。
但是我收到一个错误,如Traceback(最近一次调用最后一次):File" C:/Python27/Hough_video_try.py" ;,第14行,in为rho,the行在行[0]中:TypeError :' NoneType'对象没有属性' getitem'
以下是我的代码,请帮助
import numpy as np
import cv2
cam = cv2.VideoCapture(0)
while (True): s, img = cam.read()
winName = "Movement Indicator"
cv2.namedWindow(winName, cv2.WINDOW_AUTOSIZE)
edges = cv2.Canny(img,100,200)
lines = cv2.HoughLinesP(edges,1,np.pi/180,2,None,30,1)
if lines is None:
for rho,theta in lines[0]:
pt1 = (line[0],line[1])
pt2 = (line[2],line[3])
cv2.line(img, pt1, pt2, (0,0,255), 3)
cv2.imshow('edges',edges)
cv2.imshow('original',img)
if cv2.waitKey(1) & 0xff == ord('q'):
break
cam.release()
cv2.destroyAllWindows()
答案 0 :(得分:-1)
问题在于您正在检查
if lines is None:
for rho,theta in lines[0]:
如果lines
为None
,您将如何获得None[0]
?
请更改条件
if lines is not None:
for rho,theta in lines[0]: