1 | initial version |
Do a truth check after capture.read on the returned, if the return is true, only then proceed. I faced a similar problem, this fixed that.
See this example:
import numpy as np
import cv2
cap=cv2.VideoCapture(0)
while(cap.isOpened()):
#cpature frame by frame
ret,frame=cap.read()
if(ret): #if cam read is successful
#ops here:
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
#disp the resulting frame
cv2.imshow('Grayframe :: q to exit',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
#when everything else done,release capture
cap.release()
cv2.destroyAllWindows()
2 | No.2 Revision |
Do a truth check after capture.read on the returned, returned value, if the return is true, only then proceed. I faced a similar problem, this fixed that.
See this example:
import numpy as np
import cv2
cap=cv2.VideoCapture(0)
while(cap.isOpened()):
#cpature frame by frame
ret,frame=cap.read()
if(ret): #if cam read is successful
#ops here:
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
#disp the resulting frame
cv2.imshow('Grayframe :: q to exit',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
#when everything else done,release capture
cap.release()
cv2.destroyAllWindows()