Equivalent to mapper.adjust_local_bundle(...)
(
mapper: pycolmap.IncrementalMapper,
mapper_options: pycolmap.IncrementalMapperOptions,
ba_options: pycolmap.BundleAdjustmentOptions,
tri_options: pycolmap.IncrementalTriangulatorOptions,
image_id: int,
point3D_ids: set[int],
)
| 132 | |
| 133 | |
| 134 | def adjust_local_bundle( |
| 135 | mapper: pycolmap.IncrementalMapper, |
| 136 | mapper_options: pycolmap.IncrementalMapperOptions, |
| 137 | ba_options: pycolmap.BundleAdjustmentOptions, |
| 138 | tri_options: pycolmap.IncrementalTriangulatorOptions, |
| 139 | image_id: int, |
| 140 | point3D_ids: set[int], |
| 141 | ) -> pycolmap.LocalBundleAdjustmentReport: |
| 142 | """Equivalent to mapper.adjust_local_bundle(...)""" |
| 143 | reconstruction = mapper.reconstruction |
| 144 | assert reconstruction is not None |
| 145 | report = pycolmap.LocalBundleAdjustmentReport() |
| 146 | |
| 147 | # Find images that have most 3D points with given image in common |
| 148 | local_bundle = mapper.find_local_bundle(mapper_options, image_id) |
| 149 | image_ids = set() |
| 150 | |
| 151 | # Do the bundle adjustment only if there is any connected images |
| 152 | if local_bundle: |
| 153 | ba_config = pycolmap.BundleAdjustmentConfig() |
| 154 | ba_config.fix_gauge(pycolmap.BundleAdjustmentGauge.THREE_POINTS) |
| 155 | |
| 156 | # Insert the images of all local frames. |
| 157 | image = reconstruction.image(image_id) |
| 158 | frame_ids = {image.frame_id} |
| 159 | assert image.frame is not None |
| 160 | for data_id in image.frame.image_ids: |
| 161 | ba_config.add_image(data_id.id) |
| 162 | for local_image_id in local_bundle: |
| 163 | local_image = reconstruction.image(local_image_id) |
| 164 | frame_ids.add(local_image.frame_id) |
| 165 | assert local_image.frame is not None |
| 166 | for data_id in local_image.frame.image_ids: |
| 167 | ba_config.add_image(data_id.id) |
| 168 | |
| 169 | # Fix the existing images, if options specified |
| 170 | if mapper_options.fix_existing_frames: |
| 171 | for frame_id in frame_ids: |
| 172 | if frame_id in mapper.existing_frame_ids: |
| 173 | ba_config.set_constant_rig_from_world_pose(frame_id) |
| 174 | |
| 175 | # Fix rig poses, if not all frames within the local bundle. |
| 176 | num_frames_per_rig: dict[int, int] = collections.defaultdict(int) |
| 177 | for frame_id in frame_ids: |
| 178 | frame = reconstruction.frame(frame_id) |
| 179 | num_frames_per_rig[frame.rig_id] += 1 |
| 180 | for rig_id, num_frames_local in num_frames_per_rig.items(): |
| 181 | if ( |
| 182 | rig_id in mapper_options.constant_rigs |
| 183 | or num_frames_local < mapper.num_reg_frames_per_rig[rig_id] |
| 184 | ): |
| 185 | for sensor_id in reconstruction.rig(rig_id).non_ref_sensors: |
| 186 | ba_config.set_constant_sensor_from_rig_pose(sensor_id) |
| 187 | |
| 188 | # Fix camera intrinsics, if not all images within local bundle. |
| 189 | num_images_per_camera: dict[int, int] = collections.defaultdict(int) |
| 190 | for image_id in ba_config.images: |
| 191 | image = reconstruction.images[image_id] |
no test coverage detected