Skip to content

Commit

Permalink
Add --num-frames arg to canny (webcam) example (#1923)
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc authored Apr 19, 2023
1 parent fce9cf4 commit 207a283
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions examples/python/opencv_canny/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@
"""

import argparse
from typing import Optional

import cv2
import rerun as rr


def run_canny() -> None:
def run_canny(num_frames: Optional[int]) -> None:
# Create a new video capture
cap = cv2.VideoCapture(0)

frame_nr = 0

while cap.isOpened():
if num_frames and frame_nr >= num_frames:
break

# Read the frame
ret, img = cap.read()
if not ret:
Expand Down Expand Up @@ -66,6 +70,7 @@ def main() -> None:
parser.add_argument(
"--device", type=int, default=0, help="Which camera device to use. (Passed to `cv2.VideoCapture()`)"
)
parser.add_argument("--num-frames", type=int, default=None, help="The number of frames to log")

rr.script_add_args(parser)
args = parser.parse_args()
Expand Down Expand Up @@ -93,7 +98,7 @@ def main() -> None:
"""
)

run_canny()
run_canny(args.num_frames)

rr.script_teardown(args)

Expand Down

0 comments on commit 207a283

Please sign in to comment.