Skip to content

Instantly share code, notes, and snippets.

@doron2402
Created September 29, 2020 23:44
Show Gist options
  • Save doron2402/5c6236dfed3b26d36c310f316fa5e59c to your computer and use it in GitHub Desktop.
Save doron2402/5c6236dfed3b26d36c310f316fa5e59c to your computer and use it in GitHub Desktop.
OpenCV2 read a video
import numpy as np
import cv2
video_file_path = '<link to video>'
video = cv2.VideoCapture(video_file_path)
# Check if video was opened
if video.isOpened() == False:
print(f'Cannot open video stream {video_file_path}')
# loop through the video read frame by frame
while True:
ret, frame = video.read()
if ret == True:
cv2.imshow('Frame', frame)
if cv2.waitKey(25) & 0xFF == 27:
break
else:
break
# Close video and close OpenCV window
video.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment