Skip to content

Commit 3402e46

Browse files
Shared data for triangulation unit tests
1 parent f53f5db commit 3402e46

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

python/gtsam/tests/test_Cal3Fisheye.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ def setUpClass(cls):
3333
u, v = np.arctan2(x, z), 0.0
3434
cls.obj_point = np.array([x, y, z])
3535
cls.img_point = np.array([u, v])
36+
37+
p1 = [-1.0, 0.0, -1.0]
38+
p2 = [ 1.0, 0.0, -1.0]
39+
q1 = gtsam.Rot3(1.0, 0.0, 0.0, 0.0)
40+
q2 = gtsam.Rot3(1.0, 0.0, 0.0, 0.0)
41+
pose1 = gtsam.Pose3(q1, p1)
42+
pose2 = gtsam.Pose3(q2, p2)
43+
camera1 = gtsam.PinholeCameraCal3Fisheye(pose1)
44+
camera2 = gtsam.PinholeCameraCal3Fisheye(pose2)
45+
cls.origin = np.array([0.0, 0.0, 0.0])
46+
cls.poses = gtsam.Pose3Vector([pose1, pose2])
47+
cls.cameras = gtsam.CameraSetCal3Fisheye([camera1, camera2])
48+
cls.measurements = gtsam.Point2Vector([k.project(cls.origin) for k in cls.cameras])
3649

3750
def test_Cal3Fisheye(self):
3851
K = gtsam.Cal3Fisheye()
@@ -96,40 +109,17 @@ def test_sfm_factor2(self):
96109
@unittest.skip("triangulatePoint3 currently seems to require perspective projections.")
97110
def test_triangulation_skipped(self):
98111
"""Estimate spatial point from image measurements"""
99-
p1 = [-1.0, 0.0, -1.0]
100-
p2 = [ 1.0, 0.0, -1.0]
101-
q1 = gtsam.Rot3(1.0, 0.0, 0.0, 0.0)
102-
q2 = gtsam.Rot3(1.0, 0.0, 0.0, 0.0)
103-
obj_point = np.array([0.0, 0.0, 0.0])
104-
pose1 = gtsam.Pose3(q1, p1)
105-
pose2 = gtsam.Pose3(q2, p2)
106-
camera1 = gtsam.PinholeCameraCal3Fisheye(pose1)
107-
camera2 = gtsam.PinholeCameraCal3Fisheye(pose2)
108-
cameras = gtsam.CameraSetCal3Fisheye([camera1, camera2])
109-
measurements = gtsam.Point2Vector([k.project(obj_point) for k in cameras])
110-
triangulated = gtsam.triangulatePoint3(cameras, measurements, rank_tol=1e-9, optimize=True)
112+
triangulated = gtsam.triangulatePoint3(self.cameras, self.measurements, rank_tol=1e-9, optimize=True)
111113
self.gtsamAssertEquals(measurements[0], self.img_point)
112-
self.gtsamAssertEquals(triangulated, obj_point)
114+
self.gtsamAssertEquals(triangulated, self.origin)
113115

114116
def test_triangulation_rectify(self):
115117
"""Estimate spatial point from image measurements using rectification"""
116-
p1 = [-1.0, 0.0, -1.0]
117-
p2 = [ 1.0, 0.0, -1.0]
118-
q1 = gtsam.Rot3(1.0, 0.0, 0.0, 0.0)
119-
q2 = gtsam.Rot3(1.0, 0.0, 0.0, 0.0)
120-
obj_point = np.array([0.0, 0.0, 0.0])
121-
pose1 = gtsam.Pose3(q1, p1)
122-
pose2 = gtsam.Pose3(q2, p2)
123-
camera1 = gtsam.PinholeCameraCal3Fisheye(pose1)
124-
camera2 = gtsam.PinholeCameraCal3Fisheye(pose2)
125-
cameras = gtsam.CameraSetCal3Fisheye([camera1, camera2])
126-
measurements = gtsam.Point2Vector([k.project(obj_point) for k in cameras])
127-
rectified = gtsam.Point2Vector([k.calibration().calibrate(pt) for k, pt in zip(cameras, measurements)])
118+
rectified = gtsam.Point2Vector([k.calibration().calibrate(pt) for k, pt in zip(self.cameras, self.measurements)])
128119
shared_cal = gtsam.Cal3_S2()
129-
poses = gtsam.Pose3Vector([pose1, pose2])
130-
triangulated = gtsam.triangulatePoint3(poses, shared_cal, rectified, rank_tol=1e-9, optimize=False)
120+
triangulated = gtsam.triangulatePoint3(self.poses, shared_cal, rectified, rank_tol=1e-9, optimize=False)
131121
self.gtsamAssertEquals(measurements[0], self.img_point)
132-
self.gtsamAssertEquals(triangulated, obj_point)
122+
self.gtsamAssertEquals(triangulated, self.origin)
133123

134124
def test_retract(self):
135125
expected = gtsam.Cal3Fisheye(100 + 2, 105 + 3, 0.0 + 4, 320 + 5, 240 + 6,

0 commit comments

Comments
 (0)