| 1 |
from pathlib import Path |
| 2 |
|
| 3 |
import pycolmap |
| 4 |
|
| 5 |
|
| 6 |
def test_scene_clustering_options_init(): |
| 7 |
options = pycolmap.SceneClusteringOptions() |
| 8 |
assert options is not None |
| 9 |
|
| 10 |
|
| 11 |
def test_scene_clustering_options_check(): |
| 12 |
options = pycolmap.SceneClusteringOptions() |
| 13 |
assert options.check() |
| 14 |
|
| 15 |
|
| 16 |
def test_scene_clustering_options_leaf_max_num_images(): |
| 17 |
options = pycolmap.SceneClusteringOptions() |
| 18 |
options.leaf_max_num_images = 100 |
| 19 |
assert options.leaf_max_num_images == 100 |
| 20 |
|
| 21 |
|
| 22 |
def test_hierarchical_pipeline_options_init(): |
| 23 |
options = pycolmap.HierarchicalPipelineOptions() |
| 24 |
assert options is not None |
| 25 |
|
| 26 |
|
| 27 |
def test_hierarchical_pipeline_options_check(): |
| 28 |
options = pycolmap.HierarchicalPipelineOptions() |
| 29 |
assert options.check() |
| 30 |
|
| 31 |
|
| 32 |
def test_hierarchical_pipeline_options_num_workers(): |
| 33 |
options = pycolmap.HierarchicalPipelineOptions() |
| 34 |
options.num_workers = 2 |
| 35 |
assert options.num_workers == 2 |
| 36 |
|
| 37 |
|
| 38 |
def test_hierarchical_pipeline_options_nested_options(): |
| 39 |
options = pycolmap.HierarchicalPipelineOptions() |
| 40 |
options.clustering_options.image_overlap = 10 |
| 41 |
assert options.clustering_options.image_overlap == 10 |
| 42 |
options.incremental_options.min_num_matches = 20 |
| 43 |
assert options.incremental_options.min_num_matches == 20 |
| 44 |
|
| 45 |
|
| 46 |
def test_hierarchical_pipeline_options_from_dict(): |
| 47 |
options = pycolmap.HierarchicalPipelineOptions( |
| 48 |
num_workers=3, clustering_options={"leaf_max_num_images": 50} |
| 49 |
) |
| 50 |
assert options.num_workers == 3 |
| 51 |
assert options.clustering_options.leaf_max_num_images == 50 |
| 52 |
|
| 53 |
|
| 54 |
def test_hierarchical_pipeline_run(tmp_path: Path): |
| 55 |
pycolmap.set_random_seed(0) |
| 56 |
|
| 57 |
database_path = tmp_path / "database.db" |
| 58 |
with pycolmap.Database.open(database_path) as database: |
| 59 |
synthetic_dataset_options = pycolmap.SyntheticDatasetOptions() |
| 60 |
synthetic_dataset_options.num_rigs = 2 |
| 61 |
synthetic_dataset_options.num_cameras_per_rig = 1 |
| 62 |
synthetic_dataset_options.num_frames_per_rig = 10 |
| 63 |
synthetic_dataset_options.num_points3D = 100 |
| 64 |
gt_reconstruction = pycolmap.synthesize_dataset( |
| 65 |
synthetic_dataset_options, database |
| 66 |
) |
| 67 |
|
| 68 |
options = pycolmap.HierarchicalPipelineOptions() |
| 69 |
options.clustering_options.leaf_max_num_images = 5 |
| 70 |
options.clustering_options.image_overlap = 3 |
| 71 |
reconstruction_manager = pycolmap.ReconstructionManager() |
| 72 |
pipeline = pycolmap.HierarchicalPipeline( |
| 73 |
options, database, reconstruction_manager |
| 74 |
) |
| 75 |
pipeline.run() |
| 76 |
|
| 77 |
assert reconstruction_manager.size() == 1 |
| 78 |
reconstruction = reconstruction_manager.get(0) |
| 79 |
assert reconstruction.num_reg_images() == gt_reconstruction.num_reg_images() |
| 80 |
assert ( |
| 81 |
reconstruction.compute_num_observations() |
| 82 |
>= gt_reconstruction.compute_num_observations() |
| 83 |
) |
| 84 |
result = pycolmap.compare_reconstructions( |
| 85 |
reconstruction, |
| 86 |
gt_reconstruction, |
| 87 |
alignment_error="proj_center", |
| 88 |
max_proj_center_error=1e-4, |
| 89 |
) |
| 90 |
assert result is not None |