Update app.py
Browse files
app.py
CHANGED
|
@@ -287,6 +287,17 @@ def process_image(image, model_choice="GLPN (Recommended)", visualization_type="
|
|
| 287 |
pcd, depth=10, n_threads=1
|
| 288 |
)[0]
|
| 289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
# Rotate mesh
|
| 291 |
rotation = mesh.get_rotation_matrix_from_xyz((np.pi, 0, 0))
|
| 292 |
mesh.rotate(rotation, center=(0, 0, 0))
|
|
@@ -345,13 +356,31 @@ def process_image(image, model_choice="GLPN (Recommended)", visualization_type="
|
|
| 345 |
vertices = np.asarray(mesh.vertices)
|
| 346 |
triangles = np.asarray(mesh.triangles)
|
| 347 |
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
data.append(mesh_trace)
|
| 356 |
|
| 357 |
layout = go.Layout(
|
|
|
|
| 287 |
pcd, depth=10, n_threads=1
|
| 288 |
)[0]
|
| 289 |
|
| 290 |
+
# Transfer colors from point cloud to mesh vertices
|
| 291 |
+
print("Transferring colors to mesh...")
|
| 292 |
+
pcd_tree = o3d.geometry.KDTreeFlann(pcd)
|
| 293 |
+
mesh_colors = []
|
| 294 |
+
for vertex in mesh.vertices:
|
| 295 |
+
# Find nearest point in point cloud
|
| 296 |
+
[_, idx, _] = pcd_tree.search_knn_vector_3d(vertex, 1)
|
| 297 |
+
# Get color from nearest point
|
| 298 |
+
mesh_colors.append(pcd.colors[idx[0]])
|
| 299 |
+
mesh.vertex_colors = o3d.utility.Vector3dVector(np.array(mesh_colors))
|
| 300 |
+
|
| 301 |
# Rotate mesh
|
| 302 |
rotation = mesh.get_rotation_matrix_from_xyz((np.pi, 0, 0))
|
| 303 |
mesh.rotate(rotation, center=(0, 0, 0))
|
|
|
|
| 356 |
vertices = np.asarray(mesh.vertices)
|
| 357 |
triangles = np.asarray(mesh.triangles)
|
| 358 |
|
| 359 |
+
# Get vertex colors if available
|
| 360 |
+
if mesh.has_vertex_colors():
|
| 361 |
+
vertex_colors = np.asarray(mesh.vertex_colors)
|
| 362 |
+
colors_rgb = ['rgb({},{},{})'.format(int(r*255), int(g*255), int(b*255))
|
| 363 |
+
for r, g, b in vertex_colors]
|
| 364 |
+
|
| 365 |
+
mesh_trace = go.Mesh3d(
|
| 366 |
+
x=vertices[:, 0], y=vertices[:, 1], z=vertices[:, 2],
|
| 367 |
+
i=triangles[:, 0], j=triangles[:, 1], k=triangles[:, 2],
|
| 368 |
+
vertexcolor=colors_rgb,
|
| 369 |
+
opacity=0.95,
|
| 370 |
+
name='Mesh',
|
| 371 |
+
lighting=dict(ambient=0.5, diffuse=0.8, specular=0.2),
|
| 372 |
+
lightposition=dict(x=100, y=100, z=100)
|
| 373 |
+
)
|
| 374 |
+
else:
|
| 375 |
+
# Fallback if no colors
|
| 376 |
+
mesh_trace = go.Mesh3d(
|
| 377 |
+
x=vertices[:, 0], y=vertices[:, 1], z=vertices[:, 2],
|
| 378 |
+
i=triangles[:, 0], j=triangles[:, 1], k=triangles[:, 2],
|
| 379 |
+
color='lightblue',
|
| 380 |
+
opacity=0.9,
|
| 381 |
+
name='Mesh'
|
| 382 |
+
)
|
| 383 |
+
|
| 384 |
data.append(mesh_trace)
|
| 385 |
|
| 386 |
layout = go.Layout(
|