def add_shots_to_reconstruction( shot_ids: List[str], positions: List[np.ndarray], rotations: List[np.ndarray], camera: pygeometry.Camera, reconstruction: types.Reconstruction, ): reconstruction.add_camera(camera) for shot_id, position, rotation in zip(shot_ids, positions, rotations): pose = pygeometry.Pose(rotation) pose.set_origin(position) reconstruction.create_shot(shot_id, camera.id, pose)
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 get_shot_with_different_camera( urec: types.Reconstruction, shot: pymap.Shot, image_format: str, ) -> pymap.Shot: new_shot_id = add_image_format_extension(shot.id, image_format) new_shot = urec.create_shot(new_shot_id, shot.camera.id, shot.pose) new_shot.metadata = shot.metadata return new_shot
def add_shot( data: DataSetBase, reconstruction: types.Reconstruction, rig_assignments: Dict[str, Tuple[int, str, List[str]]], shot_id: str, pose: pygeometry.Pose, ) -> Set[str]: """Add a shot to the recontruction. In case of a shot belonging to a rig instance, the pose of shot will drive the initial pose setup of the rig instance. All necessary shots and rig models will be created. """ added_shots = set() if shot_id not in rig_assignments: camera_id = data.load_exif(shot_id)["camera"] shot = reconstruction.create_shot(shot_id, camera_id, pose) shot.metadata = get_image_metadata(data, shot_id) added_shots = {shot_id} else: instance_id, _, instance_shots = rig_assignments[shot_id] created_shots = {} for shot in instance_shots: camera_id = data.load_exif(shot)["camera"] created_shots[shot] = reconstruction.create_shot( shot, camera_id, pygeometry.Pose() ) created_shots[shot].metadata = get_image_metadata(data, shot) rig_instance = reconstruction.add_rig_instance(pymap.RigInstance(instance_id)) for shot in instance_shots: _, rig_camera_id, _ = rig_assignments[shot] rig_instance.add_shot( reconstruction.rig_cameras[rig_camera_id], created_shots[shot] ) rig_instance.update_instance_pose_with_shot(shot_id, pose) added_shots = set(instance_shots) return added_shots
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 shot_in_reconstruction_from_json( reconstruction: types.Reconstruction, key: str, obj: Dict[str, Any], rig_instance_id: Optional[str] = None, rig_camera_id: Optional[str] = None, is_pano_shot: bool = False, ) -> pymap.Shot: """ Read shot from a json object and append it to a reconstruction """ pose = pose_from_json(obj) if is_pano_shot: shot = reconstruction.create_pano_shot(key, obj["camera"], pose) else: shot = reconstruction.create_shot( key, obj["camera"], pose, rig_camera_id, rig_instance_id ) assign_shot_attributes(obj, shot) return shot