Spaces:
Runtime error
Runtime error
jens
commited on
Commit
·
c1883e2
1
Parent(s):
e7e0776
3d segmentation reconstruction
Browse files
app.py
CHANGED
@@ -9,18 +9,26 @@ import numpy as np
|
|
9 |
def snap(image, video):
|
10 |
depth_predictor = DepthPredictor()
|
11 |
depth_result = depth_predictor.predict(image)
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
demo = gr.Interface(
|
19 |
snap,
|
20 |
inputs=[gr.Image(source="webcam", tool=None, type="pil"),
|
21 |
gr.Video(source="webcam")],
|
22 |
-
outputs=[gr.Image(label="
|
23 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
24 |
)
|
25 |
|
26 |
if __name__ == "__main__":
|
|
|
9 |
def snap(image, video):
|
10 |
depth_predictor = DepthPredictor()
|
11 |
depth_result = depth_predictor.predict(image)
|
12 |
+
rgb_gltf_path = create_3d_obj(np.array(image), depth_result, path='./rgb.gltf')
|
13 |
+
|
14 |
+
segment_predictor = SegmentPredictor()
|
15 |
+
sam_result = segment_predictor.predict(image)
|
16 |
+
seg_gltf_path = create_3d_obj(np.array(sam_result), depth_result, path='./seg.gltf')
|
17 |
+
|
18 |
+
return [image, depth_result, sam_result, rgb_gltf_path, seg_gltf_path]#[depth_result, gltf_path, gltf_path]
|
19 |
|
20 |
|
21 |
demo = gr.Interface(
|
22 |
snap,
|
23 |
inputs=[gr.Image(source="webcam", tool=None, type="pil"),
|
24 |
gr.Video(source="webcam")],
|
25 |
+
outputs=[gr.Image(label="RGB", type="pil"),
|
26 |
+
gr.Image(label="predicted depth", type="pil"),
|
27 |
+
gr.Image(label="predicted segmentation", type="pil"),
|
28 |
+
gr.Model3D(label="3D mesh reconstruction - RGB",
|
29 |
+
clear_color=[1.0, 1.0, 1.0, 1.0]),
|
30 |
+
gr.Model3D(label="3D mesh reconstruction - Segmented",
|
31 |
+
clear_color=[1.0, 1.0, 1.0, 1.0])]
|
32 |
)
|
33 |
|
34 |
if __name__ == "__main__":
|
utils.py
CHANGED
@@ -2,7 +2,7 @@ import numpy as np
|
|
2 |
import open3d as o3d
|
3 |
|
4 |
|
5 |
-
def create_3d_obj(rgb_image, depth_image, depth=10):
|
6 |
depth_o3d = o3d.geometry.Image(depth_image)
|
7 |
image_o3d = o3d.geometry.Image(rgb_image)
|
8 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
@@ -47,7 +47,7 @@ def create_3d_obj(rgb_image, depth_image, depth=10):
|
|
47 |
# mesh.remove_vertices_by_mask(vertices_to_remove)
|
48 |
bbox = pcd.get_axis_aligned_bounding_box()
|
49 |
mesh_crop = mesh.crop(bbox)
|
50 |
-
gltf_path =
|
51 |
o3d.io.write_triangle_mesh(
|
52 |
gltf_path, mesh_crop, write_triangle_uvs=True)
|
53 |
return gltf_path
|
|
|
2 |
import open3d as o3d
|
3 |
|
4 |
|
5 |
+
def create_3d_obj(rgb_image, depth_image, depth=10, path='./image.gltf'):
|
6 |
depth_o3d = o3d.geometry.Image(depth_image)
|
7 |
image_o3d = o3d.geometry.Image(rgb_image)
|
8 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
|
|
47 |
# mesh.remove_vertices_by_mask(vertices_to_remove)
|
48 |
bbox = pcd.get_axis_aligned_bounding_box()
|
49 |
mesh_crop = mesh.crop(bbox)
|
50 |
+
gltf_path = path
|
51 |
o3d.io.write_triangle_mesh(
|
52 |
gltf_path, mesh_crop, write_triangle_uvs=True)
|
53 |
return gltf_path
|