Skip to content

Commit

Permalink
webcam_filter sample: add CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
letmaik committed Mar 7, 2021
1 parent eaac0ee commit 7234cf7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions samples/webcam_filter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# This scripts uses OpenCV to capture webcam output, applies a filter,
# and sends it to the virtual camera.

import argparse
import cv2
import pyvirtualcam

verbose = False
parser = argparse.ArgumentParser()
parser.add_argument("--camera", type=int, default=0, help="ID of webcam device (default: 0)")
parser.add_argument("--fps", action="store_true", help="output fps every second")
args = parser.parse_args()

# Set up webcam capture.
vc = cv2.VideoCapture(0) # 0 = default camera
vc = cv2.VideoCapture(args.camera)

if not vc.isOpened():
raise RuntimeError('Could not open video source')
Expand All @@ -28,7 +32,7 @@
fps_out = 20

try:
with pyvirtualcam.Camera(width, height, fps_out, print_fps=True) as cam:
with pyvirtualcam.Camera(width, height, fps_out, print_fps=args.fps) as cam:
print(f'Virtual cam started: {cam.device} ({cam.width}x{cam.height} @ {cam.fps}fps)')

# Shake two channels horizontally each frame.
Expand Down

0 comments on commit 7234cf7

Please sign in to comment.