From 82ed33a052081f122df7cc8b94e7009d7ec35c2d Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 25 Aug 2020 11:07:38 -0700 Subject: [PATCH] generalize webcam detection with opt.source.isnumeric() (yolov3 #1462) --- detect.py | 2 +- utils/datasets.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/detect.py b/detect.py index 60dd059..fd2c14d 100644 --- a/detect.py +++ b/detect.py @@ -21,7 +21,7 @@ from utils.torch_utils import select_device, load_classifier, time_synchronized def detect(save_img=False): out, source, weights, view_img, save_txt, imgsz = \ opt.output, opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size - webcam = source == '0' or source.startswith('rtsp') or source.startswith('http') or source.endswith('.txt') + webcam = source.isnumeric() or source.startswith('rtsp') or source.startswith('http') or source.endswith('.txt') # Initialize set_logging() diff --git a/utils/datasets.py b/utils/datasets.py index 252d14d..d6c220f 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -235,7 +235,7 @@ class LoadStreams: # multiple IP or RTSP cameras for i, s in enumerate(sources): # Start the thread to read frames from the video stream print('%g/%g: %s... ' % (i + 1, n, s), end='') - cap = cv2.VideoCapture(0 if s == '0' else s) + cap = cv2.VideoCapture(eval(s) if s.isnumeric() else s) assert cap.isOpened(), 'Failed to open %s' % s w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))