Spaces:
Running
on
Zero
Running
on
Zero
amirgame197
commited on
Commit
•
1a37b1b
1
Parent(s):
d33123a
Update app.py
Browse files
app.py
CHANGED
@@ -10,29 +10,31 @@ remover = Remover()
|
|
10 |
|
11 |
@spaces.GPU
|
12 |
def doo(video):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
writer
|
30 |
-
|
31 |
-
processed_frames += 1
|
32 |
-
print(f"Processing: {processed_frames}")
|
33 |
-
out = remover.process(img, type='green')
|
34 |
-
writer.write(cv2.cvtColor(np.array(out), cv2.COLOR_BGR2RGB))
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
cap.release()
|
37 |
writer.release()
|
38 |
return 'output.mp4'
|
|
|
10 |
|
11 |
@spaces.GPU
|
12 |
def doo(video):
|
13 |
+
try:
|
14 |
+
cap = cv2.VideoCapture(video)
|
15 |
+
fps = cap.get(cv2.CAP_PROP_FPS)
|
16 |
+
|
17 |
+
processed_frames = 0
|
18 |
+
writer = None
|
19 |
+
|
20 |
+
while cap.isOpened():
|
21 |
+
ret, frame = cap.read()
|
22 |
+
|
23 |
+
if ret is False:
|
24 |
+
break
|
25 |
+
|
26 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
27 |
+
img = Image.fromarray(frame).convert('RGB')
|
28 |
+
|
29 |
+
if writer is None:
|
30 |
+
writer = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), fps, img.size)
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
processed_frames += 1
|
33 |
+
print(f"Processing: {processed_frames}")
|
34 |
+
out = remover.process(img, type='green')
|
35 |
+
writer.write(cv2.cvtColor(np.array(out), cv2.COLOR_BGR2RGB))
|
36 |
+
except:
|
37 |
+
pass
|
38 |
cap.release()
|
39 |
writer.release()
|
40 |
return 'output.mp4'
|