使用VideoCapture().read()时,imutils报错:AttributeError: ‘tuple‘ object has no attribute ‘shape‘解决方案

1.报错:

环境:python+opencv

使用VideoCapture().read()时,imutils报错:AttributeError: ‘tuple‘ object has no attribute ‘shape‘解决方案_第1张图片

 

File "XXX\lib\site-packages\imutils\convenience.py", line 69, in resize(h, w) = image.shape[:2]
AttributeError: 'tuple' object has no attribute 'shape'

2.原因:

.read()返回值包括两个:

1)True/False(bool类型),返回是否成功读取;

2)frame(数组类型),返回读取的图片。

调用时如果只用

frame = cv2.VideoCapture(0).read()

就会出现以上报错

3.解决方案:

将frame=cv2.VideoCapture(0).read()更改为:

_ , frame = cv2.VideoCapture(0).read()

即可正常运行

你可能感兴趣的:(PersonDetector,python,opencv)