权限都已经给了,报错信息如下:
TellHardwareToSetFrameRate 30.000000
Stream::Start - v11
Stream::Start - resumed connection
Stream::Start - connect
True
Traceback (most recent call last):
File "/SimpleShow/capVideo.py", line 10, in <module>
cv2.imshow('video', frame)
cv2.error: OpenCV(4.5.2) /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pip-req-build-2fjztvm5/opencv/modules/highgui/src/window.cpp:404: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
Connection went invalid
完整代码:
import cv2
if __name__ == '__main__':
cv2.namedWindow('video', cv2.WINDOW_AUTOSIZE)
cap = cv2.VideoCapture(0)
print(cap.isOpened())
while True:
ret, frame = cap.read()
cv2.imshow('video', frame)
key = cv2.waitKey(10)
if key & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()