mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-27 03:20:34 +08:00
Add pointcloud loading for blender parser (#2902)
* Add pointcloud loading for blender parser * Fix argument * Fix docstring * Fix metadata in dataparsers * Add changes from review * Avoid changing default behavior * Apply `scale_factor` to loaded points --------- Co-authored-by: Brent Yi <yibrenth@gmail.com>
This commit is contained in:
1 parent
03bdeff2ad
commit
c302cc5301
1 file changed
+22
-1
@@ -17,10 +17,11 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Type
|
from typing import Optional, Type
|
||||||
|
|
||||||
import imageio
|
import imageio
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import open3d as o3d
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from nerfstudio.cameras.cameras import Cameras, CameraType
|
from nerfstudio.cameras.cameras import Cameras, CameraType
|
||||||
@@ -42,6 +43,9 @@ class BlenderDataParserConfig(DataParserConfig):
|
|||||||
"""How much to scale the camera origins by."""
|
"""How much to scale the camera origins by."""
|
||||||
alpha_color: str = "white"
|
alpha_color: str = "white"
|
||||||
"""alpha color of background"""
|
"""alpha color of background"""
|
||||||
|
ply_path: Optional[Path] = None
|
||||||
|
"""Path to PLY file to load 3D points from, defined relative to the dataset directory. This is helpful for
|
||||||
|
Gaussian splatting and generally unused otherwise. If `None`, points are initialized randomly."""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -94,12 +98,29 @@ class Blender(DataParser):
|
|||||||
camera_type=CameraType.PERSPECTIVE,
|
camera_type=CameraType.PERSPECTIVE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
metadata = {}
|
||||||
|
if self.config.ply_path is not None:
|
||||||
|
metadata.update(self._load_3D_points(self.config.data / self.config.ply_path))
|
||||||
|
|
||||||
dataparser_outputs = DataparserOutputs(
|
dataparser_outputs = DataparserOutputs(
|
||||||
image_filenames=image_filenames,
|
image_filenames=image_filenames,
|
||||||
cameras=cameras,
|
cameras=cameras,
|
||||||
alpha_color=self.alpha_color_tensor,
|
alpha_color=self.alpha_color_tensor,
|
||||||
scene_box=scene_box,
|
scene_box=scene_box,
|
||||||
dataparser_scale=self.scale_factor,
|
dataparser_scale=self.scale_factor,
|
||||||
|
metadata=metadata,
|
||||||
)
|
)
|
||||||
|
|
||||||
return dataparser_outputs
|
return dataparser_outputs
|
||||||
|
|
||||||
|
def _load_3D_points(self, ply_file_path: Path):
|
||||||
|
pcd = o3d.io.read_point_cloud(str(ply_file_path))
|
||||||
|
|
||||||
|
points3D = torch.from_numpy(np.asarray(pcd.points, dtype=np.float32) * self.config.scale_factor)
|
||||||
|
points3D_rgb = torch.from_numpy((np.asarray(pcd.colors) * 255).astype(np.uint8))
|
||||||
|
|
||||||
|
out = {
|
||||||
|
"points3D_xyz": points3D,
|
||||||
|
"points3D_rgb": points3D_rgb,
|
||||||
|
}
|
||||||
|
return out
|
||||||
Reference in new issue
Block a user