Debian Codegraph @

python/pycolmap/panorama_test.py

raw
1 import numpy as np
2
3 import pycolmap
4
5 from .panorama import (
6 filter_database_by_covisibility,
7 get_virtual_rotations,
8 )
9
10
11 def test_get_virtual_rotations():
12 rotations = get_virtual_rotations(4, [-35.0, 0.0, 35.0])
13
14 assert len(rotations) == 12
15 np.testing.assert_allclose(
16 rotations[4],
17 np.eye(3),
18 atol=1e-15,
19 )
20 np.testing.assert_allclose(
21 rotations[1],
22 [
23 [0.0, 0.0, -1.0],
24 [-0.573576436351046, 0.8191520442889917, 0.0],
25 [0.8191520442889917, 0.573576436351046, 0.0],
26 ],
27 atol=1e-15,
28 )
29 for rotation in rotations:
30 np.testing.assert_allclose(rotation @ rotation.T, np.eye(3), atol=1e-15)
31 np.testing.assert_allclose(np.linalg.det(rotation), 1.0, atol=1e-15)
32
33
34 def test_filter_database_by_covisibility(tmp_path):
35 database_path = tmp_path / "database.db"
36 with pycolmap.Database.open(database_path) as database:
37 camera = pycolmap.Camera.create_from_model_name(
38 1, "SIMPLE_PINHOLE", 100.0, 100, 100
39 )
40 database.write_camera(camera)
41 for image_id, name in enumerate(["a.png", "b.png", "c.png"], start=1):
42 database.write_image(
43 pycolmap.Image(
44 image_id=image_id, camera_id=camera.camera_id, name=name
45 ),
46 use_image_id=True,
47 )
48 geometry = pycolmap.TwoViewGeometry()
49 geometry.inlier_matches = np.array([[0, 0]], dtype=np.uint32)
50 database.write_two_view_geometry(1, 2, geometry)
51 database.write_two_view_geometry(1, 3, geometry)
52
53 covisibility_path = tmp_path / "covisibility.npz"
54 np.savez(
55 covisibility_path,
56 image_names=np.array(["a.png", "b.png", "c.png"]),
57 directed_overlap_counts=np.array(
58 [[1, 10, 0], [10, 1, 0], [0, 0, 1]], dtype=np.uint32
59 ),
60 )
61 filter_database_by_covisibility(
62 database_path, covisibility_path, min_shared_points=1
63 )
64
65 with pycolmap.Database.open(database_path) as database:
66 assert database.exists_two_view_geometry(1, 2)
67 assert not database.exists_two_view_geometry(1, 3)