Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,9 @@ def process_video(video):
|
|
| 23 |
new_width, new_height = 640, 480 # Resize to 640x480 resolution
|
| 24 |
frame_width, frame_height = new_width, new_height
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
while True:
|
| 27 |
# Read a frame from the video
|
| 28 |
ret, frame = input_video.read()
|
|
@@ -43,23 +46,19 @@ def process_video(video):
|
|
| 43 |
# Convert the annotated frame to RGB format for displaying
|
| 44 |
annotated_frame_rgb = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
# Wait for a key press (optional: press 'q' to quit early)
|
| 50 |
-
if cv2.waitKey(1) & 0xFF == ord('q'):
|
| 51 |
-
break
|
| 52 |
|
| 53 |
# Release resources
|
| 54 |
input_video.release()
|
| 55 |
-
cv2.destroyAllWindows()
|
| 56 |
|
| 57 |
-
|
|
|
|
| 58 |
|
| 59 |
# Create a Gradio interface for video upload
|
| 60 |
iface = gr.Interface(fn=process_video,
|
| 61 |
inputs=gr.Video(label="Upload Video"), # Updated line
|
| 62 |
-
outputs=gr.
|
| 63 |
title="YOLOv8 Object Detection - Real-Time Display",
|
| 64 |
description="Upload a video for object detection using YOLOv8. The frames with detections will be shown in real-time.")
|
| 65 |
|
|
|
|
| 23 |
new_width, new_height = 640, 480 # Resize to 640x480 resolution
|
| 24 |
frame_width, frame_height = new_width, new_height
|
| 25 |
|
| 26 |
+
# List to store processed frames for Gradio output
|
| 27 |
+
processed_frames = []
|
| 28 |
+
|
| 29 |
while True:
|
| 30 |
# Read a frame from the video
|
| 31 |
ret, frame = input_video.read()
|
|
|
|
| 46 |
# Convert the annotated frame to RGB format for displaying
|
| 47 |
annotated_frame_rgb = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
|
| 48 |
|
| 49 |
+
# Append the annotated frame to the list for Gradio
|
| 50 |
+
processed_frames.append(annotated_frame_rgb)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Release resources
|
| 53 |
input_video.release()
|
|
|
|
| 54 |
|
| 55 |
+
# Return the processed frames for Gradio to display as a video
|
| 56 |
+
return processed_frames
|
| 57 |
|
| 58 |
# Create a Gradio interface for video upload
|
| 59 |
iface = gr.Interface(fn=process_video,
|
| 60 |
inputs=gr.Video(label="Upload Video"), # Updated line
|
| 61 |
+
outputs=gr.Video(label="Processed Video"), # This will display the output video directly
|
| 62 |
title="YOLOv8 Object Detection - Real-Time Display",
|
| 63 |
description="Upload a video for object detection using YOLOv8. The frames with detections will be shown in real-time.")
|
| 64 |
|