| 1 |
from pathlib import Path |
| 2 |
|
| 3 |
import pycolmap |
| 4 |
|
| 5 |
|
| 6 |
def test_global_mapper_options_init(): |
| 7 |
options = pycolmap.GlobalMapperOptions() |
| 8 |
assert options is not None |
| 9 |
|
| 10 |
|
| 11 |
def test_global_mapper_options_image_path(): |
| 12 |
options = pycolmap.GlobalMapperOptions() |
| 13 |
options.image_path = "/tmp/images" |
| 14 |
assert options.image_path == Path("/tmp/images") |
| 15 |
|
| 16 |
|
| 17 |
def test_global_mapper_options_ba_gpu_index(): |
| 18 |
options = pycolmap.GlobalMapperOptions() |
| 19 |
options.ba_gpu_index = "0" |
| 20 |
assert options.ba_gpu_index == "0" |
| 21 |
|
| 22 |
|
| 23 |
def test_global_mapper_options_get_rotation_averaging(): |
| 24 |
options = pycolmap.GlobalMapperOptions() |
| 25 |
assert options.get_rotation_averaging() is not None |
| 26 |
|
| 27 |
|
| 28 |
def test_global_mapper_options_get_global_positioning(): |
| 29 |
options = pycolmap.GlobalMapperOptions() |
| 30 |
assert options.get_global_positioning() is not None |
| 31 |
|
| 32 |
|
| 33 |
def test_global_mapper_options_get_bundle_adjustment(): |
| 34 |
options = pycolmap.GlobalMapperOptions() |
| 35 |
assert options.get_bundle_adjustment() is not None |
| 36 |
|
| 37 |
|
| 38 |
def test_global_mapper_options_get_retriangulation(): |
| 39 |
options = pycolmap.GlobalMapperOptions() |
| 40 |
assert options.get_retriangulation() is not None |
| 41 |
|
| 42 |
|
| 43 |
def test_global_pipeline_options_init(): |
| 44 |
options = pycolmap.GlobalPipelineOptions() |
| 45 |
assert options is not None |
| 46 |
|
| 47 |
|
| 48 |
def test_global_pipeline_options_nested_options(): |
| 49 |
options = pycolmap.GlobalPipelineOptions() |
| 50 |
options.mapper.min_tri_angle_deg = 2.0 |
| 51 |
assert options.mapper.min_tri_angle_deg == 2.0 |
| 52 |
|
| 53 |
|
| 54 |
def test_global_pipeline_options_from_dict(): |
| 55 |
options = pycolmap.GlobalPipelineOptions( |
| 56 |
min_num_matches=20, mapper={"ba_num_iterations": 5} |
| 57 |
) |
| 58 |
assert options.min_num_matches == 20 |
| 59 |
assert options.mapper.ba_num_iterations == 5 |
| 60 |
|
| 61 |
|
| 62 |
def test_global_pipeline_callback_model_update(): |
| 63 |
assert pycolmap.GlobalPipelineCallback.MODEL_UPDATE_CALLBACK is not None |
| 64 |
|
| 65 |
|
| 66 |
def test_global_pipeline_run(tmp_path: Path): |
| 67 |
pycolmap.set_random_seed(0) |
| 68 |
|
| 69 |
database_path = tmp_path / "database.db" |
| 70 |
with pycolmap.Database.open(database_path) as database: |
| 71 |
synthetic_dataset_options = pycolmap.SyntheticDatasetOptions() |
| 72 |
synthetic_dataset_options.num_rigs = 2 |
| 73 |
synthetic_dataset_options.num_cameras_per_rig = 1 |
| 74 |
synthetic_dataset_options.num_frames_per_rig = 7 |
| 75 |
synthetic_dataset_options.num_points3D = 50 |
| 76 |
synthetic_dataset_options.camera_has_prior_focal_length = False |
| 77 |
gt_reconstruction = pycolmap.synthesize_dataset( |
| 78 |
synthetic_dataset_options, database |
| 79 |
) |
| 80 |
|
| 81 |
# Global mapping requires calibrated two-view geometries. |
| 82 |
assert pycolmap.calibrate_view_graph(database_path) |
| 83 |
|
| 84 |
with pycolmap.Database.open(database_path) as database: |
| 85 |
num_model_updates = 0 |
| 86 |
|
| 87 |
def on_model_update(): |
| 88 |
nonlocal num_model_updates |
| 89 |
num_model_updates += 1 |
| 90 |
|
| 91 |
reconstruction_manager = pycolmap.ReconstructionManager() |
| 92 |
pipeline = pycolmap.GlobalPipeline( |
| 93 |
pycolmap.GlobalPipelineOptions(), |
| 94 |
database, |
| 95 |
reconstruction_manager, |
| 96 |
) |
| 97 |
pipeline.add_callback( |
| 98 |
pycolmap.GlobalPipelineCallback.MODEL_UPDATE_CALLBACK, |
| 99 |
on_model_update, |
| 100 |
) |
| 101 |
pipeline.run() |
| 102 |
|
| 103 |
assert num_model_updates > 0 |
| 104 |
assert reconstruction_manager.size() == 1 |
| 105 |
reconstruction = reconstruction_manager.get(0) |
| 106 |
assert reconstruction.num_reg_images() == gt_reconstruction.num_reg_images() |
| 107 |
result = pycolmap.compare_reconstructions( |
| 108 |
reconstruction, |
| 109 |
gt_reconstruction, |
| 110 |
alignment_error="proj_center", |
| 111 |
max_proj_center_error=1e-4, |
| 112 |
) |
| 113 |
assert result is not None |
| 114 |
for error in result["errors"]: |
| 115 |
assert error.rotation_error_deg < 1e-2 |
| 116 |
assert error.proj_center_error < 1e-4 |