Update app.py
Browse files
app.py
CHANGED
|
@@ -42,8 +42,16 @@ if video_file is not None:
|
|
| 42 |
tfile = tempfile.NamedTemporaryFile(delete=False)
|
| 43 |
tfile.write(video_file.read())
|
| 44 |
|
|
|
|
| 45 |
# Open video capture using temporary file path
|
| 46 |
cap = cv2.VideoCapture(tfile.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
alert_set = set(alerting_classes.keys())
|
| 48 |
alert_set.remove(0)
|
| 49 |
|
|
@@ -67,6 +75,9 @@ if video_file is not None:
|
|
| 67 |
# st.warning("Can't receive frame (stream end?). Exiting ...")
|
| 68 |
break
|
| 69 |
|
|
|
|
|
|
|
|
|
|
| 70 |
if frame_counter % 4 == 0: # Perform inference on every 4th frame
|
| 71 |
alert_flag = False
|
| 72 |
alert_reason = []
|
|
@@ -127,12 +138,9 @@ if video_file is not None:
|
|
| 127 |
cap.release()
|
| 128 |
tfile.close()
|
| 129 |
|
| 130 |
-
# Display frames one by one as a video
|
| 131 |
-
progress_bar_display = st.progress(0)
|
| 132 |
for i, frame in enumerate(frames):
|
| 133 |
video_placeholder.image(frame, channels="BGR", caption="YOLOv8 Inference")
|
| 134 |
-
# Update display progress bar
|
| 135 |
-
progress_bar_display.progress((i + 1) / len(frames))
|
| 136 |
time.sleep(frame_delay)
|
| 137 |
|
| 138 |
st.markdown("<hr>", unsafe_allow_html=True)
|
|
|
|
| 42 |
tfile = tempfile.NamedTemporaryFile(delete=False)
|
| 43 |
tfile.write(video_file.read())
|
| 44 |
|
| 45 |
+
# Open video capture using temporary file path
|
| 46 |
# Open video capture using temporary file path
|
| 47 |
cap = cv2.VideoCapture(tfile.name)
|
| 48 |
+
original_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 49 |
+
original_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 50 |
+
|
| 51 |
+
# Set the target width and height based on the conditions
|
| 52 |
+
target_width = int(original_width * 0.65) if original_width <= 1920 else int(original_width * 0.5)
|
| 53 |
+
target_height = int(original_height * 0.65) if original_width <= 1920 else int(original_height * 0.5)
|
| 54 |
+
|
| 55 |
alert_set = set(alerting_classes.keys())
|
| 56 |
alert_set.remove(0)
|
| 57 |
|
|
|
|
| 75 |
# st.warning("Can't receive frame (stream end?). Exiting ...")
|
| 76 |
break
|
| 77 |
|
| 78 |
+
# Resize the frame
|
| 79 |
+
resized_frame = cv2.resize(frame, (target_width, target_height))
|
| 80 |
+
|
| 81 |
if frame_counter % 4 == 0: # Perform inference on every 4th frame
|
| 82 |
alert_flag = False
|
| 83 |
alert_reason = []
|
|
|
|
| 138 |
cap.release()
|
| 139 |
tfile.close()
|
| 140 |
|
| 141 |
+
# Display frames one by one as a video
|
|
|
|
| 142 |
for i, frame in enumerate(frames):
|
| 143 |
video_placeholder.image(frame, channels="BGR", caption="YOLOv8 Inference")
|
|
|
|
|
|
|
| 144 |
time.sleep(frame_delay)
|
| 145 |
|
| 146 |
st.markdown("<hr>", unsafe_allow_html=True)
|