Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -262,7 +262,7 @@ def pano_depth_to_world_points(depth):
|
|
262 |
def rgb2gray(rgb):
|
263 |
return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
|
264 |
|
265 |
-
def get_mesh(image, depth, blur_data, loadall):
|
266 |
global frame_selected
|
267 |
global mesh
|
268 |
global mesh_n
|
@@ -328,7 +328,7 @@ def get_mesh(image, depth, blur_data, loadall):
|
|
328 |
glb_file = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)
|
329 |
scene.export(glb_file.name)
|
330 |
print('file - ok')
|
331 |
-
return glb_file.name, glb_file.name, ",".join(mesh_n)
|
332 |
|
333 |
def blur_image(image, depth, blur_data):
|
334 |
blur_a = blur_data.split()
|
@@ -413,9 +413,9 @@ def optimize(v, d):
|
|
413 |
cv2.imwrite(depths[k], depth)
|
414 |
|
415 |
if d == False:
|
416 |
-
return frames
|
417 |
else:
|
418 |
-
return depths
|
419 |
|
420 |
def bincount(a):
|
421 |
a2D = a.reshape(-1,a.shape[-1])
|
@@ -522,12 +522,13 @@ def draw_mask(l, t, v, d, evt: gr.EventData):
|
|
522 |
|
523 |
|
524 |
load_model="""
|
525 |
-
async(f, c, o)=>{
|
526 |
if (document.getElementById("iframe3D")) {
|
527 |
document.getElementById("iframe3D").src = "index.htm?file=" + f.path;
|
528 |
document.getElementById("iframe3D").onload = function() {
|
529 |
document.getElementById("iframe3D").contentDocument.getElementById("coords").value = c;
|
530 |
document.getElementById("iframe3D").contentDocument.getElementById("order").value = o;
|
|
|
531 |
}
|
532 |
toggleDisplay("model");
|
533 |
}
|
@@ -629,7 +630,7 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
629 |
output_switch = gr.Checkbox(label="Show depths")
|
630 |
optimize_switch = gr.Checkbox(label="Optimize")
|
631 |
output_switch.input(fn=switch_rows, inputs=[output_switch], outputs=[output_frame])
|
632 |
-
optimize_switch.input(fn=optimize, inputs=[optimize_switch, output_switch], outputs=[output_frame])
|
633 |
output_mask = gr.ImageEditor(layers=False, sources=('upload', 'clipboard'), show_download_button=True, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=0, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="image_edit")
|
634 |
with gr.Row():
|
635 |
selector = gr.HTML(value="""
|
@@ -933,9 +934,10 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
933 |
]"""
|
934 |
coords = gr.Textbox(elem_id="coords", value=example_coords, label="Coordinates", interactive=False)
|
935 |
mesh_order = gr.Textbox(elem_id="order", value="", label="Order", interactive=False)
|
|
|
936 |
|
937 |
result_file = gr.File(label="3D file (.glb)")
|
938 |
-
result_file.change(fn=None, inputs=[result_file, coords, mesh_order], outputs=None, js=load_model)
|
939 |
html = gr.HTML(value="""<label for='zoom'>Zoom</label><input id='zoom' type='range' style='width:256px;height:1em;' value='0.8' min='0.157' max='1.57' step='0.001' oninput='
|
940 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
941 |
var evt = document.createEvent(\"Event\");
|
@@ -1091,7 +1093,7 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
1091 |
return output_video_path + (json.dumps(locations),)
|
1092 |
|
1093 |
submit.click(on_submit, inputs=[input_video, model_type, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, coords])
|
1094 |
-
render.click(partial(get_mesh), inputs=[output_frame, output_mask, blur_in, load_all], outputs=[result, result_file, mesh_order])
|
1095 |
|
1096 |
example_files = os.listdir('examples')
|
1097 |
example_files.sort()
|
|
|
262 |
def rgb2gray(rgb):
|
263 |
return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
|
264 |
|
265 |
+
def get_mesh(image, depth, blur_data, loadall, dcolor):
|
266 |
global frame_selected
|
267 |
global mesh
|
268 |
global mesh_n
|
|
|
328 |
glb_file = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)
|
329 |
scene.export(glb_file.name)
|
330 |
print('file - ok')
|
331 |
+
return gr.Model3D(value=glb_file.name, clear_color=json.loads(dcolor)), glb_file.name, ",".join(mesh_n)
|
332 |
|
333 |
def blur_image(image, depth, blur_data):
|
334 |
blur_a = blur_data.split()
|
|
|
413 |
cv2.imwrite(depths[k], depth)
|
414 |
|
415 |
if d == False:
|
416 |
+
return frames, dcolor
|
417 |
else:
|
418 |
+
return depths, dcolor
|
419 |
|
420 |
def bincount(a):
|
421 |
a2D = a.reshape(-1,a.shape[-1])
|
|
|
522 |
|
523 |
|
524 |
load_model="""
|
525 |
+
async(f, c, o, b)=>{
|
526 |
if (document.getElementById("iframe3D")) {
|
527 |
document.getElementById("iframe3D").src = "index.htm?file=" + f.path;
|
528 |
document.getElementById("iframe3D").onload = function() {
|
529 |
document.getElementById("iframe3D").contentDocument.getElementById("coords").value = c;
|
530 |
document.getElementById("iframe3D").contentDocument.getElementById("order").value = o;
|
531 |
+
document.getElementById("iframe3D").contentDocument.getElementById("bgcolor").value = b;
|
532 |
}
|
533 |
toggleDisplay("model");
|
534 |
}
|
|
|
630 |
output_switch = gr.Checkbox(label="Show depths")
|
631 |
optimize_switch = gr.Checkbox(label="Optimize")
|
632 |
output_switch.input(fn=switch_rows, inputs=[output_switch], outputs=[output_frame])
|
633 |
+
optimize_switch.input(fn=optimize, inputs=[optimize_switch, output_switch], outputs=[output_frame, bgcolor])
|
634 |
output_mask = gr.ImageEditor(layers=False, sources=('upload', 'clipboard'), show_download_button=True, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=0, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="image_edit")
|
635 |
with gr.Row():
|
636 |
selector = gr.HTML(value="""
|
|
|
934 |
]"""
|
935 |
coords = gr.Textbox(elem_id="coords", value=example_coords, label="Coordinates", interactive=False)
|
936 |
mesh_order = gr.Textbox(elem_id="order", value="", label="Order", interactive=False)
|
937 |
+
bgcolor = gr.Textbox(elem_id="bgcolor", value="[127, 127, 127, 255]", label="Background color", interactive=False)
|
938 |
|
939 |
result_file = gr.File(label="3D file (.glb)")
|
940 |
+
result_file.change(fn=None, inputs=[result_file, coords, mesh_order, bgcolor], outputs=None, js=load_model)
|
941 |
html = gr.HTML(value="""<label for='zoom'>Zoom</label><input id='zoom' type='range' style='width:256px;height:1em;' value='0.8' min='0.157' max='1.57' step='0.001' oninput='
|
942 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
943 |
var evt = document.createEvent(\"Event\");
|
|
|
1093 |
return output_video_path + (json.dumps(locations),)
|
1094 |
|
1095 |
submit.click(on_submit, inputs=[input_video, model_type, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, coords])
|
1096 |
+
render.click(partial(get_mesh), inputs=[output_frame, output_mask, blur_in, load_all, bgcolor], outputs=[result, result_file, mesh_order])
|
1097 |
|
1098 |
example_files = os.listdir('examples')
|
1099 |
example_files.sort()
|