Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
parser.add_argument('--y_up', action='store_true')
parser.add_argument('--recenter', action='store_true')
parser.add_argument('--rescale', type=float, default=None)
parser.add_argument('--camera_axis', type=str, default='-z')

args = parser.parse_args()

Expand Down Expand Up @@ -61,7 +62,7 @@

images.append(load_image(fpath, sz=args.image_size))

viz = CameraVisualizer(poses, legends, colors, images=images)
viz = CameraVisualizer(poses, legends, colors, images=images, camera_axis=args.camera_axis)
fig = viz.update_figure(args.scene_size, base_radius=1, zoom_scale=1, show_grid=True, show_ticklabels=True, show_background=True, y_up=args.y_up)

fig.show()
26 changes: 18 additions & 8 deletions src/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@
import numpy as np


def calc_cam_cone_pts_3d(c2w, fov_deg, zoom = 1.0):
def calc_cam_cone_pts_3d(c2w, fov_deg, zoom = 1.0, camera_axis = '-z'):

fov_rad = np.deg2rad(fov_deg)

cam_x = c2w[0, -1]
cam_y = c2w[1, -1]
cam_z = c2w[2, -1]

corn1 = [np.tan(fov_rad / 2.0), np.tan(fov_rad / 2.0), -1.0]
corn2 = [-np.tan(fov_rad / 2.0), np.tan(fov_rad / 2.0), -1.0]
corn3 = [-np.tan(fov_rad / 2.0), -np.tan(fov_rad / 2.0), -1.0]
corn4 = [np.tan(fov_rad / 2.0), -np.tan(fov_rad / 2.0), -1.0]
corn5 = [0, np.tan(fov_rad / 2.0), -1.0]
if camera_axis == '+z':
z_multiplier = -1
elif camera_axis == '-z':
z_multiplier = 1
else:
raise ValueError("Camera axis must be either '+z' or '-z'. It's '-z' by default.")

corn1 = [np.tan(fov_rad / 2.0), np.tan(fov_rad / 2.0), z_multiplier*-1.0]
corn2 = [-np.tan(fov_rad / 2.0), np.tan(fov_rad / 2.0), z_multiplier*-1.0]
corn3 = [-np.tan(fov_rad / 2.0), -np.tan(fov_rad / 2.0), z_multiplier*-1.0]
corn4 = [np.tan(fov_rad / 2.0), -np.tan(fov_rad / 2.0), z_multiplier*-1.0]
corn5 = [0, np.tan(fov_rad / 2.0), z_multiplier*-1.0]

corn1 = np.dot(c2w[:3, :3], corn1)
corn2 = np.dot(c2w[:3, :3], corn2)
Expand Down Expand Up @@ -56,10 +63,13 @@ def calc_cam_cone_pts_3d(c2w, fov_deg, zoom = 1.0):

class CameraVisualizer:

def __init__(self, poses, legends, colors, images=None, mesh_path=None, camera_x=1.0):
def __init__(self, poses, legends, colors, images=None, mesh_path=None, camera_x=1.0, camera_axis='-z'):
self._fig = None

self._camera_x = camera_x

# Boresight axis of the camera.
self._camera_axis = camera_axis

self._poses = poses
self._legends = legends
Expand Down Expand Up @@ -140,7 +150,7 @@ def update_figure(

edges = [(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (2, 3), (3, 4), (4, 1), (0, 5)]

cone = calc_cam_cone_pts_3d(pose, fov_deg)
cone = calc_cam_cone_pts_3d(pose, fov_deg, camera_axis=self._camera_axis)
radius = np.linalg.norm(pose[:3, -1])

if self._bit_images and self._bit_images[i]:
Expand Down