Skip to content

Instantly share code, notes, and snippets.

@ricklon
Created July 16, 2021 01:12
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 ricklon/eb72c17096b6e72a1ab1a39f274272ec to your computer and use it in GitHub Desktop.
Save ricklon/eb72c17096b6e72a1ab1a39f274272ec to your computer and use it in GitHub Desktop.
#quick rough out of multi camera image capture
import cv2
import numpy as np
from datetime import datetime
import time
import argparse
# construct the argument parser and parse the arguments
parser = argparse.ArgumentParser()
# Do not show image to user
parser.add_argument("--view", action='store_true',required=False, help="supress image to user")
parser.add_argument("-o", "--output_dir", required=False, help="path to output location")
# Specify the source is a video
parser.add_argument("-src", "--source", required=False, help="path and name to input video")
args = parser.parse_args()
# Set data directory path
DATA_DIR = "./data/"
if args.output_dir:
DATA_DIR = args.output_dir
out_filename = f"{DATA_DIR}contour-{datetime.now()}.png"
cam0 = cv2.VideoCapture(0)
cam0.set(3, 1280) # width
cam0.set(4, 720) # height
cam1 = cv2.VideoCapture(1)
cam1.set(3, 1280) # width
cam1.set(4, 720) # height
cam2 = cv2.VideoCapture(2)
cam2.set(3, 1280) # width
cam2.set(4, 720) # height
cam3 = cv2.VideoCapture(3)
cam3.set(3, 1280) # width
cam3.set(4, 720) # height
while cam0.isOpened():
ret, frame0 = cam0.read()
ret, frame1 = cam1.read()
ret, frame2 = cam2.read()
ret, frame3 = cam3.read()
cv2.imwrite(out_filename, frame0)
out_filename = f"{DATA_DIR}contour-{datetime.now()}.png"
cv2.imwrite(out_filename, frame1)
out_filename = f"{DATA_DIR}contour-{datetime.now()}.png"
cv2.imwrite(out_filename, frame2)
out_filename = f"{DATA_DIR}contour-{datetime.now()}.png"
cv2.imwrite(out_filename, frame3)
out_filename = f"{DATA_DIR}contour-{datetime.now()}.png"
if args.view:
cv2.imshow("frame0", frame0)
cv2.imshow("frame1", frame2)
cv2.imshow("frame2", frame3)
cv2.imshow("frame3", frame4)
if cv2.waitKey(40) == 27:
break
cv2.destroyAllWindows()
cam0.release()
cam1.release()
cam2.release()
cam3.release()
out.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment