testCameraSet.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #include <gtsam/geometry/Pose3.h>
23 #include <boost/bind.hpp>
24 
25 using namespace std;
26 using namespace gtsam;
27 
28 /* ************************************************************************* */
29 // Cal3Bundler test
32 TEST(CameraSet, Pinhole) {
34  typedef CameraSet<Camera> Set;
35  typedef Point2Vector ZZ;
36  Set set;
37  Camera camera;
38  set.push_back(camera);
39  set.push_back(camera);
40  Point3 p(0, 0, 1);
41  EXPECT(assert_equal(set, set));
42  Set set2 = set;
43  set2.push_back(camera);
44  EXPECT(!set.equals(set2));
45 
46  // Check measurements
47  Point2 expected(0,0);
48  ZZ z = set.project2(p);
49  EXPECT(assert_equal(expected, z[0]));
50  EXPECT(assert_equal(expected, z[1]));
51 
52  // Calculate expected derivatives using Pinhole
53  Matrix actualE;
54  Matrix29 F1;
55  {
56  Matrix23 E1;
57  camera.project2(p, F1, E1);
58  actualE.resize(4,3);
59  actualE << E1, E1;
60  }
61 
62  // Check computed derivatives
63  Set::FBlocks Fs;
64  Matrix E;
65  set.project2(p, Fs, E);
66  LONGS_EQUAL(2, Fs.size());
67  EXPECT(assert_equal(F1, Fs[0]));
68  EXPECT(assert_equal(F1, Fs[1]));
69  EXPECT(assert_equal(actualE, E));
70 
71  // Check errors
72  ZZ measured;
73  measured.push_back(Point2(1, 2));
74  measured.push_back(Point2(3, 4));
75  Vector4 expectedV;
76 
77  // reprojectionError
78  expectedV << -1, -2, -3, -4;
79  Vector actualV = set.reprojectionError(p, measured);
80  EXPECT(assert_equal(expectedV, actualV));
81 
82  // Check Schur complement
83  Matrix F(4, 18);
84  F << F1, Matrix29::Zero(), Matrix29::Zero(), F1;
85  Matrix Ft = F.transpose();
86  Matrix34 Et = E.transpose();
87  Matrix3 P = Et * E;
88  Matrix schur(19, 19);
89  Vector4 b = actualV;
90  Vector v = Ft * (b - E * P * Et * b);
91  schur << Ft * F - Ft * E * P * Et * F, v, v.transpose(), 30;
92  SymmetricBlockMatrix actualReduced = Set::SchurComplement<3>(Fs, E, P, b);
93  EXPECT(assert_equal(schur, actualReduced.selfadjointView()));
94 
95  // Check Schur complement update, same order, should just double
96  KeyVector allKeys {1, 2}, keys {1, 2};
97  Set::UpdateSchurComplement<3>(Fs, E, P, b, allKeys, keys, actualReduced);
98  EXPECT(assert_equal((Matrix )(2.0 * schur), actualReduced.selfadjointView()));
99 
100  // Check Schur complement update, keys reversed
101  KeyVector keys2 {2, 1};
102  Set::UpdateSchurComplement<3>(Fs, E, P, b, allKeys, keys2, actualReduced);
103  Vector4 reverse_b;
104  reverse_b << b.tail<2>(), b.head<2>();
105  Vector reverse_v = Ft * (reverse_b - E * P * Et * reverse_b);
106  Matrix A(19, 19);
107  A << Ft * F - Ft * E * P * Et * F, reverse_v, reverse_v.transpose(), 30;
108  EXPECT(assert_equal((Matrix )(2.0 * schur + A), actualReduced.selfadjointView()));
109 
110  // reprojectionErrorAtInfinity
111  Unit3 pointAtInfinity(0, 0, 1000);
112  EXPECT(
113  assert_equal(pointAtInfinity,
114  camera.backprojectPointAtInfinity(Point2(0,0))));
115  actualV = set.reprojectionError(pointAtInfinity, measured, Fs, E);
116  EXPECT(assert_equal(expectedV, actualV));
117  LONGS_EQUAL(2, Fs.size());
118  {
119  Matrix22 E1;
120  camera.project2(pointAtInfinity, F1, E1);
121  actualE.resize(4,2);
122  actualE << E1, E1;
123  }
124  EXPECT(assert_equal(F1, Fs[0]));
125  EXPECT(assert_equal(F1, Fs[1]));
126  EXPECT(assert_equal(actualE, E));
127 }
128 
129 /* ************************************************************************* */
131 TEST(CameraSet, Stereo) {
135  set.push_back(camera);
136  set.push_back(camera);
137  Point3 p(0, 0, 1);
139 
140  // Check measurements
141  StereoPoint2 expected(0, -1, 0);
142  ZZ z = set.project2(p);
143  EXPECT(assert_equal(expected, z[0]));
144  EXPECT(assert_equal(expected, z[1]));
145 
146  // Calculate expected derivatives using Pinhole
147  Matrix63 actualE;
148  Matrix F1;
149  {
150  Matrix33 E1;
151  camera.project2(p, F1, E1);
152  actualE << E1, E1;
153  }
154 
155  // Check computed derivatives
157  Matrix E;
158  set.project2(p, Fs, E);
159  LONGS_EQUAL(2, Fs.size());
160  EXPECT(assert_equal(F1, Fs[0]));
161  EXPECT(assert_equal(F1, Fs[1]));
162  EXPECT(assert_equal(actualE, E));
163 }
164 
165 /* ************************************************************************* */
166 int main() {
167  TestResult tr;
168  return TestRegistry::runAllTests(tr);
169 }
170 /* ************************************************************************* */
171 
ComplexSchur< MatrixXcf > schur(4)
Key E(std::uint64_t j)
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
Definition: CameraSet.h:74
Scalar * b
Definition: benchVecAdd.cpp:17
static int runAllTests(TestResult &result)
Matrix expected
Definition: testMatrix.cpp:974
Base class to create smart factors on poses or cameras.
Vector2 Point2
Definition: Point2.h:27
ArrayXcf v
Definition: Cwise_arg.cpp:1
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
const vector< Matrix26, Eigen::aligned_allocator< Matrix26 > > FBlocks
Definition: Half.h:150
Some functions to compute numerical derivatives.
const Matrix26 F1
A set of cameras, all with their own calibration.
Definition: CameraSet.h:35
Unit3 pointAtInfinity(0, 0,-1000)
StereoPoint2Vector MeasurementVector
Definition: StereoCamera.h:56
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
Base class for all pinhole cameras.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
Signature::Row F
Definition: Signature.cpp:53
Eigen::VectorXd Vector
Definition: Vector.h:38
std::vector< Point2, Eigen::aligned_allocator< Point2 > > Point2Vector
Definition: Point2.h:42
#define EXPECT(condition)
Definition: Test.h:151
StereoPoint2 project2(const Point3 &point, OptionalJacobian< 3, 6 > H1=boost::none, OptionalJacobian< 3, 3 > H2=boost::none) const
#define LONGS_EQUAL(expected, actual)
Definition: Test.h:135
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
A Stereo Camera based on two Simple Cameras.
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:155
int main()
float * p
Eigen::SelfAdjointView< constBlock, Eigen::Upper > selfadjointView(DenseIndex I, DenseIndex J) const
Return the square sub-matrix that contains blocks(i:j, i:j).
TEST(CameraSet, Pinhole)
PinholePose< Cal3_S2 > Camera
Vector3 Point3
Definition: Point3.h:35
const KeyVector keys
Point3 measured
static const CalibratedCamera camera(kDefaultPose)
3D Pose
Calibration used by Bundler.


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