Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -134,7 +134,7 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
|
|
134 |
if not ret:
|
135 |
break
|
136 |
|
137 |
-
frame = cv2.cvtColor(raw_frame, cv2.
|
138 |
frame_pil = Image.fromarray((frame * 255).astype(np.uint8))
|
139 |
frame = transform({'image': frame})['image']
|
140 |
|
@@ -464,6 +464,7 @@ def reset_mask():
|
|
464 |
return masks[frame_selected], f"f{frame_selected}_dmap.png"
|
465 |
|
466 |
def apply_mask(d, b):
|
|
|
467 |
global frame_selected
|
468 |
global masks
|
469 |
global depths
|
@@ -477,17 +478,23 @@ def apply_mask(d, b):
|
|
477 |
dilation = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2 * b + 1, 2 * b + 1), (b, b))
|
478 |
dmask = cv2.dilate(mask, dilation)
|
479 |
|
480 |
-
d["background"][mask==255] = (
|
481 |
-
mask = cv2.inRange(d["background"], np.array([
|
482 |
|
483 |
for k, mk in enumerate(masks):
|
484 |
if k != frame_selected and k < len(depths):
|
485 |
masks[k] = cv2.imread(depths[k]).astype(np.uint8)
|
486 |
-
masks[k][dmask<255] = (
|
487 |
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
masks[frame_selected] = d["background"]
|
489 |
cv2.imwrite(f"f{frame_selected}_dmap.png", masks[frame_selected])
|
490 |
-
return masks[frame_selected], f"f{frame_selected}_dmap.png"
|
491 |
|
492 |
def draw_mask(l, t, v, d, evt: gr.EventData):
|
493 |
global params
|
@@ -786,7 +793,7 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
786 |
bsize = gr.Slider(label="Border size", value=15, maximum=256, minimum=1, step=2)
|
787 |
mouse = gr.Textbox(elem_id="mouse", value="""[]""", interactive=False)
|
788 |
mouse.input(fn=draw_mask, show_progress="minimal", inputs=[levels, tolerance, mouse, output_mask], outputs=[output_mask])
|
789 |
-
apply.click(fn=apply_mask, inputs=[output_mask, bsize], outputs=[output_mask, depth_file])
|
790 |
reset.click(fn=reset_mask, inputs=None, outputs=[output_mask, depth_file])
|
791 |
with gr.Column():
|
792 |
model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
|
|
|
134 |
if not ret:
|
135 |
break
|
136 |
|
137 |
+
frame = cv2.cvtColor(raw_frame, cv2.COLOR_BGR2RGBA) / 255.0
|
138 |
frame_pil = Image.fromarray((frame * 255).astype(np.uint8))
|
139 |
frame = transform({'image': frame})['image']
|
140 |
|
|
|
464 |
return masks[frame_selected], f"f{frame_selected}_dmap.png"
|
465 |
|
466 |
def apply_mask(d, b):
|
467 |
+
global frames
|
468 |
global frame_selected
|
469 |
global masks
|
470 |
global depths
|
|
|
478 |
dilation = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2 * b + 1, 2 * b + 1), (b, b))
|
479 |
dmask = cv2.dilate(mask, dilation)
|
480 |
|
481 |
+
d["background"][mask==255] = (0,0,0,0)
|
482 |
+
mask = cv2.inRange(d["background"], np.array([0,0,0,0]), np.array([0,0,0,0]))
|
483 |
|
484 |
for k, mk in enumerate(masks):
|
485 |
if k != frame_selected and k < len(depths):
|
486 |
masks[k] = cv2.imread(depths[k]).astype(np.uint8)
|
487 |
+
masks[k][dmask<255] = (0,0,0)
|
488 |
|
489 |
+
ksize = np.sqrt(np.sum(mask) / 255)
|
490 |
+
frame = cv2.imread(frames[frame_selected]).astype(np.uint8)
|
491 |
+
dmask = cv2.GaussianBlur(dmask, (ksize,ksize), 0)
|
492 |
+
frame[3] = 255 - dmask
|
493 |
+
cv2.imwrite(frames[frame_selected], frame)
|
494 |
+
|
495 |
masks[frame_selected] = d["background"]
|
496 |
cv2.imwrite(f"f{frame_selected}_dmap.png", masks[frame_selected])
|
497 |
+
return masks[frame_selected], f"f{frame_selected}_dmap.png", frames
|
498 |
|
499 |
def draw_mask(l, t, v, d, evt: gr.EventData):
|
500 |
global params
|
|
|
793 |
bsize = gr.Slider(label="Border size", value=15, maximum=256, minimum=1, step=2)
|
794 |
mouse = gr.Textbox(elem_id="mouse", value="""[]""", interactive=False)
|
795 |
mouse.input(fn=draw_mask, show_progress="minimal", inputs=[levels, tolerance, mouse, output_mask], outputs=[output_mask])
|
796 |
+
apply.click(fn=apply_mask, inputs=[output_mask, bsize], outputs=[output_mask, depth_file, output_frame])
|
797 |
reset.click(fn=reset_mask, inputs=None, outputs=[output_mask, depth_file])
|
798 |
with gr.Column():
|
799 |
model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
|