Skip to content

Instantly share code, notes, and snippets.

@ndujar
Created April 26, 2020 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndujar/af36c182e2d79a228b9ac0504c523996 to your computer and use it in GitHub Desktop.
Save ndujar/af36c182e2d79a228b9ac0504c523996 to your computer and use it in GitHub Desktop.
OpenCV main loop
"""
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()
@ndujar
Copy link
Author

ndujar commented Apr 26, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment