Spaces:
Running
on
Zero
Running
on
Zero
amirgame197
commited on
Commit
•
ce6434e
1
Parent(s):
6ef9294
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
-
|
5 |
-
from PIL import Image
|
6 |
from transparent_background import Remover
|
7 |
|
8 |
-
remover = Remover(mode='fast')
|
9 |
-
|
10 |
-
#def doo(image):
|
11 |
-
#img = Image.fromarray(image).convert('RGB') # read image
|
12 |
-
#out = remover.process(img) # default setting - transparent background
|
13 |
-
|
14 |
-
#out.save('output.png') # save result
|
15 |
-
#return out
|
16 |
|
17 |
def doo(video):
|
18 |
-
cap = cv2.VideoCapture(video)
|
19 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
while cap.isOpened():
|
24 |
-
ret, frame = cap.read()
|
25 |
-
|
26 |
if ret is False:
|
27 |
break
|
28 |
-
|
29 |
-
frame
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
38 |
cap.release()
|
39 |
-
|
40 |
-
|
|
|
41 |
|
42 |
iface = gr.Interface(fn=doo, inputs="video", outputs="video")
|
43 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
|
|
|
|
4 |
from transparent_background import Remover
|
5 |
|
6 |
+
remover = Remover(mode='fast') # Custom setting
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def doo(video):
|
9 |
+
cap = cv2.VideoCapture(video) # Video reader for input
|
10 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
11 |
+
|
12 |
+
processed_frames = [] # List to store processed frames
|
13 |
+
|
14 |
while cap.isOpened():
|
15 |
+
ret, frame = cap.read() # Read video
|
16 |
+
|
17 |
if ret is False:
|
18 |
break
|
19 |
+
|
20 |
+
# Assuming frame is a NumPy array (e.g., shape: (height, width, 3))
|
21 |
+
# Perform background removal using the model
|
22 |
+
# Replace this placeholder code with actual model inference
|
23 |
+
|
24 |
+
# Example: Apply a simple threshold to create a binary mask
|
25 |
+
gray_frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
|
26 |
+
_, mask = cv2.threshold(gray_frame, 200, 255, cv2.THRESH_BINARY)
|
27 |
+
|
28 |
+
# Create a masked frame
|
29 |
+
masked_frame = cv2.bitwise_and(frame, frame, mask=mask)
|
30 |
+
|
31 |
+
# Append the processed frame to the output
|
32 |
+
processed_frames.append(masked_frame)
|
33 |
+
|
34 |
cap.release()
|
35 |
+
|
36 |
+
# Return the list of processed frames
|
37 |
+
return processed_frames
|
38 |
|
39 |
iface = gr.Interface(fn=doo, inputs="video", outputs="video")
|
40 |
+
iface.launch()
|