Spaces:
Sleeping
Sleeping
| import numpy as np | |
| import os | |
| def depth_to_pointcloud(depth_maps, frame_paths, out_dir): | |
| points = [] | |
| for depth in depth_maps: | |
| h, w = depth.shape | |
| for y in range(0, h, 12): | |
| for x in range(0, w, 12): | |
| points.append([x, y, depth[y, x]]) | |
| points = np.array(points, dtype=np.float32) | |
| out_path = os.path.join(out_dir, "model.ply") | |
| write_ply(points, out_path) | |
| return out_path | |
| def write_ply(points, path): | |
| with open(path, "w") as f: | |
| f.write("ply\nformat ascii 1.0\n") | |
| f.write(f"element vertex {len(points)}\n") | |
| f.write("property float x\nproperty float y\nproperty float z\n") | |
| f.write("end_header\n") | |
| for p in points: | |
| f.write(f"{p[0]} {p[1]} {p[2]}\n") | |