Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions models/object_detection_nanodet/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions models/palm_detection_mediapipe/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down