File size: 771 Bytes
6e11755
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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")