nagasurendra commited on
Commit
98cc7fb
·
verified ·
1 Parent(s): 177b569

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
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 an empty list to store processed frames
21
- processed_frames = []
 
 
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
- # Convert the annotated frame to RGB format
36
- annotated_frame_rgb = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
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 frames as an output video in Gradio
45
- return processed_frames
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