mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-04 14:58:55 +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
@@ -43,10 +43,23 @@ def get_chunks(
|
||||
return chunks
|
||||
|
||||
|
||||
def three_js_perspective_camera_focal_length(fov: float, image_height: int):
|
||||
"""Returns the focal length of a three.js perspective camera.
|
||||
|
||||
Args:
|
||||
fov: the field of view of the camera in degrees.
|
||||
image_height: the height of the image in pixels.
|
||||
"""
|
||||
pp_h = image_height / 2.0
|
||||
focal_length = pp_h / np.tan(fov * (np.pi / 180.0) / 2.0)
|
||||
return focal_length
|
||||
|
||||
|
||||
def get_intrinsics_matrix_and_camera_to_world_h(
|
||||
camera_object: Dict[str, Any], image_height: int
|
||||
) -> Tuple[torch.Tensor, torch.Tensor]:
|
||||
"""Returns the camera intrinsics matrix and the camera to world homogeneous matrix.
|
||||
|
||||
Args:
|
||||
camera_object: a Camera object.
|
||||
image_size: the size of the image (height, width)
|
||||
@@ -57,7 +70,7 @@ def get_intrinsics_matrix_and_camera_to_world_h(
|
||||
image_width = aspect * image_height
|
||||
pp_w = image_width / 2.0
|
||||
pp_h = image_height / 2.0
|
||||
focal_length = pp_h / np.tan(fov * (np.pi / 180.0) / 2.0)
|
||||
focal_length = three_js_perspective_camera_focal_length(fov, image_height)
|
||||
intrinsics_matrix = torch.tensor([[focal_length, 0, pp_w], [0, focal_length, pp_h], [0, 0, 1]]).float()
|
||||
|
||||
# extrinsics
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
|
||||
import enum
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
import numpy as np
|
||||
@@ -32,6 +34,7 @@ from nerfactory.datamanagers.datasets import InputDataset
|
||||
from nerfactory.models.base import Model
|
||||
from nerfactory.utils import profiler, visualization, writer
|
||||
from nerfactory.utils.decorators import check_visualizer_enabled, decorate_all
|
||||
from nerfactory.utils.io import load_from_json, write_to_json
|
||||
from nerfactory.utils.misc import get_dict_to_torch
|
||||
from nerfactory.utils.writer import GLOBAL_BUFFER, EventName, TimeWriter
|
||||
from nerfactory.viewer.server.subprocess import run_viewer_bridge_server_as_subprocess
|
||||
@@ -185,8 +188,9 @@ class VisualizerState:
|
||||
config: viewer setup configuration
|
||||
"""
|
||||
|
||||
def __init__(self, config: cfg.ViewerConfig):
|
||||
def __init__(self, config: cfg.ViewerConfig, config_base_dir: Optional[Path] = None):
|
||||
self.config = config
|
||||
self.config_base_dir = config_base_dir
|
||||
|
||||
self.vis = None
|
||||
self.viewer_url = None
|
||||
@@ -203,7 +207,9 @@ class VisualizerState:
|
||||
# of the logging stack and easy to see and click
|
||||
# TODO(ethan): log the output of the viewer bridge server in a file where the training logs go
|
||||
console.line()
|
||||
self.viewer_url = f"https://viewer.nerfactory.com/latest/?websocket_url=localhost:{websocket_port}"
|
||||
json_filename = os.path.join(os.path.dirname(__file__), "../app/package.json")
|
||||
version = load_from_json(Path(json_filename))["version"]
|
||||
self.viewer_url = f"https://viewer.nerfactory.com/{version}/?websocket_url=localhost:{websocket_port}"
|
||||
viewer_url_local = f"http://localhost:4000/?websocket_url=localhost:{websocket_port}"
|
||||
pub_open_viewer_instructions_string = f"[Public] Open the viewer at {self.viewer_url}"
|
||||
dev_open_viewer_instructions_string = f"[Local] Open the viewer at {viewer_url_local}"
|
||||
@@ -240,6 +246,10 @@ class VisualizerState:
|
||||
start_train: whether to start train when viewer init;
|
||||
if False, only displays dataset until resume train is toggled
|
||||
"""
|
||||
# set the config base dir
|
||||
if self.config_base_dir:
|
||||
self.vis["renderingState/config_base_dir"].write(str(self.config_base_dir))
|
||||
|
||||
# clear the current scene
|
||||
self.vis["sceneState/sceneBounds"].delete()
|
||||
self.vis["sceneState/cameras"].delete()
|
||||
@@ -277,6 +287,15 @@ class VisualizerState:
|
||||
is_training = self.vis["renderingState/isTraining"].read()
|
||||
self.step = step
|
||||
|
||||
# check if we should interrupt from a button press?
|
||||
camera_path_payload = self.vis["camera_path_payload"].read()
|
||||
if camera_path_payload:
|
||||
# write to json file
|
||||
camera_path_filename = camera_path_payload["camera_path_filename"]
|
||||
camera_path = camera_path_payload["camera_path"]
|
||||
write_to_json(Path(camera_path_filename), camera_path)
|
||||
self.vis["camera_path_payload"].delete()
|
||||
|
||||
camera_object = self._get_camera_object()
|
||||
if camera_object is None:
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user