def perspective_views_of_a_panorama( spherical_shot: pymap.Shot, width: int, reconstruction: types.Reconstruction, image_format: str, rig_instance_count: Iterator[int], ) -> List[pymap.Shot]: """Create 6 perspective views of a panorama.""" camera = pygeometry.Camera.create_perspective(0.5, 0.0, 0.0) camera.id = "perspective_panorama_camera" camera.width = width camera.height = width reconstruction.add_camera(camera) names = ["front", "left", "back", "right", "top", "bottom"] rotations = [ tf.rotation_matrix(-0 * np.pi / 2, np.array([0, 1, 0])), tf.rotation_matrix(-1 * np.pi / 2, np.array([0, 1, 0])), tf.rotation_matrix(-2 * np.pi / 2, np.array([0, 1, 0])), tf.rotation_matrix(-3 * np.pi / 2, np.array([0, 1, 0])), tf.rotation_matrix(-np.pi / 2, np.array([1, 0, 0])), tf.rotation_matrix(+np.pi / 2, np.array([1, 0, 0])), ] rig_instance = reconstruction.add_rig_instance( pymap.RigInstance(str(next(rig_instance_count))) ) shots = [] for name, rotation in zip(names, rotations): if name not in reconstruction.rig_cameras: rig_camera_pose = pygeometry.Pose() rig_camera_pose.set_rotation_matrix(rotation[:3, :3]) rig_camera = pymap.RigCamera(rig_camera_pose, name) reconstruction.add_rig_camera(rig_camera) rig_camera = reconstruction.rig_cameras[name] shot_id = add_image_format_extension( f"{spherical_shot.id}_perspective_view_{name}", image_format ) shot = reconstruction.create_shot( shot_id, camera.id, pygeometry.Pose(), rig_camera.id, rig_instance.id ) shot.metadata = spherical_shot.metadata shots.append(shot) rig_instance.pose = spherical_shot.pose return shots
def add_shots_to_reconstruction( shots: List[List[str]], positions: List[np.ndarray], rotations: List[np.ndarray], rig_cameras: List[pymap.RigCamera], cameras: List[pygeometry.Camera], reconstruction: types.Reconstruction, sequence_key: str, ): for camera in cameras: reconstruction.add_camera(camera) rec_rig_cameras = [] for rig_camera in rig_cameras: rec_rig_cameras.append(reconstruction.add_rig_camera(rig_camera)) for i_shots, position, rotation in zip(shots, positions, rotations): instance_id = "_".join([s[0] for s in i_shots]) rig_instance = reconstruction.add_rig_instance(pymap.RigInstance(instance_id)) rig_instance.pose = pygeometry.Pose(rotation, -rotation.dot(position)) for shot, camera in zip(i_shots, cameras): shot_id = shot[0] rig_camera_id = shot[1] shot = reconstruction.create_shot( shot_id, camera.id, pose=None, rig_camera_id=rig_camera_id, rig_instance_id=instance_id, ) shot.metadata.sequence_key.value = sequence_key
def add_rigs_to_reconstruction( shots: List[List[str]], positions: List[np.ndarray], rotations: List[np.ndarray], rig_cameras: List[pymap.RigCamera], reconstruction: types.Reconstruction, ): rec_rig_cameras = [] for rig_camera in rig_cameras: if rig_camera.id not in reconstruction.rig_cameras: rec_rig_cameras.append(reconstruction.add_rig_camera(rig_camera)) else: rec_rig_cameras.append(reconstruction.rig_cameras[rig_camera.id]) for i, (i_shots, position, rotation) in enumerate(zip(shots, positions, rotations)): rig_instance = reconstruction.add_rig_instance(pymap.RigInstance(i)) for j, s in enumerate(i_shots): rig_instance.add_shot(rec_rig_cameras[j], reconstruction.get_shot(s[0])) rig_instance.pose = pygeometry.Pose(rotation, -rotation.dot(position))