mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-04 14:58:55 +08:00
DNeRF Data Parser (#817)
* Add dnerf dataparser * Switch time to be stored per camera I realized it would be better downstream to store times on the ray bundle, and in order to store them on the ray bundle it's much easier to store them on the camera. Rather than having to revert this change, I just made it here.
This commit is contained in:
1 parent
6f158a3e68
commit
35610cb9e2
4 files changed
+122
-13
No files matched your search
@@ -81,6 +81,7 @@ class Cameras:
|
||||
camera_type: Optional[
|
||||
Union[TensorType["num_cameras"], int, List[CameraType], CameraType]
|
||||
] = CameraType.PERSPECTIVE,
|
||||
times: Optional[TensorType["num_cameras"]] = None,
|
||||
):
|
||||
self._num_cameras = camera_to_worlds.shape[0]
|
||||
self.camera_to_worlds = camera_to_worlds # This comes first since it determines @property self.device
|
||||
@@ -121,6 +122,8 @@ class Cameras:
|
||||
|
||||
self.camera_type = self._init_get_camera_type(camera_type)
|
||||
|
||||
self.times = times
|
||||
|
||||
def _init_get_camera_type(
|
||||
self, camera_type: Union[TensorType["num_cameras"], int, List[CameraType], CameraType]
|
||||
) -> TensorType["num_cameras"]:
|
||||
@@ -223,6 +226,7 @@ class Cameras:
|
||||
height=self.image_height.to(device),
|
||||
distortion_params=distortion_params.to(device) if distortion_params is not None else None,
|
||||
camera_type=self.camera_type.to(device),
|
||||
times=self.times.to(device) if self.times is not None else None,
|
||||
)
|
||||
|
||||
def get_image_coords(self, pixel_offset: float = 0.5) -> TensorType["height", "width", 2]:
|
||||
@@ -305,11 +309,7 @@ class Cameras:
|
||||
|
||||
sin_theta = torch.sin(theta)
|
||||
directions_stack = torch.stack(
|
||||
[
|
||||
coord_stack[..., 0] * sin_theta / theta,
|
||||
coord_stack[..., 1] * sin_theta / theta,
|
||||
-torch.cos(theta),
|
||||
],
|
||||
[coord_stack[..., 0] * sin_theta / theta, coord_stack[..., 1] * sin_theta / theta, -torch.cos(theta)],
|
||||
dim=-1,
|
||||
)
|
||||
else:
|
||||
@@ -338,17 +338,11 @@ class Cameras:
|
||||
ray_bundle_camera_indices = camera_indices.view(pixel_area.shape)
|
||||
|
||||
return RayBundle(
|
||||
origins=origins,
|
||||
directions=directions,
|
||||
pixel_area=pixel_area,
|
||||
camera_indices=ray_bundle_camera_indices,
|
||||
origins=origins, directions=directions, pixel_area=pixel_area, camera_indices=ray_bundle_camera_indices
|
||||
)
|
||||
|
||||
def to_json(
|
||||
self,
|
||||
camera_idx: int,
|
||||
image: Optional[TensorType["height", "width", 2]] = None,
|
||||
max_size: Optional[int] = None,
|
||||
self, camera_idx: int, image: Optional[TensorType["height", "width", 2]] = None, max_size: Optional[int] = None
|
||||
) -> Dict:
|
||||
"""Convert a camera to a json dictionary.
|
||||
|
||||
@@ -368,6 +362,7 @@ class Cameras:
|
||||
"fy": self.fy[camera_idx].tolist(),
|
||||
"camera_to_world": self.camera_to_worlds[camera_idx].tolist(),
|
||||
"camera_index": camera_idx,
|
||||
"times": self.times[camera_idx] if self.times is not None else None,
|
||||
}
|
||||
if image is not None:
|
||||
image_uint8 = (image * 255).detach().type(torch.uint8)
|
||||
@@ -422,6 +417,7 @@ class Cameras:
|
||||
width=self._image_widths[indices],
|
||||
distortion_params=self.distortion_params[indices] if self.distortion_params is not None else None,
|
||||
camera_type=self.camera_type[indices],
|
||||
times=self.times[indices] if self.times is not None else None,
|
||||
)
|
||||
if isinstance(indices, (int, slice)):
|
||||
indices = (indices,)
|
||||
@@ -437,4 +433,5 @@ class Cameras:
|
||||
if self.distortion_params is not None
|
||||
else None,
|
||||
camera_type=self.camera_type[indices + (slice(None),)],
|
||||
times=self.times[indices + (slice(None),)] if self.times is not None else None,
|
||||
)
|
||||
Reference in new issue
Block a user