mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-12 19:04:03 +08:00
27 lines
771 B
Python
27 lines
771 B
Python
"""
|
|
Test the camera classes.
|
|
"""
|
|
|
|
import torch
|
|
|
|
from nerfstudio.cameras.cameras import Cameras
|
|
from nerfstudio.cameras.rays import RayBundle
|
|
|
|
|
|
def test_pinhole_camera():
|
|
"""Test that the pinhole camera model works."""
|
|
c2w = torch.eye(4)[None, :3, :]
|
|
pinhole_camera = Cameras(cx=400.0, cy=400.0, fx=10.0, fy=10.0, camera_to_worlds=c2w)
|
|
camera_ray_bundle = pinhole_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]))
|
|
|
|
# Test generate rays on 1D input
|
|
num_rays = 10
|
|
coords = torch.ones(num_rays, 2)
|
|
pinhole_camera.generate_rays(camera_indices=0, coords=coords)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_pinhole_camera()
|