mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-05 15:28:49 +08:00
Viewer refactor with state sync (#212)
* initial commit for viewer refactor * updating name change to nerfactory * adding headers * making the rendering fix which broke from a merge * things are starting to work. removing old commands now * removed prints * cleanup * updating state works now even for nested dictionaries * updating state in redux. listening for state changes. trying to draw three.js now * added drawing functionality. need to fix translation of frustums and image planes * images and frustums drawn correctly * fixing lint * github actions * back to npm * fixing eslint * remove package.json from root * new favicon * some viewer cleanup * notebook * fixed camera drawings speed to avoid redraw * trying to get Leva to update * quick fix * synced config panel * adding notebook * fixing output print error
This commit is contained in:
1 parent
966374474d
commit
73fedc7593
67 files changed
+2510
-14057
No files matched your search
@@ -17,14 +17,16 @@ Camera Models
|
||||
"""
|
||||
import base64
|
||||
from abc import abstractmethod
|
||||
from typing import Dict, Optional, Type
|
||||
from typing import Dict, Optional, Tuple, Type
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
import torch
|
||||
from torch.nn.functional import normalize
|
||||
from torchtyping import TensorType
|
||||
|
||||
from nerfactory.cameras.rays import RayBundle
|
||||
from nerfactory.utils.misc import is_not_none
|
||||
|
||||
|
||||
class Camera:
|
||||
@@ -161,11 +163,15 @@ class Camera:
|
||||
return ray_bundle
|
||||
|
||||
@abstractmethod
|
||||
def to_json(self, image: Optional[TensorType["image_height", "image_width", 2]] = None) -> Dict:
|
||||
def to_json(
|
||||
self,
|
||||
image: Optional[TensorType["image_height", "image_width", 2]] = None,
|
||||
resize_shape: Optional[Tuple[int, int]] = None,
|
||||
) -> Dict:
|
||||
"""Converts the camera to a json dictionary.
|
||||
|
||||
Args:
|
||||
image: An image that is encoded to a base64 string. Defaults to None.
|
||||
image: An image in range [0, 1] that is encoded to a base64 string. Defaults to None.
|
||||
|
||||
Returns:
|
||||
A JSON representation of the camera
|
||||
@@ -295,7 +301,11 @@ class PinholeCamera(Camera):
|
||||
|
||||
return RayBundle(origins=origins, directions=directions, pixel_area=pixel_area[..., None])
|
||||
|
||||
def to_json(self, image: Optional[TensorType["image_height", "image_width", 2]] = None) -> Dict:
|
||||
def to_json(
|
||||
self,
|
||||
image: Optional[TensorType["image_height", "image_width", 2]] = None,
|
||||
resize_shape: Optional[Tuple[int, int]] = None,
|
||||
) -> Dict:
|
||||
json_ = {
|
||||
"type": "PinholeCamera",
|
||||
"cx": self.cx,
|
||||
@@ -305,10 +315,11 @@ class PinholeCamera(Camera):
|
||||
"camera_to_world": self.camera_to_world.tolist(),
|
||||
"camera_index": self.camera_index,
|
||||
}
|
||||
if image:
|
||||
# move image to cpu if not already
|
||||
# TODO: move to numpy
|
||||
data = cv2.imencode(".png", image[:, :, ::-1])[1].tobytes()
|
||||
if is_not_none(image):
|
||||
image_uint8 = (image * 255).detach().cpu().numpy().astype(np.uint8)
|
||||
if resize_shape:
|
||||
image_uint8 = cv2.resize(image_uint8, resize_shape)
|
||||
data = cv2.imencode(".png", image_uint8)[1].tobytes()
|
||||
json_["image"] = str("data:image/png;base64," + base64.b64encode(data).decode("ascii"))
|
||||
return json_
|
||||
|
||||
@@ -346,9 +357,6 @@ class SimplePinholeCamera(PinholeCamera):
|
||||
def fy_index(cls):
|
||||
return 2
|
||||
|
||||
def to_json(self, image: Optional[TensorType["image_height", "image_width", 2]] = None) -> Dict:
|
||||
raise NotImplementedError
|
||||
|
||||
@staticmethod
|
||||
def from_json(json_: Dict) -> "SimplePinholeCamera": # pylint:disable=no-self-use
|
||||
raise NotImplementedError
|
||||
@@ -441,7 +449,11 @@ class EquirectangularCamera(Camera):
|
||||
pixel_area = dx * dy
|
||||
return RayBundle(origins=origins, directions=directions, pixel_area=pixel_area[..., None])
|
||||
|
||||
def to_json(self, image: Optional[TensorType["image_height", "image_width", 2]] = None) -> Dict:
|
||||
def to_json(
|
||||
self,
|
||||
image: Optional[TensorType["image_height", "image_width", 2]] = None,
|
||||
resize_shape: Optional[Tuple[int, int]] = None,
|
||||
) -> Dict:
|
||||
raise NotImplementedError
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in new issue
Block a user