Update app.py
Browse files
app.py
CHANGED
@@ -548,7 +548,7 @@ def apply_mask(d, b):
|
|
548 |
cv2.imwrite(masks[frame_selected], mask) #d["background"]
|
549 |
return masks[frame_selected], depths, frames
|
550 |
|
551 |
-
def draw_mask(l, t, v, d, evt: gr.EventData):
|
552 |
global depths
|
553 |
global params
|
554 |
global frame_selected
|
@@ -599,7 +599,7 @@ def draw_mask(l, t, v, d, evt: gr.EventData):
|
|
599 |
res = center[label.flatten()]
|
600 |
bg = res.reshape((bg.shape))
|
601 |
|
602 |
-
bg[bd>
|
603 |
bg[mask>0] = 0
|
604 |
bg[bg==255] = 0
|
605 |
|
@@ -973,8 +973,9 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
973 |
levels = gr.Slider(label="Color levels", value=16, maximum=32, minimum=2, step=1)
|
974 |
tolerance = gr.Slider(label="Tolerance", value=1, maximum=7, minimum=0, step=1)
|
975 |
bsize = gr.Slider(label="Border size", value=15, maximum=256, minimum=1, step=2)
|
|
|
976 |
mouse = gr.Textbox(elem_id="mouse", value="""[]""", interactive=False)
|
977 |
-
mouse.input(fn=draw_mask, show_progress="minimal", inputs=[levels, tolerance, mouse, output_mask], outputs=[output_mask])
|
978 |
apply.click(fn=apply_mask, inputs=[output_mask, bsize], outputs=[output_mask, output_depth, output_frame])
|
979 |
reset.click(fn=reset_mask, inputs=None, outputs=[output_mask, output_depth])
|
980 |
|
|
|
548 |
cv2.imwrite(masks[frame_selected], mask) #d["background"]
|
549 |
return masks[frame_selected], depths, frames
|
550 |
|
551 |
+
def draw_mask(l, t, th, v, d, evt: gr.EventData):
|
552 |
global depths
|
553 |
global params
|
554 |
global frame_selected
|
|
|
599 |
res = center[label.flatten()]
|
600 |
bg = res.reshape((bg.shape))
|
601 |
|
602 |
+
bg[bd>th] = 0
|
603 |
bg[mask>0] = 0
|
604 |
bg[bg==255] = 0
|
605 |
|
|
|
973 |
levels = gr.Slider(label="Color levels", value=16, maximum=32, minimum=2, step=1)
|
974 |
tolerance = gr.Slider(label="Tolerance", value=1, maximum=7, minimum=0, step=1)
|
975 |
bsize = gr.Slider(label="Border size", value=15, maximum=256, minimum=1, step=2)
|
976 |
+
threshold = gr.Slider(label="Threshold", value=20, maximum=127, minimum=0, step=1)
|
977 |
mouse = gr.Textbox(elem_id="mouse", value="""[]""", interactive=False)
|
978 |
+
mouse.input(fn=draw_mask, show_progress="minimal", inputs=[levels, tolerance, threshold, mouse, output_mask], outputs=[output_mask])
|
979 |
apply.click(fn=apply_mask, inputs=[output_mask, bsize], outputs=[output_mask, output_depth, output_frame])
|
980 |
reset.click(fn=reset_mask, inputs=None, outputs=[output_mask, output_depth])
|
981 |
|