How to do it...

The following are the steps for this recipe:

  1. Create a VideoCapture object for video file:
import cv2capture = cv2.VideoCapture('../data/drop.avi')
  1. Replay all the frames in the video:
while True:    has_frame, frame = capture.read()    if not has_frame:        print('Reached the end of the video')        break    cv2.imshow('frame', frame)    key = cv2.waitKey(50)    if key == 27:        print('Pressed Esc')        breakcv2.destroyAllWindows()

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.