mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-11 10:34:29 +08:00
Record3D bugfixes (#382)
* fixing bbox and rotation matrix. * added rotation. * cleanup. * fix coordinate system rotation. * added orientation as config.
This commit is contained in:
parent
26f7c5ddd3
commit
cbebde0d58
@ -293,7 +293,7 @@ class InstantNGPDataParserConfig(DataParserConfig):
|
||||
|
||||
@dataclass
|
||||
class Record3DDataParserConfig(DataParserConfig):
|
||||
"""Mipnerf 360 dataset config"""
|
||||
"""Record3D dataset config"""
|
||||
|
||||
_target: Type = Record3D
|
||||
"""target class to instantiate"""
|
||||
|
||||
@ -21,11 +21,12 @@ import numpy as np
|
||||
import torch
|
||||
from scipy.spatial.transform import Rotation
|
||||
|
||||
from nerfactory.cameras import utils as camera_utils
|
||||
from nerfactory.cameras.cameras import Cameras, CameraType
|
||||
from nerfactory.configs import base as cfg
|
||||
from nerfactory.datamanagers.dataparsers.base import DataParser
|
||||
from nerfactory.datamanagers.dataparsers.mipnerf_parser import Mipnerf360
|
||||
from nerfactory.datamanagers.structs import DatasetInputs, SceneBounds
|
||||
from nerfactory.utils import poses as pose_utils
|
||||
from nerfactory.utils.io import get_absolute_path, load_from_json
|
||||
|
||||
|
||||
@ -70,24 +71,6 @@ class Record3D(DataParser):
|
||||
image_filenames = image_filenames[idx]
|
||||
num_images = len(image_filenames)
|
||||
|
||||
# Normalization similar to Mipnerf360
|
||||
poses = Mipnerf360.normalize_orientation(poses)
|
||||
|
||||
bottom = np.reshape([0, 0, 0, 1.0], [1, 4])
|
||||
bottom = np.tile(np.reshape(bottom, [1, 1, 4]), [poses.shape[0], 1, 1])
|
||||
poses = np.concatenate([poses[:, :3, :4], bottom], -2).astype(np.float32)
|
||||
|
||||
rotation_matrix = np.array(
|
||||
[
|
||||
[1.0, 0.0, 0.0, 0.0],
|
||||
[0.0, 0.0, -1.0, 0.0],
|
||||
[0.0, 1.0, 0.0, 0.0],
|
||||
[0.0, 0.0, 0.0, 1.0],
|
||||
],
|
||||
dtype=np.float32,
|
||||
)
|
||||
poses = rotation_matrix @ poses
|
||||
|
||||
idx_test = np.arange(num_images)[:: self.config.val_skip]
|
||||
idx_train = np.array([i for i in np.arange(num_images) if i not in idx_test])
|
||||
idx = idx_train if split == "train" else idx_test
|
||||
@ -97,10 +80,19 @@ class Record3D(DataParser):
|
||||
image_filenames = image_filenames[idx]
|
||||
poses = poses[idx]
|
||||
|
||||
# Centering poses
|
||||
poses[:, :3, 3] = poses[:, :3, 3] - np.mean(poses[:, :3, 3], axis=0)
|
||||
# convert to Tensors
|
||||
poses = torch.from_numpy(poses[:, :3, :4])
|
||||
|
||||
camera_to_world = torch.from_numpy(poses[:, :3, :4]) # camera to world transform
|
||||
# convert OpenGL to OpenCV coordinate system
|
||||
poses = poses @ torch.diag(torch.tensor([1.0, -1.0, -1.0, 1.0]))
|
||||
|
||||
poses = camera_utils.auto_orient_poses(pose_utils.to4x4(poses), method=self.config.orientation_method)[
|
||||
:, :3, :4
|
||||
]
|
||||
|
||||
# Centering poses
|
||||
poses[:, :3, 3] = poses[:, :3, 3] - torch.mean(poses[:, :3, 3], dim=0)
|
||||
poses = pose_utils.normalize(poses)
|
||||
|
||||
# Camera intrinsics
|
||||
K = np.array(metadata_dict["K"]).reshape((3, 3)).T
|
||||
@ -127,7 +119,7 @@ class Record3D(DataParser):
|
||||
fy=focal_length,
|
||||
cx=cx,
|
||||
cy=cy,
|
||||
camera_to_worlds=camera_to_world,
|
||||
camera_to_worlds=poses,
|
||||
camera_type=CameraType.PERSPECTIVE,
|
||||
)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user