diff --git a/app.py b/app.py index e42e254..6efe3ec 100644 --- a/app.py +++ b/app.py @@ -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() @@ -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() diff --git a/src/visualizer.py b/src/visualizer.py index e0ec9af..1204f39 100644 --- a/src/visualizer.py +++ b/src/visualizer.py @@ -5,7 +5,7 @@ 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) @@ -13,11 +13,18 @@ def calc_cam_cone_pts_3d(c2w, fov_deg, zoom = 1.0): 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) @@ -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 @@ -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]: