radial_and_tangential_undistort in nerfacc

This commit is contained in:
Ruilong Li committed 2023-04-07 20:10:43 +00:00
1 parent 39e6c97d42
commit 0cc168381e
2 files changed
+20 -8

No files matched your search

+19 -7
View File
@@ -25,6 +25,7 @@ from typing import Dict, List, Optional, Tuple, Union
import cv2 import cv2
import torch import torch
import torchvision import torchvision
from nerfacc.cameras import opencv_lens_undistortion
from torch.nn import Parameter from torch.nn import Parameter
from torchtyping import TensorType from torchtyping import TensorType
@@ -33,9 +34,9 @@ import nerfstudio.utils.poses as pose_utils
from nerfstudio.cameras import camera_utils from nerfstudio.cameras import camera_utils
from nerfstudio.cameras.rays import RayBundle from nerfstudio.cameras.rays import RayBundle
from nerfstudio.data.scene_box import SceneBox from nerfstudio.data.scene_box import SceneBox
from nerfstudio.utils import profiler
from nerfstudio.utils.misc import strtobool from nerfstudio.utils.misc import strtobool
from nerfstudio.utils.tensor_dataclass import TensorDataclass from nerfstudio.utils.tensor_dataclass import TensorDataclass
from nerfstudio.utils import profiler
TORCH_DEVICE = Union[torch.device, str] # pylint: disable=invalid-name TORCH_DEVICE = Union[torch.device, str] # pylint: disable=invalid-name
@@ -149,8 +150,6 @@ class Cameras(TensorDataclass):
self.__post_init__() # This will do the dataclass post_init and broadcast all the tensors self.__post_init__() # This will do the dataclass post_init and broadcast all the tensors
self._use_nerfacc = strtobool(os.environ.get("INTERSECT_WITH_NERFACC", "TRUE"))
def _init_get_fc_xy(self, fc_xy: Union[float, torch.Tensor], name: str) -> torch.Tensor: def _init_get_fc_xy(self, fc_xy: Union[float, torch.Tensor], name: str) -> torch.Tensor:
""" """
Parses the input focal length / principle point x or y and returns a tensor of the correct shape Parses the input focal length / principle point x or y and returns a tensor of the correct shape
@@ -636,10 +635,23 @@ class Cameras(TensorDataclass):
mask = (self.camera_type[true_indices] != CameraType.EQUIRECTANGULAR.value).squeeze(-1) # (num_rays) mask = (self.camera_type[true_indices] != CameraType.EQUIRECTANGULAR.value).squeeze(-1) # (num_rays)
coord_mask = torch.stack([mask, mask, mask], dim=0) coord_mask = torch.stack([mask, mask, mask], dim=0)
if mask.any(): if mask.any():
coord_stack[coord_mask, :] = camera_utils.radial_and_tangential_undistort( if distortion_params_delta is not None:
coord_stack[coord_mask, :].reshape(3, -1, 2), coord_stack[coord_mask, :] = camera_utils.radial_and_tangential_undistort(
distortion_params[mask, :], coord_stack[coord_mask, :].reshape(3, -1, 2),
).reshape(-1, 2) distortion_params[mask, :],
).reshape(-1, 2)
else:
# try to use nerfacc to accelerate if we don't need any gradient to optimize distortion params
try:
coord_stack[coord_mask, :] = opencv_lens_undistortion(
coord_stack[coord_mask, :].reshape(3, -1, 2),
distortion_params[mask, :],
).reshape(-1, 2)
except:
coord_stack[coord_mask, :] = camera_utils.radial_and_tangential_undistort(
coord_stack[coord_mask, :].reshape(3, -1, 2),
distortion_params[mask, :],
).reshape(-1, 2)
# Make sure after we have undistorted our images, the shapes are still correct # Make sure after we have undistorted our images, the shapes are still correct
assert coord_stack.shape == (3,) + num_rays_shape + (2,) assert coord_stack.shape == (3,) + num_rays_shape + (2,)
+1 -1
View File
@@ -30,7 +30,7 @@ dependencies = [
"mediapy>=1.1.0", "mediapy>=1.1.0",
"msgpack>=1.0.4", "msgpack>=1.0.4",
"msgpack_numpy>=0.4.8", "msgpack_numpy>=0.4.8",
"nerfacc==0.3.5", "nerfacc==0.5.2",
"open3d>=0.16.0", "open3d>=0.16.0",
"opencv-python==4.6.0.66", "opencv-python==4.6.0.66",
"Pillow>=9.3.0", "Pillow>=9.3.0",