mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 14:28:41 +08:00
Support non-pinhole rendering (#1141)
This commit is contained in:
1 parent
cc38d48294
commit
c338de4aa4
9 files changed
+191
-100
No files matched your search
@@ -23,7 +23,7 @@ import torch
|
||||
import nerfstudio.utils.poses as pose_utils
|
||||
from nerfstudio.cameras import camera_utils
|
||||
from nerfstudio.cameras.camera_utils import get_interpolated_poses_many
|
||||
from nerfstudio.cameras.cameras import Cameras
|
||||
from nerfstudio.cameras.cameras import Cameras, CameraType
|
||||
from nerfstudio.viewer.server.utils import three_js_perspective_camera_focal_length
|
||||
|
||||
|
||||
@@ -121,6 +121,19 @@ def get_path_from_json(camera_path: Dict[str, Any]) -> Cameras:
|
||||
|
||||
image_height = camera_path["render_height"]
|
||||
image_width = camera_path["render_width"]
|
||||
if "camera_type" in camera_path:
|
||||
camera_type = camera_path["camera_type"]
|
||||
else:
|
||||
camera_type = "perspective"
|
||||
|
||||
if "camera_type" not in camera_path:
|
||||
camera_type = CameraType.PERSPECTIVE
|
||||
elif camera_path["camera_type"] == "fisheye":
|
||||
camera_type = CameraType.FISHEYE
|
||||
elif camera_path["camera_type"] == "equirectangular":
|
||||
camera_type = CameraType.EQUIRECTANGULAR
|
||||
else:
|
||||
camera_type = CameraType.PERSPECTIVE
|
||||
|
||||
c2ws = []
|
||||
fxs = []
|
||||
@@ -129,11 +142,15 @@ def get_path_from_json(camera_path: Dict[str, Any]) -> Cameras:
|
||||
# pose
|
||||
c2w = torch.tensor(camera["camera_to_world"]).view(4, 4)[:3]
|
||||
c2ws.append(c2w)
|
||||
# field of view
|
||||
fov = camera["fov"]
|
||||
focal_length = three_js_perspective_camera_focal_length(fov, image_height)
|
||||
fxs.append(focal_length)
|
||||
fys.append(focal_length)
|
||||
if camera_type == CameraType.EQUIRECTANGULAR:
|
||||
fxs.append(image_width / 2)
|
||||
fys.append(image_height)
|
||||
else:
|
||||
# field of view
|
||||
fov = camera["fov"]
|
||||
focal_length = three_js_perspective_camera_focal_length(fov, image_height)
|
||||
fxs.append(focal_length)
|
||||
fys.append(focal_length)
|
||||
|
||||
camera_to_worlds = torch.stack(c2ws, dim=0)
|
||||
fx = torch.tensor(fxs)
|
||||
@@ -144,4 +161,5 @@ def get_path_from_json(camera_path: Dict[str, Any]) -> Cameras:
|
||||
cx=image_width / 2,
|
||||
cy=image_height / 2,
|
||||
camera_to_worlds=camera_to_worlds,
|
||||
camera_type=camera_type,
|
||||
)
|
||||
@@ -634,7 +634,7 @@ class Cameras(TensorDataclass):
|
||||
|
||||
directions_stack[..., 0][mask] = torch.masked_select(coord_stack[..., 0] * sin_theta / theta, mask).float()
|
||||
directions_stack[..., 1][mask] = torch.masked_select(coord_stack[..., 1] * sin_theta / theta, mask).float()
|
||||
directions_stack[..., 2][mask] = -torch.masked_select(torch.cos(theta), mask)
|
||||
directions_stack[..., 2][mask] = -torch.masked_select(torch.cos(theta), mask).float()
|
||||
|
||||
if CameraType.EQUIRECTANGULAR.value in cam_types:
|
||||
mask = (self.camera_type[true_indices] == CameraType.EQUIRECTANGULAR.value).squeeze(-1) # (num_rays)
|
||||
|
||||
Reference in new issue
Block a user