Add a point cloud option for Record3D (#3556)

* Add a point cloud option for Record3D

* Change parameter names and add voxel size parameter

* fix record3d point cloud docs formatting
This commit is contained in:
Jameson Crate authored and GitHub committed 2024-12-24 01:02:52 +00:00
1 parent 14f1d4ed62
commit 0ced5cecdd
6 files changed
+67 -4

No files matched your search

+25
View File
@@ -268,6 +268,31 @@ ns-process-data record3d --data {data directory} --output-dir {output directory}
ns-train nerfacto --data {output directory} ns-train nerfacto --data {output directory}
``` ```
### Adding a Point Cloud
Adding a point cloud is useful for avoiding random initialization when training gaussian splats. To add a point cloud using Record3D follow these steps:
1. Export a Zipped sequence of PLY point clouds from Record3D.
<img src="imgs/record_3d_video_example.png" width=150>
<img src="imgs/record_3d_export_button.png" width=150>
<img src="imgs/record_3d_ply_selection.png" width=150>
2. Move the exported zip file to your computer from your iPhone.
3. Unzip the file and move all extracted `.ply` files to a directory.
4. Convert the data to nerfstudio format with the `--ply` flag and the directory from step 3.
```bash
ns-process-data record3d --data {data directory} --ply {ply directory} --output-dir {output directory}
```
Additionally you can specify `--voxel-size {float}` which determines the level of sparsity when downsampling from the dense point clouds generated by Record3D to the sparse point cloud used in Nerfstudio. The default value is 0.8, lower is less sparse, higher is more sparse.
(spectacularai)= (spectacularai)=
## Spectacular AI ## Spectacular AI
Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

+29 -3
View File
@@ -16,23 +16,32 @@
import json import json
from pathlib import Path from pathlib import Path
from typing import List from typing import List, Optional
import numpy as np import numpy as np
import open3d as o3d
from scipy.spatial.transform import Rotation from scipy.spatial.transform import Rotation
from nerfstudio.process_data.process_data_utils import CAMERA_MODELS from nerfstudio.process_data.process_data_utils import CAMERA_MODELS
from nerfstudio.utils import io from nerfstudio.utils import io
def record3d_to_json(images_paths: List[Path], metadata_path: Path, output_dir: Path, indices: np.ndarray) -> int: def record3d_to_json(
images_paths: List[Path],
metadata_path: Path,
output_dir: Path,
indices: np.ndarray,
ply_dirname: Optional[Path],
voxel_size: Optional[float],
) -> int:
"""Converts Record3D's metadata and image paths to a JSON file. """Converts Record3D's metadata and image paths to a JSON file.
Args: Args:
images_paths: list if image paths. images_paths: list of image paths.
metadata_path: Path to the Record3D metadata JSON file. metadata_path: Path to the Record3D metadata JSON file.
output_dir: Path to the output directory. output_dir: Path to the output directory.
indices: Indices to sample the metadata_path. Should be the same length as images_paths. indices: Indices to sample the metadata_path. Should be the same length as images_paths.
ply_dirname: Path to the directory of exported ply files.
Returns: Returns:
The number of registered images. The number of registered images.
@@ -87,6 +96,23 @@ def record3d_to_json(images_paths: List[Path], metadata_path: Path, output_dir:
out["frames"] = frames out["frames"] = frames
# If .ply directory exists add the sparse point cloud for gsplat point initialization
if ply_dirname is not None:
assert ply_dirname.exists(), f"Directory not found: {ply_dirname}"
assert ply_dirname.is_dir(), f"Path given is not a directory: {ply_dirname}"
# Create sparce point cloud
pcd = o3d.geometry.PointCloud()
for ply_filename in ply_dirname.iterdir():
temp_pcd = o3d.io.read_point_cloud(str(ply_filename))
pcd += temp_pcd.voxel_down_sample(voxel_size=voxel_size)
# Save point cloud
points3D = np.asarray(pcd.points)
pcd.points = o3d.utility.Vector3dVector(points3D)
o3d.io.write_point_cloud(str(output_dir / "sparse_pc.ply"), pcd, write_ascii=True)
out["ply_file_path"] = "sparse_pc.ply"
with open(output_dir / "transforms.json", "w", encoding="utf-8") as f: with open(output_dir / "transforms.json", "w", encoding="utf-8") as f:
json.dump(out, f, indent=4) json.dump(out, f, indent=4)
+13 -1
View File
@@ -49,6 +49,11 @@ class ProcessRecord3D(BaseConverterToNerfstudioDataset):
2. Converts Record3D poses into the nerfstudio format. 2. Converts Record3D poses into the nerfstudio format.
""" """
ply_dir: Optional[Path] = None
"""Path to the Record3D directory of point export ply files."""
voxel_size: Optional[float] = 0.8
"""Voxel size for down sampling dense point cloud"""
num_downscales: int = 3 num_downscales: int = 3
"""Number of times to downscale the images. Downscales by 2 each time. For example a value of 3 """Number of times to downscale the images. Downscales by 2 each time. For example a value of 3
will downscale the images by 2x, 4x, and 8x.""" will downscale the images by 2x, 4x, and 8x."""
@@ -101,7 +106,14 @@ class ProcessRecord3D(BaseConverterToNerfstudioDataset):
) )
metadata_path = self.data / "metadata.json" metadata_path = self.data / "metadata.json"
record3d_utils.record3d_to_json(copied_image_paths, metadata_path, self.output_dir, indices=idx) record3d_utils.record3d_to_json(
copied_image_paths,
metadata_path,
self.output_dir,
indices=idx,
ply_dirname=self.ply_dir,
voxel_size=self.voxel_size,
)
CONSOLE.rule("[bold green]:tada: :tada: :tada: All DONE :tada: :tada: :tada:") CONSOLE.rule("[bold green]:tada: :tada: :tada: All DONE :tada: :tada: :tada:")
for summary in summary_log: for summary in summary_log: