opencv打开摄像头报错 cv2.error: OpenCV(4.10.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:973: error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow’) 解决
详细报错如下:
[ERROR:0@0.210] global obsensor_uvc_stream_channel.cpp:158 cv::obsensor::getStreamChannelGroup Camera index out of range
Traceback (most recent call last):
File “G:\power_quality\wave_plot_csv\camera_use.py”, line 7, in
cv2.imshow(‘frames’,frame)
cv2.error: OpenCV(4.10.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:973: error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow’
有时候报错不能只看最后一行,根据黄色高亮处显示,表明摄像头索引超范围了。将cap = cv2.VideoCapture(2)语句修改为cap = cv2.VideoCapture(0)即可。