generalize webcam detection with opt.source.isnumeric() (yolov3 #1462)

This commit is contained in:
Glenn Jocher 2020-08-25 11:07:38 -07:00
parent 09402a2174
commit 82ed33a052
2 changed files with 2 additions and 2 deletions

View File

@ -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()

View File

@ -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))