Skip to content

Commit 3873f45

Browse files
committed
Add sparse_pc.ply to support Nerfstudio 1.0
1 parent 71c15d0 commit 3873f45

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

python/cli/process/process.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ def blurScore(path):
7676
magnitude_spectrum = np.abs(f_transform_shifted)
7777
return np.percentile(magnitude_spectrum, 95)
7878

79+
def point_cloud_data_frame_to_ply(df, out_fn):
80+
with open(out_fn, 'wt') as f:
81+
f.write('\n'.join([
82+
'ply',
83+
'format ascii 1.0',
84+
'element vertex %d' % len(df),
85+
'property float x',
86+
'property float y',
87+
'property float z',
88+
'property uint8 red',
89+
'property uint8 green',
90+
'property uint8 blue',
91+
'end_header'
92+
]) + '\n')
93+
for _, row in df.iterrows():
94+
r = []
95+
for prop in 'xyz': r.append(row[prop])
96+
for prop in 'rgb': r.append(int(row[prop]))
97+
f.write(' '.join([str(v) for v in r]) + '\n')
98+
7999
def convert_json_taichi_to_nerfstudio(d):
80100
import numpy as np
81101
def transform_camera(c):
@@ -102,7 +122,8 @@ def transform_camera(c):
102122
"w": c['camera_width'],
103123
"h": c['camera_height'],
104124
"aabb_scale": 16,
105-
'frames': []
125+
"frames": [],
126+
"ply_file_path": "./sparse_pc.ply"
106127
}
107128
cam_id = json.dumps(params, sort_keys=True)
108129
if cam_id not in by_camera:
@@ -455,6 +476,9 @@ def write_colmap_csv(data, fn):
455476
for row in data:
456477
f.write(' '.join([str(c) for c in row])+'\n')
457478

479+
# splatfacto point cloud format
480+
point_cloud_data_frame_to_ply(merged_df, f"{args.output}/sparse_pc.ply")
481+
458482
write_colmap_csv(c_points, f"{fake_colmap}/points3D.txt")
459483
write_colmap_csv(c_images, f"{fake_colmap}/images.txt")
460484
write_colmap_csv(c_cameras, f"{fake_colmap}/cameras.txt")

0 commit comments

Comments
 (0)