Created
April 26, 2020 19:17
-
-
Save ndujar/af36c182e2d79a228b9ac0504c523996 to your computer and use it in GitHub Desktop.
OpenCV main loop
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
""" | |
Module for video processing using opencv | |
""" | |
import time | |
import argparse | |
import numpy as np | |
import pandas as pd | |
import cv2 | |
PARSER = argparse.ArgumentParser() | |
PARSER.add_argument("source", help="The file with the source video") | |
ARGS = PARSER.parse_args() | |
def main(): | |
""" | |
Main loop | |
""" | |
cap = cv2.VideoCapture(ARGS.source) | |
start_time = time.time() | |
# Read until video is completed | |
while cap.isOpened(): | |
# Capture frame-by-frame | |
ret, frame = cap.read() | |
if ret: | |
# Display the resulting frame | |
cv2.imshow('Frame', frame) | |
# Press Q on keyboard to exit | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
# Break the loop | |
else: | |
break | |
# When everything done, release the video capture object | |
cap.release() | |
# Closes all the frames | |
cv2.destroyAllWindows() | |
print('Elapsed time:', time.time() - start_time) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credits to https://www.learnopencv.com/read-write-and-display-a-video-using-opencv-cpp-python/
I have only added argparse to be able to pass different test videos from console