amirgame197 commited on
Commit
3cd966d
1 Parent(s): b88392f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -1,12 +1,12 @@
1
  import spaces
2
  import gradio as gr
3
- #import cv2
4
  #import numpy as np
5
 
6
  #from PIL import Image
7
  #from transparent_background import Remover
8
 
9
- import rembg
10
 
11
  #remover = Remover()
12
 
@@ -43,7 +43,24 @@ import rembg
43
 
44
  @spaces.GPU
45
  def doo(video):
46
- rembg.greenscreen(video, gpu=True, output="output.mp4", format="mp4", alpha=True, gpubatchsize=10)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  return 'output.mp4'
48
 
49
  iface = gr.Interface(fn=doo, inputs="video", outputs="video")
 
1
  import spaces
2
  import gradio as gr
3
+ import cv2
4
  #import numpy as np
5
 
6
  #from PIL import Image
7
  #from transparent_background import Remover
8
 
9
+ from backgroundremover import BackgroundRemover
10
 
11
  #remover = Remover()
12
 
 
43
 
44
  @spaces.GPU
45
  def doo(video):
46
+ video = cv2.VideoCapture(video)
47
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
48
+ out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (640, 480))
49
+ while(video.isOpened()):
50
+ ret, frame = video.read()
51
+ if ret == True:
52
+ # Remove the background from the frame
53
+ no_bg_frame = remover.remove(frame)
54
+
55
+ # Write the frame into the file 'output.mp4'
56
+ out.write(no_bg_frame)
57
+ else:
58
+ break
59
+
60
+ # Release everything when the job is finished
61
+ video.release()
62
+ out.release()
63
+ cv2.destroyAllWindows()
64
  return 'output.mp4'
65
 
66
  iface = gr.Interface(fn=doo, inputs="video", outputs="video")