Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -115,8 +115,12 @@ def main(share=True):
|
|
| 115 |
cl, ind = pcd.remove_statistical_outlier(nb_neighbors=20, std_ratio=2.0)
|
| 116 |
pcd = pcd.select_by_index(ind)
|
| 117 |
|
| 118 |
-
tempdir = tempfile.
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
pointcloud_path = os.path.join(out_dir, 'pointcloud.ply')
|
| 121 |
|
| 122 |
# save pcd to temporary .ply
|
|
@@ -128,14 +132,14 @@ def main(share=True):
|
|
| 128 |
vertices[:, 2] = -vertices[:, 2]
|
| 129 |
vertices[:, 1] = -vertices[:, 1]
|
| 130 |
mesh = trimesh.PointCloud(vertices=vertices, colors=vertex_colors)
|
| 131 |
-
glb_path = os.path.join(
|
| 132 |
# tmp_glb = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)
|
| 133 |
mesh.export(glb_path)
|
| 134 |
|
| 135 |
|
| 136 |
# save raw depth (npy)
|
| 137 |
depth = cv2.resize(ppd_depth, (W, H), interpolation=cv2.INTER_LINEAR)
|
| 138 |
-
raw_depth_path = os.path.join(
|
| 139 |
np.save(raw_depth_path, depth)
|
| 140 |
|
| 141 |
# tmp_raw_depth = tempfile.NamedTemporaryFile(suffix='.npy', delete=False)
|
|
@@ -148,14 +152,20 @@ def main(share=True):
|
|
| 148 |
split_region = np.ones((image.shape[0], 50, 3), dtype=np.uint8) * 255
|
| 149 |
combined_result = cv2.hconcat([image[:, :, ::-1], split_region, colored_depth[:, :, ::-1]])
|
| 150 |
|
| 151 |
-
vis_path = os.path.join(
|
| 152 |
cv2.imwrite(vis_path, combined_result)
|
| 153 |
|
| 154 |
# tmp_concat = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
| 155 |
# cv2.imwrite(tmp_concat.name, combined_result)
|
| 156 |
|
| 157 |
# download_files = [tmp_concat.name, tmp_raw_depth.name, tmp_ply.name]
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
return [(image, colored_depth), glb_path, download_files]
|
| 161 |
|
|
|
|
| 115 |
cl, ind = pcd.remove_statistical_outlier(nb_neighbors=20, std_ratio=2.0)
|
| 116 |
pcd = pcd.select_by_index(ind)
|
| 117 |
|
| 118 |
+
tempdir = Path(tempfile.gettempdir(), 'ppd')
|
| 119 |
+
tempdir.mkdir(exist_ok=True)
|
| 120 |
+
output_path = Path(tempdir, request.session_hash)
|
| 121 |
+
shutil.rmtree(output_path, ignore_errors=True)
|
| 122 |
+
output_path.mkdir(exist_ok=True, parents=True)
|
| 123 |
+
|
| 124 |
pointcloud_path = os.path.join(out_dir, 'pointcloud.ply')
|
| 125 |
|
| 126 |
# save pcd to temporary .ply
|
|
|
|
| 132 |
vertices[:, 2] = -vertices[:, 2]
|
| 133 |
vertices[:, 1] = -vertices[:, 1]
|
| 134 |
mesh = trimesh.PointCloud(vertices=vertices, colors=vertex_colors)
|
| 135 |
+
glb_path = os.path.join(output_path, 'pointcloud.glb')
|
| 136 |
# tmp_glb = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)
|
| 137 |
mesh.export(glb_path)
|
| 138 |
|
| 139 |
|
| 140 |
# save raw depth (npy)
|
| 141 |
depth = cv2.resize(ppd_depth, (W, H), interpolation=cv2.INTER_LINEAR)
|
| 142 |
+
raw_depth_path = os.path.join(output_path, 'raw_depth.npy')
|
| 143 |
np.save(raw_depth_path, depth)
|
| 144 |
|
| 145 |
# tmp_raw_depth = tempfile.NamedTemporaryFile(suffix='.npy', delete=False)
|
|
|
|
| 152 |
split_region = np.ones((image.shape[0], 50, 3), dtype=np.uint8) * 255
|
| 153 |
combined_result = cv2.hconcat([image[:, :, ::-1], split_region, colored_depth[:, :, ::-1]])
|
| 154 |
|
| 155 |
+
vis_path = os.path.join(output_path, 'image_depth_vis.png')
|
| 156 |
cv2.imwrite(vis_path, combined_result)
|
| 157 |
|
| 158 |
# tmp_concat = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
| 159 |
# cv2.imwrite(tmp_concat.name, combined_result)
|
| 160 |
|
| 161 |
# download_files = [tmp_concat.name, tmp_raw_depth.name, tmp_ply.name]
|
| 162 |
+
file_names = ["image_depth_vis.png", "raw_depth.npy", "pointcloud.ply"]
|
| 163 |
+
download_files = [
|
| 164 |
+
(output_path / name).as_posix()
|
| 165 |
+
for name in file_names
|
| 166 |
+
if (output_path / name).exists()
|
| 167 |
+
]
|
| 168 |
+
# download_files = [vis_path, raw_depth_path, pointcloud_path]
|
| 169 |
|
| 170 |
return [(image, colored_depth), glb_path, download_files]
|
| 171 |
|