【发布时间】:2020-11-18 09:58:03
【问题描述】:
我正在使用 python 学习 OpenCV。我正在尝试运行以下代码以使用 OpenCV 捕获快照。我能够通过 Anaconda spyder 正确运行脚本,但是在使用命令提示符时出现错误。我提到了关于stackoverflow的问题Assertion failure : size.width>0 && size.height>0 in function imshow 但是,在这里我没有加载任何外部图像。 我的代码是:
import cv2
videoObject = cv2.VideoCapture(0) #0== integrated webcam 1==External webcam
i=0
while True:
check, frame = videoObject.read()
cv2.imshow("Webcam Shot",frame)
key = cv2.waitKey(1)
# 'c' button to capture the image
# the 'q' button is set as the quit
if key == ord('c'):
cv2.imwrite('Image_'+str(i)+'.png', frame)
i+=1
print('Image saved')
if key == ord('q'):
break
# shutdown the camera
videoObject.release()
cv2.destroyAllWindows()
我得到的错误:
cv2.error: OpenCV(4.3.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
请帮忙。
【问题讨论】: