Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -336,16 +336,17 @@ def switch_rows(v):
|
|
336 |
print(frames[0])
|
337 |
return frames
|
338 |
|
339 |
-
def draw_mask(v, d, evt: gr.EventData):
|
340 |
print(v)
|
341 |
vv = json.loads(v)
|
342 |
pts = np.array(vv, np.int32)
|
343 |
pts = pts.reshape((-1,1,2))
|
344 |
|
345 |
bg = cv2.cvtColor(d["background"], cv2.COLOR_RGB2GRAY)
|
346 |
-
gd = cv2.cvtColor(cv2.imread(masks[len(masks)-1]), cv2.COLOR_RGB2GRAY)-
|
347 |
-
|
348 |
-
|
|
|
349 |
|
350 |
d["layers"][0] = cv2.fillPoly(d["layers"][0], [pts], (0,0,0,255))
|
351 |
d["composite"] = cv2.fillPoly(d["composite"], [pts], (0,0,0,255))
|
@@ -404,6 +405,7 @@ with gr.Blocks(css=css) as demo:
|
|
404 |
output_switch = gr.Checkbox(label="Show depths")
|
405 |
output_switch.input(fn=switch_rows, inputs=[output_switch], outputs=[output_frame])
|
406 |
output_mask = gr.ImageEditor(layers=True, sources=None, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=0, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="image_edit")
|
|
|
407 |
selector = gr.HTML(value="""<div id='select_cursor' style='width:1px;height:1px;position:absolute;border:8px dotted #ffffff;opacity:50%;'></div>
|
408 |
<a href='#' id='selector' onclick='this.style.fontWeight=\"bold\";
|
409 |
document.body.appendChild(document.getElementById(\"select_cursor\"));
|
@@ -460,7 +462,7 @@ with gr.Blocks(css=css) as demo:
|
|
460 |
document.getElementById(\"select_cursor\").style.top = 0;
|
461 |
' title='Clear selection' style='text-decoration:none;color:white;'>[x] Clear selection</a>""")
|
462 |
mouse = gr.Textbox(elem_id="mouse", value="""[]""", interactive=False)
|
463 |
-
output_mask.apply(fn=draw_mask, inputs=[mouse, output_mask], outputs=[output_mask])
|
464 |
submit = gr.Button("Submit")
|
465 |
with gr.Column():
|
466 |
model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
|
|
|
336 |
print(frames[0])
|
337 |
return frames
|
338 |
|
339 |
+
def draw_mask(th, v, d, evt: gr.EventData):
|
340 |
print(v)
|
341 |
vv = json.loads(v)
|
342 |
pts = np.array(vv, np.int32)
|
343 |
pts = pts.reshape((-1,1,2))
|
344 |
|
345 |
bg = cv2.cvtColor(d["background"], cv2.COLOR_RGB2GRAY)
|
346 |
+
gd = (cv2.cvtColor(cv2.imread(masks[len(masks)-1]), cv2.COLOR_RGB2GRAY)-th).astype(np.uint8)
|
347 |
+
diff = abs(bg-gd).astype(np.uint8)
|
348 |
+
mask = cv2.inRange(diff, 0, 5)
|
349 |
+
d["background"][mask>0] = (0,0,0,255)
|
350 |
|
351 |
d["layers"][0] = cv2.fillPoly(d["layers"][0], [pts], (0,0,0,255))
|
352 |
d["composite"] = cv2.fillPoly(d["composite"], [pts], (0,0,0,255))
|
|
|
405 |
output_switch = gr.Checkbox(label="Show depths")
|
406 |
output_switch.input(fn=switch_rows, inputs=[output_switch], outputs=[output_frame])
|
407 |
output_mask = gr.ImageEditor(layers=True, sources=None, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=0, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="image_edit")
|
408 |
+
threshold = gr.Slider(value=127, minimum=1, maximum=255, step=1)
|
409 |
selector = gr.HTML(value="""<div id='select_cursor' style='width:1px;height:1px;position:absolute;border:8px dotted #ffffff;opacity:50%;'></div>
|
410 |
<a href='#' id='selector' onclick='this.style.fontWeight=\"bold\";
|
411 |
document.body.appendChild(document.getElementById(\"select_cursor\"));
|
|
|
462 |
document.getElementById(\"select_cursor\").style.top = 0;
|
463 |
' title='Clear selection' style='text-decoration:none;color:white;'>[x] Clear selection</a>""")
|
464 |
mouse = gr.Textbox(elem_id="mouse", value="""[]""", interactive=False)
|
465 |
+
output_mask.apply(fn=draw_mask, inputs=[threshold, mouse, output_mask], outputs=[output_mask])
|
466 |
submit = gr.Button("Submit")
|
467 |
with gr.Column():
|
468 |
model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
|