1 | initial version |
there's a difference between webcams and movie files - webcams have an endless stream, while with files you eventually reach the end of it. please make it a HABIT to check return values, and for empty frames, whenever you read images from videos, disk, etc..
cap = cv2.VideoCapture('vtest.avi')
while(cap.isOpened()):
ret, frame = cap.read()
if not ret: break # movie's over !
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
2 | No.2 Revision |
there's a difference between webcams and movie files - webcams have an endless stream, while with files you eventually reach the end of it. please make it a HABIT to check return values, and for empty frames, whenever you read images from videos, disk, etc..
cap = cv2.VideoCapture('vtest.avi')
while(cap.isOpened()):
ret, frame = cap.read()
if not ret: break # movie's over !
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
ps: please do not use the outdated tutroals, opencv's python tutorials are here