| 1 |
from pathlib import Path |
| 2 |
|
| 3 |
import pycolmap |
| 4 |
|
| 5 |
|
| 6 |
def test_image_selection_method_max_visible_points_num(): |
| 7 |
assert pycolmap.ImageSelectionMethod.MAX_VISIBLE_POINTS_NUM is not None |
| 8 |
|
| 9 |
|
| 10 |
def test_image_selection_method_max_visible_points_ratio(): |
| 11 |
assert pycolmap.ImageSelectionMethod.MAX_VISIBLE_POINTS_RATIO is not None |
| 12 |
|
| 13 |
|
| 14 |
def test_image_selection_method_min_uncertainty(): |
| 15 |
assert pycolmap.ImageSelectionMethod.MIN_UNCERTAINTY is not None |
| 16 |
|
| 17 |
|
| 18 |
def test_incremental_mapper_options_init(): |
| 19 |
options = pycolmap.IncrementalMapperOptions() |
| 20 |
assert options is not None |
| 21 |
|
| 22 |
|
| 23 |
def test_incremental_mapper_options_check(): |
| 24 |
options = pycolmap.IncrementalMapperOptions() |
| 25 |
assert options.check() |
| 26 |
|
| 27 |
|
| 28 |
def test_local_bundle_adjustment_report_init(): |
| 29 |
report = pycolmap.LocalBundleAdjustmentReport() |
| 30 |
assert report is not None |
| 31 |
|
| 32 |
|
| 33 |
def test_local_bundle_adjustment_report_num_merged_observations(): |
| 34 |
report = pycolmap.LocalBundleAdjustmentReport() |
| 35 |
report.num_merged_observations = 5 |
| 36 |
assert report.num_merged_observations == 5 |
| 37 |
|
| 38 |
|
| 39 |
def test_local_bundle_adjustment_report_num_completed_observations(): |
| 40 |
report = pycolmap.LocalBundleAdjustmentReport() |
| 41 |
report.num_completed_observations = 10 |
| 42 |
assert report.num_completed_observations == 10 |
| 43 |
|
| 44 |
|
| 45 |
def test_local_bundle_adjustment_report_num_filtered_observations(): |
| 46 |
report = pycolmap.LocalBundleAdjustmentReport() |
| 47 |
report.num_filtered_observations = 3 |
| 48 |
assert report.num_filtered_observations == 3 |
| 49 |
|
| 50 |
|
| 51 |
def test_local_bundle_adjustment_report_num_adjusted_observations(): |
| 52 |
report = pycolmap.LocalBundleAdjustmentReport() |
| 53 |
report.num_adjusted_observations = 7 |
| 54 |
assert report.num_adjusted_observations == 7 |
| 55 |
|
| 56 |
|
| 57 |
def test_incremental_pipeline_callback_initial_image_pair(): |
| 58 |
assert ( |
| 59 |
pycolmap.IncrementalPipelineCallback.INITIAL_IMAGE_PAIR_REG_CALLBACK |
| 60 |
is not None |
| 61 |
) |
| 62 |
|
| 63 |
|
| 64 |
def test_incremental_pipeline_callback_next_image(): |
| 65 |
assert ( |
| 66 |
pycolmap.IncrementalPipelineCallback.NEXT_IMAGE_REG_CALLBACK is not None |
| 67 |
) |
| 68 |
|
| 69 |
|
| 70 |
def test_incremental_pipeline_callback_last_image(): |
| 71 |
assert ( |
| 72 |
pycolmap.IncrementalPipelineCallback.LAST_IMAGE_REG_CALLBACK is not None |
| 73 |
) |
| 74 |
|
| 75 |
|
| 76 |
def test_incremental_pipeline_status_success(): |
| 77 |
assert pycolmap.IncrementalPipelineStatus.SUCCESS is not None |
| 78 |
|
| 79 |
|
| 80 |
def test_incremental_pipeline_status_interrupted(): |
| 81 |
assert pycolmap.IncrementalPipelineStatus.INTERRUPTED is not None |
| 82 |
|
| 83 |
|
| 84 |
def test_incremental_pipeline_status_continue(): |
| 85 |
assert pycolmap.IncrementalPipelineStatus.CONTINUE is not None |
| 86 |
|
| 87 |
|
| 88 |
def test_incremental_pipeline_status_stop(): |
| 89 |
assert pycolmap.IncrementalPipelineStatus.STOP is not None |
| 90 |
|
| 91 |
|
| 92 |
def test_incremental_pipeline_status_no_initial_pair(): |
| 93 |
assert pycolmap.IncrementalPipelineStatus.NO_INITIAL_PAIR is not None |
| 94 |
|
| 95 |
|
| 96 |
def test_incremental_pipeline_status_bad_initial_pair(): |
| 97 |
assert pycolmap.IncrementalPipelineStatus.BAD_INITIAL_PAIR is not None |
| 98 |
|
| 99 |
|
| 100 |
def test_incremental_pipeline_options_init(): |
| 101 |
options = pycolmap.IncrementalPipelineOptions() |
| 102 |
assert options is not None |
| 103 |
|
| 104 |
|
| 105 |
def test_incremental_pipeline_options_min_num_matches(): |
| 106 |
options = pycolmap.IncrementalPipelineOptions() |
| 107 |
options.min_num_matches = 20 |
| 108 |
assert options.min_num_matches == 20 |
| 109 |
|
| 110 |
|
| 111 |
def test_incremental_pipeline_options_check(): |
| 112 |
options = pycolmap.IncrementalPipelineOptions() |
| 113 |
assert options.check() |
| 114 |
|
| 115 |
|
| 116 |
def test_incremental_pipeline_options_is_initial_pair_provided(): |
| 117 |
options = pycolmap.IncrementalPipelineOptions() |
| 118 |
result = options.is_initial_pair_provided() |
| 119 |
assert isinstance(result, bool) |
| 120 |
|
| 121 |
|
| 122 |
def test_incremental_pipeline_options_get_mapper(): |
| 123 |
options = pycolmap.IncrementalPipelineOptions() |
| 124 |
mapper_options = options.get_mapper() |
| 125 |
assert mapper_options is not None |
| 126 |
|
| 127 |
|
| 128 |
def test_incremental_pipeline_options_get_triangulation(): |
| 129 |
options = pycolmap.IncrementalPipelineOptions() |
| 130 |
triangulation_options = options.get_triangulation() |
| 131 |
assert triangulation_options is not None |
| 132 |
|
| 133 |
|
| 134 |
def test_incremental_pipeline_options_get_local_bundle_adjustment(): |
| 135 |
options = pycolmap.IncrementalPipelineOptions() |
| 136 |
bundle_adjustment_options = options.get_local_bundle_adjustment() |
| 137 |
assert bundle_adjustment_options is not None |
| 138 |
|
| 139 |
|
| 140 |
def test_incremental_pipeline_options_get_global_bundle_adjustment(): |
| 141 |
options = pycolmap.IncrementalPipelineOptions() |
| 142 |
bundle_adjustment_options = options.get_global_bundle_adjustment() |
| 143 |
assert bundle_adjustment_options is not None |
| 144 |
|
| 145 |
|
| 146 |
def test_incremental_pipeline_options_ba_local_backend_readwrite(): |
| 147 |
options = pycolmap.IncrementalPipelineOptions() |
| 148 |
options.ba_local_backend = pycolmap.BundleAdjustmentBackend.CERES |
| 149 |
assert options.ba_local_backend == pycolmap.BundleAdjustmentBackend.CERES |
| 150 |
options.ba_local_backend = pycolmap.BundleAdjustmentBackend.CASPAR |
| 151 |
assert options.ba_local_backend == pycolmap.BundleAdjustmentBackend.CASPAR |
| 152 |
|
| 153 |
|
| 154 |
def test_incremental_pipeline_options_ba_global_backend_readwrite(): |
| 155 |
options = pycolmap.IncrementalPipelineOptions() |
| 156 |
options.ba_global_backend = pycolmap.BundleAdjustmentBackend.CERES |
| 157 |
assert options.ba_global_backend == pycolmap.BundleAdjustmentBackend.CERES |
| 158 |
options.ba_global_backend = pycolmap.BundleAdjustmentBackend.CASPAR |
| 159 |
assert options.ba_global_backend == pycolmap.BundleAdjustmentBackend.CASPAR |
| 160 |
|
| 161 |
|
| 162 |
def test_incremental_pipeline_run(tmp_path: Path): |
| 163 |
pycolmap.set_random_seed(0) |
| 164 |
|
| 165 |
database_path = tmp_path / "database.db" |
| 166 |
with pycolmap.Database.open(database_path) as database: |
| 167 |
synthetic_dataset_options = pycolmap.SyntheticDatasetOptions() |
| 168 |
synthetic_dataset_options.num_rigs = 2 |
| 169 |
synthetic_dataset_options.num_cameras_per_rig = 1 |
| 170 |
synthetic_dataset_options.num_frames_per_rig = 7 |
| 171 |
synthetic_dataset_options.num_points3D = 50 |
| 172 |
synthetic_dataset_options.camera_has_prior_focal_length = False |
| 173 |
gt_reconstruction = pycolmap.synthesize_dataset( |
| 174 |
synthetic_dataset_options, database |
| 175 |
) |
| 176 |
|
| 177 |
reconstruction_manager = pycolmap.ReconstructionManager() |
| 178 |
pipeline = pycolmap.IncrementalPipeline( |
| 179 |
pycolmap.IncrementalPipelineOptions(), |
| 180 |
database, |
| 181 |
reconstruction_manager, |
| 182 |
) |
| 183 |
pipeline.run() |
| 184 |
|
| 185 |
assert reconstruction_manager.size() == 1 |
| 186 |
reconstruction = reconstruction_manager.get(0) |
| 187 |
assert reconstruction.num_reg_images() == gt_reconstruction.num_reg_images() |
| 188 |
result = pycolmap.compare_reconstructions( |
| 189 |
reconstruction, |
| 190 |
gt_reconstruction, |
| 191 |
alignment_error="proj_center", |
| 192 |
max_proj_center_error=1e-4, |
| 193 |
) |
| 194 |
assert result is not None |
| 195 |
for error in result["errors"]: |
| 196 |
assert error.rotation_error_deg < 1e-2 |
| 197 |
assert error.proj_center_error < 1e-4 |