mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-21 15:15:43 +08:00
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:
1 parent
f21375ff1b
commit
9bc39d895c
21 files changed
+676
-196
No files matched your search
+23
-6
@@ -18,8 +18,10 @@ import yaml
|
||||
from tqdm import tqdm
|
||||
from typing_extensions import assert_never
|
||||
|
||||
# pylint: disable=unused-import
|
||||
from nerfactory.cameras.camera_paths import (
|
||||
get_interpolated_camera_path,
|
||||
get_path_from_json,
|
||||
get_spiral_path,
|
||||
)
|
||||
from nerfactory.cameras.cameras import Cameras
|
||||
@@ -98,6 +100,7 @@ def _render_trajectory_video(
|
||||
rendered_output_name: str,
|
||||
rendered_resolution_scaling_factor: float = 1.0,
|
||||
num_rays_per_chunk: int = 4096,
|
||||
seconds: float = 5.0,
|
||||
) -> None:
|
||||
"""Helper function to create a video of the spiral trajectory.
|
||||
|
||||
@@ -109,6 +112,7 @@ def _render_trajectory_video(
|
||||
rendered_resolution_scaling_factor: Scaling factor to apply to the camera image resolution.
|
||||
Defaults to 1.0.
|
||||
num_rays_per_chunk: Number of rays to use per chunk. Defaults to 4096.
|
||||
seconds: Number for the output video. Defaults to 5.0.
|
||||
"""
|
||||
print("Creating trajectory video.")
|
||||
images = []
|
||||
@@ -121,7 +125,6 @@ def _render_trajectory_video(
|
||||
image = outputs[rendered_output_name].cpu().numpy()
|
||||
images.append(image)
|
||||
|
||||
seconds = 5.0
|
||||
fps = len(images) / seconds
|
||||
media.write_video(output_filename, images, fps=fps)
|
||||
|
||||
@@ -198,24 +201,37 @@ class RenderTrajectory:
|
||||
# Name of the renderer output to use. rgb, depth, etc.
|
||||
rendered_output_name: str = "rgb"
|
||||
# Trajectory to render.
|
||||
traj: Literal["spiral", "interp"] = "spiral"
|
||||
traj: Literal["spiral", "interp", "filename"] = "spiral"
|
||||
# Scaling factor to apply to the camera image resolution.
|
||||
rendered_resolution_scaling_factor: float = 1.0
|
||||
downscale_factor: int = 1
|
||||
# Filename of the camera path to render.
|
||||
camera_path_filename: Path = Path("camera_path.json")
|
||||
# Name of the output file.
|
||||
output_path: Path = Path("output.mp4")
|
||||
# How long the video should be.
|
||||
seconds: float = 5.0
|
||||
|
||||
def main(self) -> None:
|
||||
"""Main function."""
|
||||
config, pipeline, _ = _eval_setup(self.load_config)
|
||||
|
||||
seconds = self.seconds
|
||||
|
||||
# TODO(ethan): use camera information from parsing args
|
||||
if self.traj == "spiral":
|
||||
camera_start = pipeline.datamanager.eval_dataloader.get_camera(image_idx=0)
|
||||
# TODO(ethan): pass in the up direction of the camera
|
||||
camera_path = get_spiral_path(camera_start, steps=30, radius=0.1)
|
||||
elif self.traj == "interp":
|
||||
cameras = pipeline.datamanager.eval_dataloader.get_camera(image_idx=[0, 10])
|
||||
camera_path = get_interpolated_camera_path(cameras, steps=30)
|
||||
# cameras_a = pipeline.datamanager.eval_dataloader.get_camera(image_idx=0)
|
||||
# cameras_b = pipeline.datamanager.eval_dataloader.get_camera(image_idx=10)
|
||||
# camera_path = get_interpolated_camera_path(cameras, steps=30)
|
||||
raise NotImplementedError("Interpolated camera path not implemented.")
|
||||
elif self.traj == "filename":
|
||||
with open(self.camera_path_filename, "r", encoding="utf-8") as f:
|
||||
camera_path = json.load(f)
|
||||
seconds = camera_path["seconds"]
|
||||
camera_path = get_path_from_json(camera_path)
|
||||
else:
|
||||
assert_never(self.traj)
|
||||
|
||||
@@ -224,8 +240,9 @@ class RenderTrajectory:
|
||||
camera_path,
|
||||
output_filename=self.output_path,
|
||||
rendered_output_name=self.rendered_output_name,
|
||||
rendered_resolution_scaling_factor=self.rendered_resolution_scaling_factor,
|
||||
rendered_resolution_scaling_factor=1.0 / self.downscale_factor,
|
||||
num_rays_per_chunk=config.pipeline.datamanager.eval_num_rays_per_chunk,
|
||||
seconds=seconds,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user