| 1 |
import numpy as np |
| 2 |
import pytest |
| 3 |
|
| 4 |
import pycolmap |
| 5 |
|
| 6 |
|
| 7 |
def test_correspondence_default_init(): |
| 8 |
correspondence = pycolmap.Correspondence() |
| 9 |
assert correspondence is not None |
| 10 |
|
| 11 |
|
| 12 |
def test_correspondence_init_with_args(): |
| 13 |
correspondence = pycolmap.Correspondence(image_id=1, point2D_idx=5) |
| 14 |
assert correspondence.image_id == 1 |
| 15 |
assert correspondence.point2D_idx == 5 |
| 16 |
|
| 17 |
|
| 18 |
def test_correspondence_image_id_readwrite(): |
| 19 |
correspondence = pycolmap.Correspondence() |
| 20 |
correspondence.image_id = 10 |
| 21 |
assert correspondence.image_id == 10 |
| 22 |
|
| 23 |
|
| 24 |
def test_correspondence_point2d_idx_readwrite(): |
| 25 |
correspondence = pycolmap.Correspondence() |
| 26 |
correspondence.point2D_idx = 20 |
| 27 |
assert correspondence.point2D_idx == 20 |
| 28 |
|
| 29 |
|
| 30 |
def test_correspondence_graph_default_init(): |
| 31 |
graph = pycolmap.CorrespondenceGraph() |
| 32 |
assert graph.num_images() == 0 |
| 33 |
|
| 34 |
|
| 35 |
def test_correspondence_graph_add_image(): |
| 36 |
graph = pycolmap.CorrespondenceGraph() |
| 37 |
graph.add_image(1, 10) |
| 38 |
assert graph.exists_image(1) |
| 39 |
|
| 40 |
|
| 41 |
def test_correspondence_graph_exists_image(): |
| 42 |
graph = pycolmap.CorrespondenceGraph() |
| 43 |
assert not graph.exists_image(99) |
| 44 |
graph.add_image(1, 10) |
| 45 |
assert graph.exists_image(1) |
| 46 |
|
| 47 |
|
| 48 |
def test_correspondence_graph_num_images(): |
| 49 |
graph = pycolmap.CorrespondenceGraph() |
| 50 |
graph.add_image(1, 10) |
| 51 |
graph.add_image(2, 10) |
| 52 |
assert graph.num_images() == 2 |
| 53 |
|
| 54 |
|
| 55 |
def test_correspondence_graph_finalize(): |
| 56 |
graph = pycolmap.CorrespondenceGraph() |
| 57 |
graph.add_image(1, 5) |
| 58 |
graph.finalize() |
| 59 |
assert graph.num_images() == 1 |
| 60 |
|
| 61 |
|
| 62 |
def test_correspondence_graph_num_image_pairs(): |
| 63 |
graph = pycolmap.CorrespondenceGraph() |
| 64 |
graph.add_image(1, 5) |
| 65 |
graph.add_image(2, 5) |
| 66 |
graph.finalize() |
| 67 |
assert graph.num_image_pairs() >= 0 |
| 68 |
|
| 69 |
|
| 70 |
def test_correspondence_graph_num_observations_for_image(): |
| 71 |
graph = pycolmap.CorrespondenceGraph() |
| 72 |
graph.add_image(1, 5) |
| 73 |
graph.finalize() |
| 74 |
assert graph.num_observations_for_image(1) >= 0 |
| 75 |
|
| 76 |
|
| 77 |
def test_correspondence_graph_num_correspondences_for_image(): |
| 78 |
graph = pycolmap.CorrespondenceGraph() |
| 79 |
graph.add_image(1, 5) |
| 80 |
graph.finalize() |
| 81 |
assert graph.num_correspondences_for_image(1) >= 0 |
| 82 |
|
| 83 |
|
| 84 |
def test_correspondence_graph_image_pairs(): |
| 85 |
graph = pycolmap.CorrespondenceGraph() |
| 86 |
graph.add_image(1, 5) |
| 87 |
graph.add_image(2, 5) |
| 88 |
graph.finalize() |
| 89 |
pairs = graph.image_pairs() |
| 90 |
assert len(pairs) >= 0 |
| 91 |
|
| 92 |
|
| 93 |
@pytest.fixture |
| 94 |
def graph_with_matches(): |
| 95 |
graph = pycolmap.CorrespondenceGraph() |
| 96 |
graph.add_image(1, 5) |
| 97 |
graph.add_image(2, 5) |
| 98 |
two_view = pycolmap.TwoViewGeometry() |
| 99 |
two_view.config = pycolmap.TwoViewGeometryConfiguration.CALIBRATED |
| 100 |
two_view.inlier_matches = np.array([[0, 0], [1, 1]], dtype=np.uint32) |
| 101 |
graph.add_two_view_geometry(1, 2, two_view) |
| 102 |
graph.finalize() |
| 103 |
return graph |
| 104 |
|
| 105 |
|
| 106 |
def test_correspondence_graph_with_two_view_geometry(graph_with_matches): |
| 107 |
assert graph_with_matches.num_matches_between_images(1, 2) == 2 |
| 108 |
|
| 109 |
|
| 110 |
def test_correspondence_graph_extract_matches(graph_with_matches): |
| 111 |
matches = graph_with_matches.extract_matches_between_images(1, 2) |
| 112 |
assert matches.shape[0] == 2 |
| 113 |
|
| 114 |
|
| 115 |
def test_correspondence_graph_has_correspondences(graph_with_matches): |
| 116 |
assert graph_with_matches.has_correspondences(1, 0) |
| 117 |
|
| 118 |
|
| 119 |
def test_correspondence_graph_find_correspondences(graph_with_matches): |
| 120 |
result = graph_with_matches.find_correspondences(1, 0) |
| 121 |
assert result is not None |
| 122 |
|
| 123 |
|
| 124 |
def test_correspondence_graph_is_two_view_observation(): |
| 125 |
graph = pycolmap.CorrespondenceGraph() |
| 126 |
graph.add_image(1, 5) |
| 127 |
graph.add_image(2, 5) |
| 128 |
two_view = pycolmap.TwoViewGeometry() |
| 129 |
two_view.config = pycolmap.TwoViewGeometryConfiguration.CALIBRATED |
| 130 |
two_view.inlier_matches = np.array([[0, 0]], dtype=np.uint32) |
| 131 |
graph.add_two_view_geometry(1, 2, two_view) |
| 132 |
graph.finalize() |
| 133 |
assert graph.is_two_view_observation(1, 0) is True |