部分代码:
#打开视频流
#url="视频路径"
#video_capture = cv.VideoCapture(url)
#打开摄像头,参数为整型数字
video_capture = cv.VideoCapture(0) #打开摄像头设备,如果只有一个摄像头,那就是0
while True:
frame = video_capture.read() #读取失败则返回(False,None),成功返回(True,FrameArray)
frame = frame[1]
cv.imshow('frame', frame)
Traceback (most recent call last):
File "xxxxx.py", line 11, in <module>
cv.imshow('frame', frame)
cv2.error: OpenCV(3.4.2) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
出错原因未授权应用访问摄像头:
win10:
打开设置-->点击隐私设置-->开启相机 和 允许应用访问你的相机 即可