I'm learning OpenCV using python. I'm trying to run the following code to capture snapshots using OpenCV. I'm able to run the script correctly through Anaconda spyder however getting error when I'm using command prompt. I referred to questions on stackoverflow Assertion failure : size.width>0 && size.height>0 in function imshow However, here I'm not loading any external image. My code is:
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()
Error I'm getting:
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'
Please help.