Spaces:
Runtime error
Runtime error
jens
commited on
Commit
·
effc523
1
Parent(s):
2f74de8
instance on cubes
Browse files- app.py +4 -3
- inference.py +20 -0
app.py
CHANGED
@@ -34,7 +34,8 @@ with block:
|
|
34 |
with gr.Row():
|
35 |
input_image = gr.Image(label='Input', height=512, type='pil')
|
36 |
masks_annotated_image = gr.AnnotatedImage(label='Segments', height=512)
|
37 |
-
pcl_figure = gr.
|
|
|
38 |
#cutout_galary = gr.Gallery(label='Cutouts', object_fit='contain', height=512)
|
39 |
with gr.Row():
|
40 |
with gr.Column(scale=1):
|
@@ -53,8 +54,8 @@ with block:
|
|
53 |
print("depth reconstruction")
|
54 |
image = inputs[raw_image]
|
55 |
# depth reconstruction
|
56 |
-
|
57 |
-
return {pcl_figure:
|
58 |
|
59 |
depth_reconstruction_btn.click(on_depth_reconstruction_btn_click, components, [pcl_figure], queue=False)
|
60 |
|
|
|
34 |
with gr.Row():
|
35 |
input_image = gr.Image(label='Input', height=512, type='pil')
|
36 |
masks_annotated_image = gr.AnnotatedImage(label='Segments', height=512)
|
37 |
+
pcl_figure = gr.Model3D(label="3-D Reconstruction", clear_color=[1.0, 1.0, 1.0, 1.0])
|
38 |
+
#gr.Plot(label='3D Reconstruction')
|
39 |
#cutout_galary = gr.Gallery(label='Cutouts', object_fit='contain', height=512)
|
40 |
with gr.Row():
|
41 |
with gr.Column(scale=1):
|
|
|
54 |
print("depth reconstruction")
|
55 |
image = inputs[raw_image]
|
56 |
# depth reconstruction
|
57 |
+
path = dpt.generate_obj(image)
|
58 |
+
return {pcl_figure: path}
|
59 |
|
60 |
depth_reconstruction_btn.click(on_depth_reconstruction_btn_click, components, [pcl_figure], queue=False)
|
61 |
|
inference.py
CHANGED
@@ -69,6 +69,26 @@ class DepthPredictor:
|
|
69 |
ax = fig.add_subplot(111, projection='3d')
|
70 |
ax.scatter(points,size=0.01, c=colors, marker='o')
|
71 |
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
|
74 |
|
|
|
69 |
ax = fig.add_subplot(111, projection='3d')
|
70 |
ax.scatter(points,size=0.01, c=colors, marker='o')
|
71 |
return fig
|
72 |
+
|
73 |
+
def generate_obj(self, image):
|
74 |
+
# Step 1: Create a point cloud
|
75 |
+
point_cloud, color_array = self.generate_pcl(image)
|
76 |
+
# sample 1000 points
|
77 |
+
idxs = np.random.choice(len(point_cloud), 1000)
|
78 |
+
point_cloud = point_cloud[idxs]
|
79 |
+
color_array = color_array[idxs]
|
80 |
+
# Create a mesh to hold the colored cubes
|
81 |
+
mesh = o3d.geometry.TriangleMesh()
|
82 |
+
# Create cubes and add them to the mesh
|
83 |
+
for point, color in zip(point_cloud, color_array):
|
84 |
+
cube = o3d.geometry.TriangleMesh.create_box(width=0.01, height=0.01, depth=0.01)
|
85 |
+
cube.translate(point)
|
86 |
+
cube.paint_uniform_color(color)
|
87 |
+
mesh += cube
|
88 |
+
# Save the mesh to an .obj file
|
89 |
+
output_file = "./cloud.obj"
|
90 |
+
o3d.io.write_triangle_mesh(output_file, mesh)
|
91 |
+
return output_file
|
92 |
|
93 |
|
94 |
|