test_Sim3.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 Sim3 unit tests.
9 Author: John Lambert
10 """
11 # pylint: disable=no-name-in-module
12 import unittest
13 
14 import numpy as np
15 
16 import gtsam
17 from gtsam import Point3, Pose3, Pose3Pairs, Rot3, Similarity3
18 from gtsam.utils.test_case import GtsamTestCase
19 
20 
22  """Test selected Sim3 methods."""
23 
25  """Test Align Pose3Pairs method.
26 
27  Scenario:
28  3 object poses
29  same scale (no gauge ambiguity)
30  world frame has poses rotated about x-axis (90 degree roll)
31  world and egovehicle frame translated by 15 meters w.r.t. each other
32  """
33  Rx90 = Rot3.Rx(np.deg2rad(90))
34 
35  # Create source poses (three objects o1, o2, o3 living in the egovehicle "e" frame)
36  # Suppose they are 3d cuboids detected by an onboard sensor in the egovehicle frame
37  eTo0 = Pose3(Rot3(), np.array([5, 0, 0]))
38  eTo1 = Pose3(Rot3(), np.array([10, 0, 0]))
39  eTo2 = Pose3(Rot3(), np.array([15, 0, 0]))
40 
41  eToi_list = [eTo0, eTo1, eTo2]
42 
43  # Create destination poses
44  # (same three objects, but instead living in the world/city "w" frame)
45  wTo0 = Pose3(Rx90, np.array([-10, 0, 0]))
46  wTo1 = Pose3(Rx90, np.array([-5, 0, 0]))
47  wTo2 = Pose3(Rx90, np.array([0, 0, 0]))
48 
49  wToi_list = [wTo0, wTo1, wTo2]
50 
51  we_pairs = Pose3Pairs(list(zip(wToi_list, eToi_list)))
52 
53  # Recover the transformation wSe (i.e. world_S_egovehicle)
54  wSe = Similarity3.Align(we_pairs)
55 
56  for wToi, eToi in zip(wToi_list, eToi_list):
57  self.gtsamAssertEquals(wToi, wSe.transformFrom(eToi))
58 
60  """Test if Align Pose3Pairs method can account for gauge ambiguity.
61 
62  Scenario:
63  3 object poses
64  with gauge ambiguity (2x scale)
65  world frame has poses rotated about z-axis (90 degree yaw)
66  world and egovehicle frame translated by 11 meters w.r.t. each other
67  """
68  Rz90 = Rot3.Rz(np.deg2rad(90))
69 
70  # Create source poses (three objects o1, o2, o3 living in the egovehicle "e" frame)
71  # Suppose they are 3d cuboids detected by an onboard sensor in the egovehicle frame
72  eTo0 = Pose3(Rot3(), np.array([1, 0, 0]))
73  eTo1 = Pose3(Rot3(), np.array([2, 0, 0]))
74  eTo2 = Pose3(Rot3(), np.array([4, 0, 0]))
75 
76  eToi_list = [eTo0, eTo1, eTo2]
77 
78  # Create destination poses
79  # (same three objects, but instead living in the world/city "w" frame)
80  wTo0 = Pose3(Rz90, np.array([0, 12, 0]))
81  wTo1 = Pose3(Rz90, np.array([0, 14, 0]))
82  wTo2 = Pose3(Rz90, np.array([0, 18, 0]))
83 
84  wToi_list = [wTo0, wTo1, wTo2]
85 
86  we_pairs = Pose3Pairs(list(zip(wToi_list, eToi_list)))
87 
88  # Recover the transformation wSe (i.e. world_S_egovehicle)
89  wSe = Similarity3.Align(we_pairs)
90 
91  for wToi, eToi in zip(wToi_list, eToi_list):
92  self.gtsamAssertEquals(wToi, wSe.transformFrom(eToi))
93 
95  """Test if Align Pose3Pairs method can account for gauge ambiguity.
96 
97  Make sure a big and small square can be aligned.
98  The u's represent a big square (10x10), and v's represents a small square (4x4).
99 
100  Scenario:
101  4 object poses
102  with gauge ambiguity (2.5x scale)
103  """
104  # 0, 90, 180, and 270 degrees yaw
105  R0 = Rot3.Rz(np.deg2rad(0))
106  R90 = Rot3.Rz(np.deg2rad(90))
107  R180 = Rot3.Rz(np.deg2rad(180))
108  R270 = Rot3.Rz(np.deg2rad(270))
109 
110  aTi0 = Pose3(R0, np.array([2, 3, 0]))
111  aTi1 = Pose3(R90, np.array([12, 3, 0]))
112  aTi2 = Pose3(R180, np.array([12, 13, 0]))
113  aTi3 = Pose3(R270, np.array([2, 13, 0]))
114 
115  aTi_list = [aTi0, aTi1, aTi2, aTi3]
116 
117  bTi0 = Pose3(R0, np.array([4, 3, 0]))
118  bTi1 = Pose3(R90, np.array([8, 3, 0]))
119  bTi2 = Pose3(R180, np.array([8, 7, 0]))
120  bTi3 = Pose3(R270, np.array([4, 7, 0]))
121 
122  bTi_list = [bTi0, bTi1, bTi2, bTi3]
123 
124  ab_pairs = Pose3Pairs(list(zip(aTi_list, bTi_list)))
125 
126  # Recover the transformation wSe (i.e. world_S_egovehicle)
127  aSb = Similarity3.Align(ab_pairs)
128 
129  for aTi, bTi in zip(aTi_list, bTi_list):
130  self.gtsamAssertEquals(aTi, aSb.transformFrom(bTi))
131 
132 
133 if __name__ == "__main__":
134  unittest.main()
def gtsamAssertEquals(self, actual, expected, tol=1e-9)
Definition: test_case.py:18
def test_align_poses_along_straight_line_gauge(self)
Definition: test_Sim3.py:59
std::vector< std::pair< Pose3, Pose3 > > Pose3Pairs
Definition: Pose3.h:392
def test_align_poses_along_straight_line(self)
Definition: test_Sim3.py:24
Definition: pytypes.h:1301
def test_align_poses_scaled_squares(self)
Definition: test_Sim3.py:94


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