Add Support for Equirectangular Images (#966)

This commit is contained in:
Kevin Chen authored and GitHub committed 2022-11-28 21:29:02 -08:00
1 parent 1d10e047c2
commit 87c3ead680
6 files changed
+16887 -3081

No files matched your search

+40 -1
View File
@@ -6,7 +6,7 @@ from itertools import product
import torch
from nerfstudio.cameras.cameras import Cameras
from nerfstudio.cameras.cameras import Cameras, CameraType
from nerfstudio.cameras.rays import RayBundle
BATCH_SIZE = 2
@@ -121,6 +121,44 @@ def test_pinhole_camera():
pinhole_camera.generate_rays(camera_indices=0, coords=coords)
def test_equirectangular_camera():
"""Test that the equirectangular camera model works."""
height = 100 # width is twice the height
c2w = torch.eye(4)[None, :3, :]
equirectangular_camera = Cameras(
cx=float(height),
cy=0.5 * float(height),
fx=float(height),
fy=float(height),
camera_to_worlds=c2w,
camera_type=CameraType.EQUIRECTANGULAR,
)
camera_ray_bundle = equirectangular_camera.generate_rays(camera_indices=0)
assert isinstance(camera_ray_bundle, RayBundle)
assert torch.allclose(camera_ray_bundle.origins[0], torch.tensor([0.0, 0.0, 0.0]))
# Check that the directions are mostly correct in local camera coordinates (+y is up, -z is forward)
directions = camera_ray_bundle.directions
threshold = 0.9
x = torch.tensor([1.0, 0.0, 0.0])
y = torch.tensor([0.0, 1.0, 0.0])
z = torch.tensor([0.0, 0.0, 1.0])
# top pixels point up
assert directions[0, 0] @ y > threshold
assert directions[0, height] @ y > threshold
assert directions[0, -1] @ y > threshold
# middle pixels point horizontally; middle of image is camera forwards
assert directions[height // 2, 0] @ z > threshold
assert directions[height // 2, height // 2] @ -x > threshold
assert directions[height // 2, height] @ -z > threshold
assert directions[height // 2, 3 * height // 2] @ x > threshold
assert directions[height // 2, -1] @ z > threshold
# bottom pixels point down
assert directions[-1, 0] @ -y > threshold
assert directions[-1, height] @ -y > threshold
assert directions[-1, -1] @ -y > threshold
def test_camera_as_tensordataclass():
"""Test that the camera class move to Tensordataclass works."""
_ = C2_DIST[torch.tensor([0]), torch.tensor([0])]
@@ -265,4 +303,5 @@ def _check_cam_shapes(cam: Cameras, _batch_size):
if __name__ == "__main__":
test_pinhole_camera()
test_equirectangular_camera()
test_camera_as_tensordataclass()