diff --git a/models/object_detection_nanodet/demo.py b/models/object_detection_nanodet/demo.py index ab6e980a..51766921 100644 --- a/models/object_detection_nanodet/demo.py +++ b/models/object_detection_nanodet/demo.py @@ -133,7 +133,9 @@ def vis(preds, res_img, letterbox_scale, fps=None): tm = cv.TickMeter() tm.reset() - if args.input is not None: + + #if Input is NOT a digit(i.e input is a file path like dog.jpg or cat.jpg) + if args.input is not None and not args.input.isdigit(): image = cv.imread(args.input) input_blob = cv.cvtColor(image, cv.COLOR_BGR2RGB) @@ -157,9 +159,14 @@ def vis(preds, res_img, letterbox_scale, fps=None): cv.imshow(args.input, img) cv.waitKey(0) + #If it is a digit(or None),go to webcam mode else: print("Press any key to stop video capture") - deviceId = 0 + + #If args.input is None,choose 0 as default else leave it as - + # the digit the string was before the conversion to an integer i.e "1" as 1 + + deviceId = int(args.input) if args.input else 0 cap = cv.VideoCapture(deviceId) while cv.waitKey(1) < 0: diff --git a/models/palm_detection_mediapipe/demo.py b/models/palm_detection_mediapipe/demo.py index 98fdf694..335867b3 100644 --- a/models/palm_detection_mediapipe/demo.py +++ b/models/palm_detection_mediapipe/demo.py @@ -87,8 +87,8 @@ def visualize(image, results, print_results=False, fps=None): backendId=backend_id, targetId=target_id) - # If input is an image - if args.input is not None: + # if Input is NOT a digit(i.e input is a file path like thumb.jpg or index_finger.jpg) + if args.input is not None and not args.input.isdigit(): image = cv.imread(args.input) # Inference @@ -109,8 +109,9 @@ def visualize(image, results, print_results=False, fps=None): cv.namedWindow(args.input, cv.WINDOW_AUTOSIZE) cv.imshow(args.input, image) cv.waitKey(0) + #If it is a digit(or None),go to webcam mode else: # Omit input to call default camera - deviceId = 0 + deviceId = int(args.input) if args.input else 0 cap = cv.VideoCapture(deviceId) tm = cv.TickMeter()