Spaces:
Sleeping
Sleeping
Update utils/pointcloud_utils.py
Browse files- utils/pointcloud_utils.py +27 -25
utils/pointcloud_utils.py
CHANGED
|
@@ -1,25 +1,27 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def depth_to_pointcloud(depth_maps, frame_paths, out_dir):
|
| 5 |
+
points = []
|
| 6 |
+
|
| 7 |
+
for depth in depth_maps:
|
| 8 |
+
h, w = depth.shape
|
| 9 |
+
for y in range(0, h, 12):
|
| 10 |
+
for x in range(0, w, 12):
|
| 11 |
+
points.append([x, y, depth[y, x]])
|
| 12 |
+
|
| 13 |
+
points = np.array(points, dtype=np.float32)
|
| 14 |
+
|
| 15 |
+
out_path = os.path.join(out_dir, "model.ply")
|
| 16 |
+
write_ply(points, out_path)
|
| 17 |
+
return out_path
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def write_ply(points, path):
|
| 21 |
+
with open(path, "w") as f:
|
| 22 |
+
f.write("ply\nformat ascii 1.0\n")
|
| 23 |
+
f.write(f"element vertex {len(points)}\n")
|
| 24 |
+
f.write("property float x\nproperty float y\nproperty float z\n")
|
| 25 |
+
f.write("end_header\n")
|
| 26 |
+
for p in points:
|
| 27 |
+
f.write(f"{p[0]} {p[1]} {p[2]}\n")
|