Last active
May 12, 2022 20:42
-
-
Save fritzfrancisco/97f2ef440f2e6f280151c4a0ecd6f939 to your computer and use it in GitHub Desktop.
Player implemented in python for simultaneously viewing two video inputs
This file contains hidden or 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
#!/usr/bin/env python3 | |
import numpy as np | |
import cv2 | |
import sys, os | |
import argparse | |
ap = argparse.ArgumentParser( | |
description='Input specific output pathway and framerate') | |
ap.add_argument("-i", "--input1",type=str, required=True, | |
default=None, help="path to input video 1") | |
ap.add_argument("-ii","--input2",required=True, type=str, | |
default=None, help='path to input video 2') | |
ap.add_argument("-s","--scaling",required=False, type=float, | |
default=1, help='multiplicative rescaling factor') | |
args = vars(ap.parse_args()) | |
print(args) | |
videos = [args['input1'],args['input2']] | |
names = [] | |
window_titles = [] | |
for video in videos: | |
names.append(video) | |
window_titles.append(os.path.basename(video)) | |
cv2.namedWindow(os.path.basename(video), cv2.WINDOW_NORMAL) | |
cap = [cv2.VideoCapture(i) for i in names] | |
frames = [None] * len(names); | |
gray = [None] * len(names); | |
ret = [None] * len(names); | |
while True: | |
for i,c in enumerate(cap): | |
if c is not None: | |
ret[i], frames[i] = c.read(); | |
images = [] | |
for i,f in enumerate(frames): | |
if ret[i] is True: | |
gray[i] = cv2.cvtColor(f, cv2.COLOR_BGR2GRAY) | |
if args['scaling'] != 1: | |
gray[i] = cv2.resize(gray[i], None, fx=args['scaling'], fy=args['scaling']) | |
cv2.imshow(window_titles[i], gray[i]); | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
for c in cap: | |
if c is not None: | |
c.release(); | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment