Created
September 29, 2020 23:44
-
-
Save doron2402/5c6236dfed3b26d36c310f316fa5e59c to your computer and use it in GitHub Desktop.
OpenCV2 read a video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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