Update dataset loaders (#319)

* Update dataset loaders

* Set ngp default to blender
This commit is contained in:
Matthew Tancik authored and GitHub committed 2022-08-31 17:30:56 -07:00
1 parent 2a94afd9ec
commit 6ee6934581
6 files changed
+185 -113

No files matched your search

+12 -6
View File
@@ -58,6 +58,8 @@ class Cameras:
fy: Union[TensorType["num_cameras"], float],
cx: float,
cy: float,
width: Optional[int] = None,
height: Optional[int] = None,
distortion_params: Optional[TensorType["num_cameras", 6]] = None,
camera_type: CameraType = CameraType.PERSPECTIVE,
):
@@ -75,8 +77,8 @@ class Cameras:
self.distortion_params = distortion_params.broadcast_to((self._num_cameras, 6))
else:
self.distortion_params = None
self._image_heights = int(self.cy * 2)
self._image_widths = int(self.cx * 2)
self._image_heights = int(self.cy * 2) if height is None else height
self._image_widths = int(self.cx * 2) if width is None else width
self.camera_type = camera_type
@property
@@ -114,6 +116,8 @@ class Cameras:
fy=self.fy.to(device),
cx=self.cx,
cy=self.cy,
width=self.image_width,
height=self.image_height,
distortion_params=distortion_params,
camera_type=self.camera_type,
)
@@ -271,7 +275,9 @@ class Cameras:
Args:
scaling_factor: Scaling factor to apply to the output resolution.
"""
self.fx *= scaling_factor
self.fy *= scaling_factor
self.cx *= scaling_factor
self.cy *= scaling_factor
self.fx = self.fx * scaling_factor
self.fy = self.fy * scaling_factor
self.cx = self.cx * scaling_factor
self.cy = self.cy * scaling_factor
self._image_heights = int(self._image_heights * scaling_factor)
self._image_widths = int(self._image_widths * scaling_factor)
+23
View File
@@ -326,6 +326,29 @@ def viewmatrix(lookat, up, pos):
return m
def get_distortion_params(
k1: float = 0.0,
k2: float = 0.0,
k3: float = 0.0,
k4: float = 0.0,
p1: float = 0.0,
p2: float = 0.0,
):
"""Returns a distortion parameters matrix.
Args:
k1: The first radial distortion parameter.
k2: The second radial distortion parameter.
k3: The third radial distortion parameter.
k4: The fourth radial distortion parameter.
p1: The first tangential distortion parameter.
p2: The second tangential distortion parameter.
Returns:
torch.Tensor: A distortion parameters matrix.
"""
return torch.Tensor([k1, k2, k3, k4, p1, p2])
# Addapted from MultiNeRF
# https://github.com/google-research/multinerf/blob/b02228160d3179300c7d499dca28cb9ca3677f32/internal/camera_utils.py#L477-L509
def radial_and_tangential_undistort(