I want to use my laptop webcam to capture a picture using the code below:
import cv2
cap = cv2.VideoCapture(1)
while(True):
ret, frame = cap.read()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
but it throws this error:
cv2.imshow('frame', frame) cv2.error: OpenCV(4.0.0) C:projectsopencv-pythonopencvmoduleshighguisrcwindow.cpp:350: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
How can I fix this error?
See Question&Answers more detail:os