mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-14 20:03:49 +08:00
ns-render with depth colormap support (#2125)
* can render depth with a colormap * include colormap_options as argument
This commit is contained in:
1 parent
4d80f0ceee
commit
da813549e8
1 file changed
+39
-13
@@ -74,6 +74,8 @@ def _render_trajectory_video(
|
||||
output_format: Literal["images", "video"] = "video",
|
||||
image_format: Literal["jpeg", "png"] = "jpeg",
|
||||
jpeg_quality: int = 100,
|
||||
depth_near_plane: Optional[float] = None,
|
||||
depth_far_plane: Optional[float] = None,
|
||||
colormap_options: colormaps.ColormapOptions = colormaps.ColormapOptions(),
|
||||
) -> None:
|
||||
"""Helper function to create a video of the spiral trajectory.
|
||||
@@ -87,6 +89,8 @@ def _render_trajectory_video(
|
||||
rendered_resolution_scaling_factor: Scaling factor to apply to the camera image resolution.
|
||||
seconds: Length of output video.
|
||||
output_format: How to save output data.
|
||||
depth_near_plane: Closest depth to consider when using the colormap for depth. If None, use min value.
|
||||
depth_far_plane: Furthest depth to consider when using the colormap for depth. If None, use max value.
|
||||
colormap_options: Options for colormap.
|
||||
"""
|
||||
CONSOLE.print("[bold green]Creating trajectory " + output_format)
|
||||
@@ -149,14 +153,28 @@ def _render_trajectory_video(
|
||||
)
|
||||
sys.exit(1)
|
||||
output_image = outputs[rendered_output_name]
|
||||
output_image = (
|
||||
colormaps.apply_colormap(
|
||||
image=output_image,
|
||||
colormap_options=colormap_options,
|
||||
is_depth = rendered_output_name.find("depth") != -1
|
||||
if is_depth:
|
||||
output_image = (
|
||||
colormaps.apply_depth_colormap(
|
||||
output_image,
|
||||
accumulation=outputs["accumulation"],
|
||||
near_plane=depth_near_plane,
|
||||
far_plane=depth_far_plane,
|
||||
colormap_options=colormap_options,
|
||||
)
|
||||
.cpu()
|
||||
.numpy()
|
||||
)
|
||||
else:
|
||||
output_image = (
|
||||
colormaps.apply_colormap(
|
||||
image=output_image,
|
||||
colormap_options=colormap_options,
|
||||
)
|
||||
.cpu()
|
||||
.numpy()
|
||||
)
|
||||
.cpu()
|
||||
.numpy()
|
||||
)
|
||||
render_image.append(output_image)
|
||||
render_image = np.concatenate(render_image, axis=1)
|
||||
if output_format == "images":
|
||||
@@ -313,6 +331,12 @@ class BaseRender:
|
||||
"""Scaling factor to apply to the camera image resolution."""
|
||||
eval_num_rays_per_chunk: Optional[int] = None
|
||||
"""Specifies number of rays per chunk during eval. If None, use the value in the config file."""
|
||||
rendered_output_names: List[str] = field(default_factory=lambda: ["rgb"])
|
||||
"""Name of the renderer outputs to use. rgb, depth, etc. concatenates them along y axis"""
|
||||
depth_near_plane: Optional[float] = None
|
||||
"""Closest depth to consider when using the colormap for depth. If None, use min value."""
|
||||
depth_far_plane: Optional[float] = None
|
||||
"""Furthest depth to consider when using the colormap for depth. If None, use max value."""
|
||||
colormap_options: colormaps.ColormapOptions = colormaps.ColormapOptions()
|
||||
"""Colormap options."""
|
||||
|
||||
@@ -321,8 +345,6 @@ class BaseRender:
|
||||
class RenderCameraPath(BaseRender):
|
||||
"""Render a camera path generated by the viewer or blender add-on."""
|
||||
|
||||
rendered_output_names: List[str] = field(default_factory=lambda: ["rgb"])
|
||||
"""Name of the renderer outputs to use. rgb, depth, etc. concatenates them along y axis"""
|
||||
camera_path_filename: Path = Path("camera_path.json")
|
||||
"""Filename of the camera path to render."""
|
||||
output_format: Literal["images", "video"] = "video"
|
||||
@@ -378,6 +400,8 @@ class RenderCameraPath(BaseRender):
|
||||
output_format=self.output_format,
|
||||
image_format=self.image_format,
|
||||
jpeg_quality=self.jpeg_quality,
|
||||
depth_near_plane=self.depth_near_plane,
|
||||
depth_far_plane=self.depth_far_plane,
|
||||
colormap_options=self.colormap_options,
|
||||
)
|
||||
|
||||
@@ -409,6 +433,8 @@ class RenderCameraPath(BaseRender):
|
||||
output_format=self.output_format,
|
||||
image_format=self.image_format,
|
||||
jpeg_quality=self.jpeg_quality,
|
||||
depth_near_plane=self.depth_near_plane,
|
||||
depth_far_plane=self.depth_far_plane,
|
||||
colormap_options=self.colormap_options,
|
||||
)
|
||||
|
||||
@@ -461,8 +487,6 @@ class RenderCameraPath(BaseRender):
|
||||
class RenderInterpolated(BaseRender):
|
||||
"""Render a trajectory that interpolates between training or eval dataset images."""
|
||||
|
||||
rendered_output_names: List[str] = field(default_factory=lambda: ["rgb"])
|
||||
"""Name of the renderer outputs to use. rgb, depth, etc. concatenates them along y axis"""
|
||||
pose_source: Literal["eval", "train"] = "eval"
|
||||
"""Pose source to render."""
|
||||
interpolation_steps: int = 10
|
||||
@@ -507,6 +531,8 @@ class RenderInterpolated(BaseRender):
|
||||
seconds=seconds,
|
||||
output_format=self.output_format,
|
||||
image_format=self.image_format,
|
||||
depth_near_plane=self.depth_near_plane,
|
||||
depth_far_plane=self.depth_far_plane,
|
||||
colormap_options=self.colormap_options,
|
||||
)
|
||||
|
||||
@@ -515,8 +541,6 @@ class RenderInterpolated(BaseRender):
|
||||
class SpiralRender(BaseRender):
|
||||
"""Render a spiral trajectory (often not great)."""
|
||||
|
||||
rendered_output_names: List[str] = field(default_factory=lambda: ["rgb"])
|
||||
"""Name of the renderer outputs to use. rgb, depth, etc. concatenates them along y axis"""
|
||||
seconds: float = 3.0
|
||||
"""How long the video should be."""
|
||||
output_format: Literal["images", "video"] = "video"
|
||||
@@ -550,6 +574,8 @@ class SpiralRender(BaseRender):
|
||||
seconds=self.seconds,
|
||||
output_format=self.output_format,
|
||||
image_format=self.image_format,
|
||||
depth_near_plane=self.depth_near_plane,
|
||||
depth_far_plane=self.depth_far_plane,
|
||||
colormap_options=self.colormap_options,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user