testCal3_S2Stereo.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 
18 #include <gtsam/base/Testable.h>
22 
23 using namespace gtsam;
24 
27 
28 static Cal3_S2Stereo K(500, 500, 0.1, 640 / 2, 480 / 2, 1);
29 static Point2 p(1, -2);
30 static Point2 p_uv(1320.3, 1740);
31 static Point2 p_xy(2, 3);
32 
33 /* ************************************************************************* */
34 TEST(Cal3_S2Stereo, Constructor) {
35  Cal3_S2Stereo expected(554.256, 554.256, 0, 640 / 2, 480 / 2, 3);
36 
37  double fov = 60; // degrees
38  size_t w = 640, h = 480;
39  Cal3_S2Stereo actual(fov, w, h, 3);
40 
41  CHECK(assert_equal(expected, actual, 1e-3));
42 }
43 
44 /* ************************************************************************* */
45 TEST(Cal3_S2Stereo, Calibrate) {
46  Point2 intrinsic(2, 3);
47  Point2 expectedimage(1320.3, 1740);
48  Point2 imagecoordinates = K.uncalibrate(intrinsic);
49  CHECK(assert_equal(expectedimage, imagecoordinates));
50  CHECK(assert_equal(intrinsic, K.calibrate(imagecoordinates)));
51 }
52 
53 /* ************************************************************************* */
54 TEST(Cal3_S2Stereo, CalibrateHomogeneous) {
55  Vector3 intrinsic(2, 3, 1);
56  Vector3 image(1320.3, 1740, 1);
57  CHECK(assert_equal(intrinsic, K.calibrate(image)));
58 }
59 
60 /* ************************************************************************* */
62  return k.uncalibrate(pt);
63 }
64 
65 TEST(Cal3_S2Stereo, Duncalibrate) {
66  Matrix26 Dcal;
67  Matrix22 Dp;
68  K.uncalibrate(p, Dcal, Dp);
69 
71  CHECK(assert_equal(numerical1, Dcal, 1e-8));
73  CHECK(assert_equal(numerical2, Dp, 1e-9));
74 }
75 
77  return K.calibrate(pt);
78 }
79 /* ************************************************************************* */
80 TEST(Cal3_S2Stereo, Dcalibrate) {
81  Matrix26 Dcal;
82  Matrix22 Dp;
83  Point2 expected = K.calibrate(p_uv, Dcal, Dp);
84  CHECK(assert_equal(expected, p_xy, 1e-8));
85 
87  CHECK(assert_equal(numerical1, Dcal, 1e-8));
89  CHECK(assert_equal(numerical2, Dp, 1e-8));
90 }
91 
92 /* ************************************************************************* */
94  CHECK(assert_equal(K, K, 1e-9));
95 
96  Cal3_S2Stereo K1(500, 500, 0.1, 640 / 2, 480 / 2, 1);
97  CHECK(assert_equal(K, K1, 1e-9));
98 }
99 
100 /* ************************************************************************* */
101 TEST(Cal3_S2Stereo, Retract) {
102  Cal3_S2Stereo expected(500 + 1, 500 + 2, 0.1 + 3, 640 / 2 + 4, 480 / 2 + 5,
103  7);
105  EXPECT_LONGS_EQUAL(expected.dim(), 6);
106 
107  Vector6 d;
108  d << 1, 2, 3, 4, 5, 6;
109  Cal3_S2Stereo actual = K.retract(d);
110  CHECK(assert_equal(expected, actual, 1e-7));
111  CHECK(assert_equal(d, K.localCoordinates(actual), 1e-7));
112 }
113 
114 /* ************************************************************************* */
116  Cal3_S2Stereo cal(5, 5, 5, 5, 5, 2);
117  std::stringstream os;
118  os << "fx: " << cal.fx() << ", fy: " << cal.fy() << ", s: " << cal.skew()
119  << ", px: " << cal.px() << ", py: " << cal.py()
120  << ", b: " << cal.baseline();
121  EXPECT(assert_stdout_equal(os.str(), cal));
122 }
123 
124 /* ************************************************************************* */
125 int main() {
126  TestResult tr;
127  return TestRegistry::runAllTests(tr);
128 }
129 /* ************************************************************************* */
bool assert_stdout_equal(const std::string &expected, const V &actual)
double fy() const
focal length y
Definition: Cal3.h:142
Provides additional testing facilities for common data structures.
#define CHECK(condition)
Definition: Test.h:109
size_t dim() const override
return DOF, dimensionality of tangent space
static size_t Dim()
return DOF, dimensionality of tangent space
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Eigen::Vector3d Vector3
Definition: Vector.h:43
Matrix expected
Definition: testMatrix.cpp:974
Point2 uncalibrate_(const Cal3_S2Stereo &k, const Point2 &pt)
Vector2 Point2
Definition: Point2.h:27
static Point2 p_xy(2, 3)
double baseline() const
return baseline
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
Some functions to compute numerical derivatives.
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative21(const boost::function< Y(const X1 &, const X2 &)> &h, const X1 &x1, const X2 &x2, double delta=1e-5)
static const Point3 pt(1.0, 2.0, 3.0)
static Point2 p_uv(1320.3, 1740)
Point2 calibrate_(const Cal3_S2Stereo &K, const Point2 &pt)
static Point2 p(1,-2)
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative22(boost::function< Y(const X1 &, const X2 &)> h, const X1 &x1, const X2 &x2, double delta=1e-5)
double py() const
image center in y
Definition: Cal3.h:154
#define EXPECT(condition)
Definition: Test.h:151
double skew() const
skew
Definition: Cal3.h:148
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static Cal3_S2::shared_ptr K1(new Cal3_S2(fov, w, h))
RowVector3d w
int main()
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
Point2 calibrate(const Point2 &p, OptionalJacobian< 2, 6 > Dcal=boost::none, OptionalJacobian< 2, 2 > Dp=boost::none) const
const double h
The most common 5DOF 3D->2D calibration + Stereo baseline.
#define GTSAM_CONCEPT_MANIFOLD_INST(T)
Definition: Manifold.h:180
static Cal3_S2Stereo K(500, 500, 0.1, 640/2, 480/2, 1)
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:155
ofstream os("timeSchurFactors.csv")
Cal3_S2Stereo retract(const Vector &d) const
Given 6-dim tangent vector, create new calibration.
TEST(LPInitSolver, InfiniteLoopSingleVar)
static double fov
double px() const
image center in x
Definition: Cal3.h:151
double fx() const
focal length x
Definition: Cal3.h:139
Point2 uncalibrate(const Point2 &p, OptionalJacobian< 2, 6 > Dcal=boost::none, OptionalJacobian< 2, 2 > Dp=boost::none) const
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
Definition: Key.cpp:59
#define GTSAM_CONCEPT_TESTABLE_INST(T)
Definition: Testable.h:174
Vector6 localCoordinates(const Cal3_S2Stereo &T2) const
Unretraction for the calibration.


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