Export camera path (#398)

* export button working

* view changes

* adding copy to clipboard feature

* camera choice dropdown

* going to add script saving next

* copy paste working. need to add aspect ratio

* aspect overlay kind of working

* lint

* aspect ratio fixed. version specified

* merge

* openrelay back
This commit is contained in:
Ethan Weber authored and GitHub committed 2022-09-13 11:33:58 -07:00
1 parent f21375ff1b
commit 9bc39d895c
21 files changed
+676 -196

No files matched your search

+41 -3
View File
@@ -16,7 +16,7 @@
Code for camera paths.
"""
from typing import Optional, Tuple
from typing import Any, Dict, Optional, Tuple
import torch
@@ -24,6 +24,7 @@ import nerfactory.cameras.utils as camera_utils
import nerfactory.utils.poses as pose_utils
from nerfactory.cameras.cameras import Cameras
from nerfactory.cameras.utils import get_interpolated_poses_many
from nerfactory.viewer.server.utils import three_js_perspective_camera_focal_length
def get_interpolated_camera_path(cameras: Cameras, steps: int) -> Cameras:
@@ -75,9 +76,7 @@ def get_spiral_path(
else:
raise ValueError("Only one of radius or radiuses must be specified.")
# TODO: don't hardcode this. pass this in
up = camera.camera_to_worlds[0, :3, 2] # scene is z up
# up = camera.camera_to_world[:3, 1] # this will rotate 90 degrees
focal = torch.min(camera.fx[0], camera.fy[0])
target = torch.tensor([0, 0, -focal], device=camera.device) # camera looking in -z direction
@@ -98,5 +97,44 @@ def get_spiral_path(
for local_c2wh in local_c2whs:
c2wh = torch.matmul(c2wh_global, local_c2wh)
new_c2ws.append(c2wh[:3, :4])
new_c2ws = torch.stack(new_c2ws, dim=0)
return Cameras(fx=camera.fx[0], fy=camera.fy[0], cx=camera.cx, cy=camera.cy, camera_to_worlds=new_c2ws)
def get_path_from_json(camera_path: Dict[str, Any]) -> Cameras:
"""Takes a camera path dictionary and returns a trajectory as a Camera instance.
Args:
camera_path: A dictionary of the camera path information coming from the viewer.
Returns:
A Cameras instance with the camera path.
"""
image_height = camera_path["render_height"]
image_width = camera_path["render_width"]
c2ws = []
fxs = []
fys = []
for camera in camera_path["camera_path"]:
# 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)
camera_to_worlds = torch.stack(c2ws, dim=0)
fx = torch.tensor(fxs)
fy = torch.tensor(fys)
return Cameras(
fx=fx,
fy=fy,
cx=image_width / 2,
cy=image_height / 2,
camera_to_worlds=camera_to_worlds,
)
+1
View File
@@ -18,6 +18,7 @@ Camera transformation helper code.
"""
import math
from turtle import width
from typing import List, Literal, Optional, Tuple
import numpy as np