<分区>
这是我用来通过网络摄像头捕捉视频的代码:
import cv2
cap = cv2.VideoCapture(0)
while True:
ret, frame= cap.read()
# frame= cv2.resize(frame, None,fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
cv2.imshow('Input', frame)
c = cv2.waitKey(1)
if c == 27:
break
cap.release()
cv2.destroyAllWindows()
错误是:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /io/opencv/modules/highgui/src/window. cpp, line 325 Traceback (most recent call last): File "video_capturing2.py", line 10, in cv2.imshow('Input', frame) cv2.error: /io/opencv/modules/highgui/src/window.cpp:325: error: (-215) size.width>0 && size.height>0 in function ims how
我该如何解决?每当我运行上面的代码时,ret
标志永远不会是 True
。我已经尝试过 sudo pip3 install opencv-contrib-python
但它仍然没有帮助。