| 1 |
import numpy as np |
| 2 |
|
| 3 |
import pycolmap |
| 4 |
|
| 5 |
|
| 6 |
def test_triangulate_point(): |
| 7 |
cam1_from_world = np.eye(3, 4) |
| 8 |
cam2_from_world = np.eye(3, 4) |
| 9 |
cam2_from_world[0, 3] = -1.0 |
| 10 |
point1 = np.array([0.0, 0.0]) |
| 11 |
point2 = np.array([0.1, 0.0]) |
| 12 |
result = pycolmap.triangulate_point( |
| 13 |
cam1_from_world, cam2_from_world, point1, point2 |
| 14 |
) |
| 15 |
if result is not None: |
| 16 |
assert result.shape == (3,) |
| 17 |
|
| 18 |
|
| 19 |
def test_calculate_triangulation_angle(): |
| 20 |
center1 = np.array([0.0, 0.0, 0.0]) |
| 21 |
center2 = np.array([1.0, 0.0, 0.0]) |
| 22 |
point3d = np.array([0.5, 0.0, 1.0]) |
| 23 |
angle = pycolmap.calculate_triangulation_angle(center1, center2, point3d) |
| 24 |
assert isinstance(angle, float) |
| 25 |
assert angle >= 0.0 |
| 26 |
|
| 27 |
|
| 28 |
def test_triangulate_mid_point_callable(): |
| 29 |
assert callable(pycolmap.triangulate_mid_point) |
| 30 |
|
| 31 |
|
| 32 |
def test_triangulate_point_from_rays(): |
| 33 |
cam1_from_world = np.eye(3, 4) |
| 34 |
cam2_from_world = np.eye(3, 4) |
| 35 |
cam2_from_world[0, 3] = -1.0 |
| 36 |
point3d = np.array([0.0, 0.0, 5.0]) |
| 37 |
ray1 = cam1_from_world @ np.append(point3d, 1.0) |
| 38 |
ray1 /= np.linalg.norm(ray1) |
| 39 |
ray2 = cam2_from_world @ np.append(point3d, 1.0) |
| 40 |
ray2 /= np.linalg.norm(ray2) |
| 41 |
result = pycolmap.triangulate_point( |
| 42 |
cam1_from_world, cam2_from_world, ray1, ray2 |
| 43 |
) |
| 44 |
assert result is not None |
| 45 |
np.testing.assert_allclose(result, point3d, atol=1e-6) |
| 46 |
|
| 47 |
|
| 48 |
def test_triangulate_multi_view_point(): |
| 49 |
cams_from_world = [np.eye(3, 4), np.eye(3, 4), np.eye(3, 4)] |
| 50 |
cams_from_world[1][0, 3] = -1.0 |
| 51 |
cams_from_world[2][1, 3] = -1.0 |
| 52 |
point3d = np.array([0.1, -0.2, 4.0]) |
| 53 |
cam_rays = [] |
| 54 |
for cam_from_world in cams_from_world: |
| 55 |
ray = cam_from_world @ np.append(point3d, 1.0) |
| 56 |
cam_rays.append(ray / np.linalg.norm(ray)) |
| 57 |
result = pycolmap.triangulate_multi_view_point(cams_from_world, cam_rays) |
| 58 |
assert result is not None |
| 59 |
np.testing.assert_allclose(result, point3d, atol=1e-6) |