def undistort_reconstruction( tracks_manager: Optional[pymap.TracksManager], reconstruction: types.Reconstruction, data: DataSetBase, udata: UndistortedDataSet, ) -> Dict[pymap.Shot, List[pymap.Shot]]: all_images = set(data.images()) image_format = data.config["undistorted_image_format"] urec = types.Reconstruction() urec.points = reconstruction.points urec.reference = reconstruction.reference rig_instance_count = itertools.count() utracks_manager = pymap.TracksManager() logger.debug("Undistorting the reconstruction") undistorted_shots = {} for shot in reconstruction.shots.values(): if shot.id not in all_images: logger.warning( f"Not undistorting {shot.id} as it is missing from the dataset's input images." ) continue if shot.camera.projection_type == "perspective": urec.add_camera(perspective_camera_from_perspective(shot.camera)) subshots = [get_shot_with_different_camera(urec, shot, image_format)] elif shot.camera.projection_type == "brown": urec.add_camera(perspective_camera_from_brown(shot.camera)) subshots = [get_shot_with_different_camera(urec, shot, image_format)] elif shot.camera.projection_type in ["fisheye", "fisheye_opencv"]: urec.add_camera(perspective_camera_from_fisheye(shot.camera)) subshots = [get_shot_with_different_camera(urec, shot, image_format)] elif pygeometry.Camera.is_panorama(shot.camera.projection_type): subshot_width = int(data.config["depthmap_resolution"]) subshots = perspective_views_of_a_panorama( shot, subshot_width, urec, image_format, rig_instance_count ) else: logger.warning( f"Not undistorting {shot.id} with unknown camera type." ) continue for subshot in subshots: if tracks_manager: add_subshot_tracks(tracks_manager, utracks_manager, shot, subshot) undistorted_shots[shot.id] = subshots udata.save_undistorted_reconstruction([urec]) if tracks_manager: udata.save_undistorted_tracks_manager(utracks_manager) udata.save_undistorted_shot_ids( { shot_id: [ushot.id for ushot in ushots] for shot_id, ushots in undistorted_shots.items() } ) return undistorted_shots
def undistort_reconstruction( tracks_manager, reconstruction, data: DataSetBase, udata: UndistortedDataSet ): image_format = data.config["undistorted_image_format"] urec = types.Reconstruction() urec.points = reconstruction.points urec.reference = reconstruction.reference rig_instance_count = itertools.count() utracks_manager = pymap.TracksManager() logger.debug("Undistorting the reconstruction") undistorted_shots = {} for shot in reconstruction.shots.values(): if shot.camera.projection_type == "perspective": camera = perspective_camera_from_perspective(shot.camera) urec.add_camera(camera) subshots = [ get_shot_with_different_camera(urec, shot, camera, image_format) ] elif shot.camera.projection_type == "brown": camera = perspective_camera_from_brown(shot.camera) urec.add_camera(camera) subshots = [ get_shot_with_different_camera(urec, shot, camera, image_format) ] elif shot.camera.projection_type in ["fisheye", "fisheye_opencv"]: camera = perspective_camera_from_fisheye(shot.camera) urec.add_camera(camera) subshots = [ get_shot_with_different_camera(urec, shot, camera, image_format) ] elif pygeometry.Camera.is_panorama(shot.camera.projection_type): subshot_width = int(data.config["depthmap_resolution"]) subshots = perspective_views_of_a_panorama( shot, subshot_width, urec, image_format, rig_instance_count ) for subshot in subshots: if tracks_manager: add_subshot_tracks(tracks_manager, utracks_manager, shot, subshot) # pyre-fixme[61]: `subshots` may not be initialized here. undistorted_shots[shot.id] = subshots udata.save_undistorted_reconstruction([urec]) if tracks_manager: udata.save_undistorted_tracks_manager(utracks_manager) udata.save_undistorted_shot_ids( { shot_id: [ushot.id for ushot in ushots] for shot_id, ushots in undistorted_shots.items() } ) return undistorted_shots