Skip to content

Commit 7234cf7

Browse files
committed
webcam_filter sample: add CLI
1 parent eaac0ee commit 7234cf7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

samples/webcam_filter.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# This scripts uses OpenCV to capture webcam output, applies a filter,
22
# and sends it to the virtual camera.
33

4+
import argparse
45
import cv2
56
import pyvirtualcam
67

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

913
# Set up webcam capture.
10-
vc = cv2.VideoCapture(0) # 0 = default camera
14+
vc = cv2.VideoCapture(args.camera)
1115

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

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

3438
# Shake two channels horizontally each frame.

0 commit comments

Comments
 (0)