Update app.py
Browse files
app.py
CHANGED
|
@@ -136,7 +136,7 @@ def infer(f_in, interpolation, fps_output):
|
|
| 136 |
return final_vid, files
|
| 137 |
|
| 138 |
|
| 139 |
-
def remove_bg(fl):
|
| 140 |
frame = cv2.imread(fl).astype(np.uint8)
|
| 141 |
|
| 142 |
b = 5
|
|
@@ -165,8 +165,8 @@ def remove_bg(fl):
|
|
| 165 |
blur_s[i,j] = (d/512).astype(np.uint8)
|
| 166 |
|
| 167 |
#remove regions of low saturation and lightness (get scene without shadow)
|
| 168 |
-
m = cv2.inRange(cv2.cvtColor(frame_c, cv2.COLOR_RGB2HSV), np.array([0,0,0]), np.array([180,
|
| 169 |
-
mask = cv2.inRange(blur_s, 0,
|
| 170 |
masks = np.bitwise_and(m, mask)
|
| 171 |
frame[masks>0] = (127,127,127)
|
| 172 |
frame = cv2.medianBlur(frame, b)
|
|
@@ -292,7 +292,11 @@ with gr.Blocks() as demo:
|
|
| 292 |
with gr.Accordion(label="Upload files here", open=True):
|
| 293 |
files_input = gr.File(file_count="multiple", file_types=['image', '.mp4'])
|
| 294 |
gallery_input = gr.Gallery(label="Slideshow", preview=True, columns=8192, interactive=False)
|
| 295 |
-
files_input.upload(fn=loadf, inputs=[files_input], outputs=[files_input, gallery_input])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
with gr.Row():
|
| 297 |
interpolation_slider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Interpolation Steps: ")
|
| 298 |
interpolation = gr.Number(value=1, show_label=False, interactive=False)
|
|
@@ -310,7 +314,7 @@ with gr.Blocks() as demo:
|
|
| 310 |
gr.Examples(
|
| 311 |
examples=[[["./examples/0.png", "./examples/1.png", "./examples/2.png", "./examples/3.png", "./examples/4.png"], 1, 0]],
|
| 312 |
fn=loadf,
|
| 313 |
-
inputs=[files_input],
|
| 314 |
outputs=[files_input, gallery_input],
|
| 315 |
cache_examples=True
|
| 316 |
)
|
|
|
|
| 136 |
return final_vid, files
|
| 137 |
|
| 138 |
|
| 139 |
+
def remove_bg(fl, s, l, v):
|
| 140 |
frame = cv2.imread(fl).astype(np.uint8)
|
| 141 |
|
| 142 |
b = 5
|
|
|
|
| 165 |
blur_s[i,j] = (d/512).astype(np.uint8)
|
| 166 |
|
| 167 |
#remove regions of low saturation and lightness (get scene without shadow)
|
| 168 |
+
m = cv2.inRange(cv2.cvtColor(frame_c, cv2.COLOR_RGB2HSV), np.array([0,0,0]), np.array([180,s,l]))
|
| 169 |
+
mask = cv2.inRange(blur_s, 0, v)
|
| 170 |
masks = np.bitwise_and(m, mask)
|
| 171 |
frame[masks>0] = (127,127,127)
|
| 172 |
frame = cv2.medianBlur(frame, b)
|
|
|
|
| 292 |
with gr.Accordion(label="Upload files here", open=True):
|
| 293 |
files_input = gr.File(file_count="multiple", file_types=['image', '.mp4'])
|
| 294 |
gallery_input = gr.Gallery(label="Slideshow", preview=True, columns=8192, interactive=False)
|
| 295 |
+
files_input.upload(fn=loadf, inputs=[files_input, max_s, max_l, max_v], outputs=[files_input, gallery_input])
|
| 296 |
+
with gr.Accordion(label="Background removal settings", open=False):
|
| 297 |
+
max_s = gr.Slider(minimum=0, maximum=255, step=1, value=32, label="Shadow max saturation")
|
| 298 |
+
max_l = gr.Slider(minimum=0, maximum=255, step=1, value=64, label="Shadow max lightness")
|
| 299 |
+
max_v = gr.Slider(minimum=0, maximum=255, step=1, value=16, label="Shadow max variance")
|
| 300 |
with gr.Row():
|
| 301 |
interpolation_slider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Interpolation Steps: ")
|
| 302 |
interpolation = gr.Number(value=1, show_label=False, interactive=False)
|
|
|
|
| 314 |
gr.Examples(
|
| 315 |
examples=[[["./examples/0.png", "./examples/1.png", "./examples/2.png", "./examples/3.png", "./examples/4.png"], 1, 0]],
|
| 316 |
fn=loadf,
|
| 317 |
+
inputs=[files_input, max_s, max_l, max_v],
|
| 318 |
outputs=[files_input, gallery_input],
|
| 319 |
cache_examples=True
|
| 320 |
)
|