test_SfmData.py
Go to the documentation of this file.
1 """
2 GTSAM Copyright 2010-2019, Georgia Tech Research Corporation,
3 Atlanta, Georgia 30332-0415
4 All Rights Reserved
5 
6 See LICENSE for the license information
7 
8 Unit tests for testing dataset access.
9 Author: Frank Dellaert (Python: Sushmita Warrier)
10 """
11 # pylint: disable=invalid-name, no-name-in-module, no-member
12 
13 from __future__ import print_function
14 
15 import unittest
16 
17 import numpy as np
18 
19 import gtsam
20 from gtsam.utils.test_case import GtsamTestCase
21 
22 
24  """Tests for SfmData and SfmTrack modules."""
25 
26  def setUp(self):
27  """Initialize SfmData and SfmTrack"""
29  # initialize SfmTrack with 3D point
31 
32  def test_tracks(self):
33  """Test functions in SfmTrack"""
34  # measurement is of format (camera_idx, imgPoint)
35  # create arbitrary camera indices for two cameras
36  i1, i2 = 4,5
37  # create arbitrary image measurements for cameras i1 and i2
38  uv_i1 = gtsam.Point2(12.6, 82)
39  # translating point uv_i1 along X-axis
40  uv_i2 = gtsam.Point2(24.88, 82)
41  # add measurements to the track
42  self.tracks.add_measurement(i1, uv_i1)
43  self.tracks.add_measurement(i2, uv_i2)
44  # Number of measurements in the track is 2
45  self.assertEqual(self.tracks.number_measurements(), 2)
46  # camera_idx in the first measurement of the track corresponds to i1
47  cam_idx, img_measurement = self.tracks.measurement(0)
48  self.assertEqual(cam_idx, i1)
49  np.testing.assert_array_almost_equal(
50  gtsam.Point3(0.,0.,0.),
51  self.tracks.point3()
52  )
53 
54 
55  def test_data(self):
56  """Test functions in SfmData"""
57  # Create new track with 3 measurements
58  i1, i2, i3 = 3,5,6
59  uv_i1 = gtsam.Point2(21.23, 45.64)
60  # translating along X-axis
61  uv_i2 = gtsam.Point2(45.7, 45.64)
62  uv_i3 = gtsam.Point2(68.35, 45.64)
63  # add measurements and arbitrary point to the track
64  measurements = [(i1, uv_i1), (i2, uv_i2), (i3, uv_i3)]
65  pt = gtsam.Point3(1.0, 6.0, 2.0)
66  track2 = gtsam.SfmTrack(pt)
67  track2.add_measurement(i1, uv_i1)
68  track2.add_measurement(i2, uv_i2)
69  track2.add_measurement(i3, uv_i3)
70  self.data.add_track(self.tracks)
71  self.data.add_track(track2)
72  # Number of tracks in SfmData is 2
73  self.assertEqual(self.data.number_tracks(), 2)
74  # camera idx of first measurement of second track corresponds to i1
75  cam_idx, img_measurement = self.data.track(1).measurement(0)
76  self.assertEqual(cam_idx, i1)
77 
78 if __name__ == '__main__':
79  unittest.main()
Define the structure for SfM data.
Definition: dataset.h:326
Vector2 Point2
Definition: Point2.h:27
double measurement(10.0)
Define the structure for the 3D points.
Definition: dataset.h:220
Vector3 Point3
Definition: Point3.h:35


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:04