Spaces:
Running
on
Zero
Running
on
Zero
Update code for .ply file downloading
Browse files
app.py
CHANGED
@@ -116,11 +116,13 @@ def predictions_to_glb(
|
|
116 |
|
117 |
# Initialize a 3D scene
|
118 |
scene_3d = trimesh.Scene()
|
|
|
119 |
|
120 |
# Add point cloud data to the scene
|
121 |
point_cloud_data = trimesh.PointCloud(vertices=vertices_3d, colors=colors_rgb)
|
122 |
|
123 |
scene_3d.add_geometry(point_cloud_data)
|
|
|
124 |
|
125 |
# Prepare 4x4 matrices for camera extrinsics
|
126 |
num_cameras = len(camera_poses)
|
@@ -140,9 +142,10 @@ def predictions_to_glb(
|
|
140 |
align_rotation[:3, :3] = Rotation.from_euler("y", 100, degrees=True).as_matrix() # plane rotate
|
141 |
align_rotation[:3, :3] = align_rotation[:3, :3] @ Rotation.from_euler("x", 155, degrees=True).as_matrix() # roll
|
142 |
scene_3d.apply_transform(align_rotation)
|
|
|
143 |
|
144 |
print("GLB Scene built")
|
145 |
-
return scene_3d
|
146 |
|
147 |
def integrate_camera_into_scene(scene: trimesh.Scene, transform: np.ndarray, face_colors: tuple, scene_scale: float):
|
148 |
"""
|
@@ -454,7 +457,7 @@ def gradio_demo(
|
|
454 |
)
|
455 |
|
456 |
# Convert predictions to GLB
|
457 |
-
glbscene = predictions_to_glb(
|
458 |
predictions,
|
459 |
conf_thres=conf_thres,
|
460 |
filter_by_frames=frame_filter,
|
@@ -464,7 +467,7 @@ def gradio_demo(
|
|
464 |
|
465 |
# we save a .ply file too
|
466 |
plyfile = glbfile.replace('.glb', '.ply')
|
467 |
-
|
468 |
|
469 |
# Cleanup
|
470 |
del predictions
|
@@ -530,7 +533,7 @@ def update_visualization(
|
|
530 |
)
|
531 |
|
532 |
if not os.path.exists(glbfile):
|
533 |
-
glbscene = predictions_to_glb(
|
534 |
predictions,
|
535 |
conf_thres=conf_thres,
|
536 |
filter_by_frames=frame_filter,
|
@@ -538,7 +541,7 @@ def update_visualization(
|
|
538 |
)
|
539 |
glbscene.export(file_obj=glbfile)
|
540 |
|
541 |
-
|
542 |
|
543 |
return glbfile, "Updating Visualization"
|
544 |
|
|
|
116 |
|
117 |
# Initialize a 3D scene
|
118 |
scene_3d = trimesh.Scene()
|
119 |
+
scene_3d_no_cam = trimesh.Scene()
|
120 |
|
121 |
# Add point cloud data to the scene
|
122 |
point_cloud_data = trimesh.PointCloud(vertices=vertices_3d, colors=colors_rgb)
|
123 |
|
124 |
scene_3d.add_geometry(point_cloud_data)
|
125 |
+
scene_3d_no_cam.add_geometry(point_cloud_data)
|
126 |
|
127 |
# Prepare 4x4 matrices for camera extrinsics
|
128 |
num_cameras = len(camera_poses)
|
|
|
142 |
align_rotation[:3, :3] = Rotation.from_euler("y", 100, degrees=True).as_matrix() # plane rotate
|
143 |
align_rotation[:3, :3] = align_rotation[:3, :3] @ Rotation.from_euler("x", 155, degrees=True).as_matrix() # roll
|
144 |
scene_3d.apply_transform(align_rotation)
|
145 |
+
scene_3d_no_cam.apply_transform(align_rotation)
|
146 |
|
147 |
print("GLB Scene built")
|
148 |
+
return scene_3d, scene_3d_no_cam
|
149 |
|
150 |
def integrate_camera_into_scene(scene: trimesh.Scene, transform: np.ndarray, face_colors: tuple, scene_scale: float):
|
151 |
"""
|
|
|
457 |
)
|
458 |
|
459 |
# Convert predictions to GLB
|
460 |
+
glbscene, glbscene_no_cam = predictions_to_glb(
|
461 |
predictions,
|
462 |
conf_thres=conf_thres,
|
463 |
filter_by_frames=frame_filter,
|
|
|
467 |
|
468 |
# we save a .ply file too
|
469 |
plyfile = glbfile.replace('.glb', '.ply')
|
470 |
+
glbscene_no_cam.export(file_obj=plyfile)
|
471 |
|
472 |
# Cleanup
|
473 |
del predictions
|
|
|
533 |
)
|
534 |
|
535 |
if not os.path.exists(glbfile):
|
536 |
+
glbscene, glbscene_no_cam = predictions_to_glb(
|
537 |
predictions,
|
538 |
conf_thres=conf_thres,
|
539 |
filter_by_frames=frame_filter,
|
|
|
541 |
)
|
542 |
glbscene.export(file_obj=glbfile)
|
543 |
|
544 |
+
glbscene_no_cam.export(file_obj=glbfile.replace('.glb', '.ply'))
|
545 |
|
546 |
return glbfile, "Updating Visualization"
|
547 |
|