Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,8 +17,10 @@ def process_video(video):
|
|
| 17 |
frame_height = int(input_video.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 18 |
fps = input_video.get(cv2.CAP_PROP_FPS)
|
| 19 |
|
| 20 |
-
# Create
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
while True:
|
| 24 |
# Read a frame from the video
|
|
@@ -32,22 +34,20 @@ def process_video(video):
|
|
| 32 |
# The results object contains annotations for the frame
|
| 33 |
annotated_frame = results[0].plot() # Plot the frame with bounding boxes
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
# Append the frame to the list
|
| 39 |
-
processed_frames.append(annotated_frame_rgb)
|
| 40 |
|
| 41 |
# Release resources
|
| 42 |
input_video.release()
|
|
|
|
| 43 |
|
| 44 |
-
# Return the processed
|
| 45 |
-
return
|
| 46 |
|
| 47 |
# Create a Gradio interface for video upload
|
| 48 |
iface = gr.Interface(fn=process_video,
|
| 49 |
inputs=gr.Video(label="Upload Video"), # Updated line
|
| 50 |
-
outputs=gr.Video(), # This will display the output video directly
|
| 51 |
title="YOLOv8 Object Detection on Video",
|
| 52 |
description="Upload a video for object detection using YOLOv8")
|
| 53 |
|
|
|
|
| 17 |
frame_height = int(input_video.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 18 |
fps = input_video.get(cv2.CAP_PROP_FPS)
|
| 19 |
|
| 20 |
+
# Create a VideoWriter object to write processed frames to an output file
|
| 21 |
+
output_video_path = "processed_output.mp4"
|
| 22 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for .mp4 format
|
| 23 |
+
output_video = cv2.VideoWriter(output_video_path, fourcc, fps, (frame_width, frame_height))
|
| 24 |
|
| 25 |
while True:
|
| 26 |
# Read a frame from the video
|
|
|
|
| 34 |
# The results object contains annotations for the frame
|
| 35 |
annotated_frame = results[0].plot() # Plot the frame with bounding boxes
|
| 36 |
|
| 37 |
+
# Write the annotated frame to the output video
|
| 38 |
+
output_video.write(annotated_frame)
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Release resources
|
| 41 |
input_video.release()
|
| 42 |
+
output_video.release()
|
| 43 |
|
| 44 |
+
# Return the processed video file path
|
| 45 |
+
return output_video_path
|
| 46 |
|
| 47 |
# Create a Gradio interface for video upload
|
| 48 |
iface = gr.Interface(fn=process_video,
|
| 49 |
inputs=gr.Video(label="Upload Video"), # Updated line
|
| 50 |
+
outputs=gr.Video(label="Processed Video"), # This will display the output video directly
|
| 51 |
title="YOLOv8 Object Detection on Video",
|
| 52 |
description="Upload a video for object detection using YOLOv8")
|
| 53 |
|