Fix Enable Tracking Button and Optimize FPS in Streamlit Application (#14508)
Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
0f865de198
commit
ebf7dcf5a8
1 changed files with 7 additions and 5 deletions
|
|
@ -99,24 +99,26 @@ def inference():
|
|||
|
||||
stop_button = st.button("Stop") # Button to stop the inference
|
||||
|
||||
prev_time = 0
|
||||
while videocapture.isOpened():
|
||||
success, frame = videocapture.read()
|
||||
if not success:
|
||||
st.warning("Failed to read frame from webcam. Please make sure the webcam is connected properly.")
|
||||
break
|
||||
|
||||
curr_time = time.time()
|
||||
fps = 1 / (curr_time - prev_time)
|
||||
prev_time = curr_time
|
||||
prev_time = time.time()
|
||||
|
||||
# Store model predictions
|
||||
if enable_trk:
|
||||
if enable_trk == "Yes":
|
||||
results = model.track(frame, conf=conf, iou=iou, classes=selected_ind, persist=True)
|
||||
else:
|
||||
results = model(frame, conf=conf, iou=iou, classes=selected_ind)
|
||||
annotated_frame = results[0].plot() # Add annotations on frame
|
||||
|
||||
# Calculate model FPS
|
||||
curr_time = time.time()
|
||||
fps = 1 / (curr_time - prev_time)
|
||||
prev_time = curr_time
|
||||
|
||||
# display frame
|
||||
org_frame.image(frame, channels="BGR")
|
||||
ann_frame.image(annotated_frame, channels="BGR")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue