umaradnaan commited on
Commit
6e11755
·
verified ·
1 Parent(s): 6fdeeb9

Update utils/pointcloud_utils.py

Browse files
Files changed (1) hide show
  1. utils/pointcloud_utils.py +27 -25
utils/pointcloud_utils.py CHANGED
@@ -1,25 +1,27 @@
1
- import open3d as o3d
2
- import numpy as np
3
- import cv2
4
- import os
5
-
6
- def depth_to_pointcloud(depth_maps, frame_paths, out_dir):
7
- points = []
8
-
9
- for depth, frame_path in zip(depth_maps, frame_paths):
10
- img = cv2.imread(frame_path)
11
- h, w = depth.shape
12
-
13
- for y in range(0, h, 10):
14
- for x in range(0, w, 10):
15
- z = depth[y, x]
16
- points.append([x, y, z])
17
-
18
- points = np.array(points)
19
- pcd = o3d.geometry.PointCloud()
20
- pcd.points = o3d.utility.Vector3dVector(points)
21
-
22
- out_path = os.path.join(out_dir, "model.ply")
23
- o3d.io.write_point_cloud(out_path, pcd)
24
-
25
- return out_path
 
 
 
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")