mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-11 18:44:21 +08:00
6.8 MiB
6.8 MiB
In [1]:
# HIDDEN
import torch
from nerfactory.cameras import cameras
import plotly.graph_objects as go
import mediapy as mediaIn [2]:
# COLLAPSED
from nerfactory.cameras.cameras import Cameras, CameraType
from nerfactory.utils import plotly as vis
cx = 20
cy = 10
fx = 20
fy = 20
c2w = torch.eye(4)[None, :3, :]
camera = Cameras(fx=fx, fy=fy, cx=cx, cy=cy, camera_to_worlds=c2w, camera_type=CameraType.PERSPECTIVE)
fig = vis.vis_camera_rays(camera)
fig.show()In [3]:
# COLLAPSED
from nerfactory.cameras.cameras import Cameras, CameraType
from nerfactory.utils import plotly as vis
cx = 10
cy = 10
fx = 10
fy = 10
c2w = torch.eye(4)[None, :3, :]
camera = Cameras(fx=fx, fy=fy, cx=cx, cy=cy, camera_to_worlds=c2w, camera_type=CameraType.FISHEYE)
fig = vis.vis_camera_rays(camera)
fig.show()In [204]:
# OUTPUT_ONLY
height = 15
width = 15
from plotly.subplots import make_subplots
distortion_names = ("k1", "k2", "p1", "k3", "k4", "p2")
distortion_min = (0.01, 0.001, 0.01, 0.001, -0.05, -0.05)
distortion_max = (0.05, 0.05, 0.05, 0.05, 0.05, 0.05)
fig = make_subplots(rows=2, cols=3, vertical_spacing=0.1, subplot_titles=distortion_names)
num_steps = 19
all_steps = []
for i in range(len(distortion_names)):
for step in torch.linspace(distortion_min[i], distortion_max[i], num_steps):
distortion_params = torch.zeros(6)
distortion_params[i] = step
from nerfactory.cameras import utils
coords = torch.meshgrid(torch.linspace(-1, 1, height), torch.linspace(-1, 1, width), indexing="ij")
coords = torch.stack(coords, dim=-1)
coords = utils.radial_and_tangential_undistort(coords, distortion_params)
fig.add_trace(
go.Scatter(
x=coords[..., 0].flatten(),
y=coords[..., 1].flatten(),
mode="markers",
marker=dict(
size=10,
),
visible=False,
),
row=i % 2 + 1,
col=i // 2 + 1,
)
fig.data[num_steps * i + num_steps // 2].visible = True
# Create and add slider
steps = []
for i in range(num_steps):
step = dict(method="update", args=[{"visible": [False] * len(fig.data)}], label="")
for d in range(len(distortion_names)):
step["args"][0]["visible"][num_steps * d + i] = True
steps.append(step)
sliders = [
dict(
active=num_steps // 2,
pad={"t": 10},
steps=steps,
len=0.5,
x=0.5,
xanchor="center",
)
]
webdocs_layout = go.Layout(
height=600,
sliders=sliders,
margin=dict(r=0, b=0, l=0, t=20),
hovermode=False,
showlegend=False,
paper_bgcolor="rgba(0,0,0,0)",
plot_bgcolor="rgba(0,0,0,0)",
font=dict(color="#a3a3a3", size=18),
)
fig.for_each_yaxis(lambda x: x.update(range=[-1.3, 1.3], constrain="domain", showgrid=False, visible=False))
fig.for_each_xaxis(lambda x: x.update(scaleanchor="y", scaleratio=1, showgrid=False, visible=False))
fig.update_layout(webdocs_layout)
fig.show()