This is the code I am using for capturing video through my webcam:
import cv2
cap = cv2.VideoCapture(0)
while True:
ret, frame= cap.read()
# frame= cv2.resize(frame, None,fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
cv2.imshow('Input', frame)
c = cv2.waitKey(1)
if c == 27:
break
cap.release()
cv2.destroyAllWindows()
And the error is:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /io/opencv/modules/highgui/src/window. cpp, line 325 Traceback (most recent call last): File "video_capturing2.py", line 10, in cv2.imshow('Input', frame) cv2.error: /io/opencv/modules/highgui/src/window.cpp:325: error: (-215) size.width>0 && size.height>0 in function ims how
How do I solve it? whenever I am running the code above, the ret
flag is never True
. I have tried sudo pip3 install opencv-contrib-python
but still it is not helping.