Alpersx commited on
Commit
67388d8
·
verified ·
1 Parent(s): 3f650e2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2 as cv
2
+ import numpy as np
3
+ import gradio as gr
4
+ import os
5
+
6
+ def process_video(input_video):
7
+ output_path = "car_output.mp4"
8
+
9
+ cap = cv.VideoCapture(input_video)
10
+ fourcc = cv.VideoWriter_fourcc(*"mp4v")
11
+ fps = int(cap.get(cv.CAP_PROP_FPS))
12
+ width = int(cap.get(cv.CAP_PROP_FRAME_WIDTH))
13
+ height = int(cap.get(cv.CAP_PROP_FRAME_HEIGHT))
14
+ out = cv.VideoWriter(output_path, fourcc, fps, (width, height))
15
+
16
+ while cap.isOpened():
17
+ ret, frame = cap.read()
18
+ if not ret:
19
+ break
20
+
21
+ b, g, r = cv.split(frame)
22
+ rgb_frame = cv.merge((r, g, b))
23
+ out.write(rgb_frame)
24
+
25
+ cap.release()
26
+ out.release()
27
+
28
+ return output_path
29
+
30
+ gr.Interface(
31
+ fn=process_video,
32
+ inputs=gr.Video(label="Upload a video"),
33
+ outputs=gr.Video(label="Processed Video Output"),
34
+ title="RGB Channel Swap Video Processor",
35
+ description="This app reads a video, swaps the BGR to RGB channel, and shows the processed video.",
36
+ allow_flagging="never" # Disable flag button
37
+ ).launch()