test_DsfTrackGenerator.py
Go to the documentation of this file.
1 """Unit tests for track generation using a Disjoint Set Forest data structure.
2 
3 Authors: John Lambert
4 """
5 
6 import unittest
7 
8 import numpy as np
9 from gtsam.gtsfm import Keypoints
10 from gtsam.utils.test_case import GtsamTestCase
11 
12 import gtsam
13 from gtsam import IndexPair, Point2, SfmTrack2d
14 
15 
17  """Tests for DsfTrackGenerator."""
18 
19  def test_track_generation(self) -> None:
20  """Ensures that DSF generates three tracks from measurements
21  in 3 images (H=200,W=400)."""
22  kps_i0 = Keypoints(np.array([[10.0, 20], [30, 40]]))
23  kps_i1 = Keypoints(np.array([[50.0, 60], [70, 80], [90, 100]]))
24  kps_i2 = Keypoints(np.array([[110.0, 120], [130, 140]]))
25 
26  keypoints_list = []
27  keypoints_list.append(kps_i0)
28  keypoints_list.append(kps_i1)
29  keypoints_list.append(kps_i2)
30 
31  # For each image pair (i1,i2), we provide a (K,2) matrix
32  # of corresponding image indices (k1,k2).
33  matches_dict = {}
34  matches_dict[IndexPair(0, 1)] = np.array([[0, 0], [1, 1]])
35  matches_dict[IndexPair(1, 2)] = np.array([[2, 0], [1, 1]])
36 
38  matches_dict,
39  keypoints_list,
40  verbose=False,
41  )
42  assert len(tracks) == 3
43 
44  # Verify track 0.
45  track0 = tracks[0]
46  assert track0.numberMeasurements() == 2
47  np.testing.assert_allclose(track0.measurements[0][1], Point2(10, 20))
48  np.testing.assert_allclose(track0.measurements[1][1], Point2(50, 60))
49  assert track0.measurements[0][0] == 0
50  assert track0.measurements[1][0] == 1
51  np.testing.assert_allclose(
52  track0.measurementMatrix(),
53  [
54  [10, 20],
55  [50, 60],
56  ],
57  )
58  np.testing.assert_allclose(track0.indexVector(), [0, 1])
59 
60  # Verify track 1.
61  track1 = tracks[1]
62  np.testing.assert_allclose(
63  track1.measurementMatrix(),
64  [
65  [30, 40],
66  [70, 80],
67  [130, 140],
68  ],
69  )
70  np.testing.assert_allclose(track1.indexVector(), [0, 1, 2])
71 
72  # Verify track 2.
73  track2 = tracks[2]
74  np.testing.assert_allclose(
75  track2.measurementMatrix(),
76  [
77  [90, 100],
78  [110, 120],
79  ],
80  )
81  np.testing.assert_allclose(track2.indexVector(), [1, 2])
82 
83 
85  """Tests for SfmTrack2d."""
86 
87  def test_sfm_track_2d_constructor(self) -> None:
88  """Test construction of 2D SfM track."""
89  measurements = []
90  measurements.append((0, Point2(10, 20)))
91  track = SfmTrack2d(measurements=measurements)
92  track.measurement(0)
93  assert track.numberMeasurements() == 1
94 
95 
96 if __name__ == "__main__":
97  unittest.main()
Vector2 Point2
Definition: Point2.h:32
std::vector< SfmTrack2d > tracksFromPairwiseMatches(const MatchIndicesMap &matches, const KeypointsVector &keypoints, bool verbose)
Creates a list of tracks from 2d point correspondences.
Track containing 2D measurements associated with a single 3D point. Note: Equivalent to gtsam...
Definition: SfmTrack.h:42
Small utility class for representing a wrappable pairs of ints.
Definition: DSFMap.h:117
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:2244


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:37:45