testCal3DS2.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>
21 #include <gtsam/geometry/Cal3DS2.h>
22 
23 using namespace gtsam;
24 
27 
28 static Cal3DS2 K(500, 100, 0.1, 320, 240, 1e-3, 2.0 * 1e-3, 3.0 * 1e-3,
29  4.0 * 1e-3);
30 static Point2 p(2, 3);
31 
32 /* ************************************************************************* */
33 TEST(Cal3DS2, Uncalibrate) {
34  Vector k = K.k();
35  double r = p.x() * p.x() + p.y() * p.y();
36  double g = 1 + k[0] * r + k[1] * r * r;
37  double tx = 2 * k[2] * p.x() * p.y() + k[3] * (r + 2 * p.x() * p.x());
38  double ty = k[2] * (r + 2 * p.y() * p.y()) + 2 * k[3] * p.x() * p.y();
39  Vector v_hat = (Vector(3) << g * p.x() + tx, g * p.y() + ty, 1.0).finished();
40  Vector v_i = K.K() * v_hat;
41  Point2 p_i(v_i(0) / v_i(2), v_i(1) / v_i(2));
42  Point2 q = K.uncalibrate(p);
43  CHECK(assert_equal(q, p_i));
44 }
45 
46 TEST(Cal3DS2, Calibrate) {
47  Point2 pn(0.5, 0.5);
48  Point2 pi = K.uncalibrate(pn);
49  Point2 pn_hat = K.calibrate(pi);
50  CHECK(traits<Point2>::Equals(pn, pn_hat, 1e-5));
51 }
52 
53 Point2 uncalibrate_(const Cal3DS2& k, const Point2& pt) {
54  return k.uncalibrate(pt);
55 }
56 
57 /* ************************************************************************* */
58 TEST(Cal3DS2, Duncalibrate1) {
59  Matrix computed;
60  K.uncalibrate(p, computed, boost::none);
61  Matrix numerical = numericalDerivative21(uncalibrate_, K, p, 1e-7);
62  CHECK(assert_equal(numerical, computed, 1e-5));
63  Matrix separate = K.D2d_calibration(p);
64  CHECK(assert_equal(numerical, separate, 1e-5));
65 }
66 
67 /* ************************************************************************* */
68 TEST(Cal3DS2, Duncalibrate2) {
69  Matrix computed;
70  K.uncalibrate(p, boost::none, computed);
71  Matrix numerical = numericalDerivative22(uncalibrate_, K, p, 1e-7);
72  CHECK(assert_equal(numerical, computed, 1e-5));
73  Matrix separate = K.D2d_intrinsic(p);
74  CHECK(assert_equal(numerical, separate, 1e-5));
75 }
76 
77 Point2 calibrate_(const Cal3DS2& k, const Point2& pt) {
78  return k.calibrate(pt);
79 }
80 
81 /* ************************************************************************* */
82 TEST(Cal3DS2, Dcalibrate) {
83  Point2 pn(0.5, 0.5);
84  Point2 pi = K.uncalibrate(pn);
85  Matrix Dcal, Dp;
86  K.calibrate(pi, Dcal, Dp);
87  Matrix numerical1 = numericalDerivative21(calibrate_, K, pi, 1e-7);
88  CHECK(assert_equal(numerical1, Dcal, 1e-5));
89  Matrix numerical2 = numericalDerivative22(calibrate_, K, pi, 1e-7);
90  CHECK(assert_equal(numerical2, Dp, 1e-5));
91 }
92 
93 /* ************************************************************************* */
94 TEST(Cal3DS2, Equal) { CHECK(assert_equal(K, K, 1e-5)); }
95 
96 /* ************************************************************************* */
97 TEST(Cal3DS2, Retract) {
98  Cal3DS2 expected(500 + 1, 100 + 2, 0.1 + 3, 320 + 4, 240 + 5, 1e-3 + 6,
99  2.0 * 1e-3 + 7, 3.0 * 1e-3 + 8, 4.0 * 1e-3 + 9);
100 
102  EXPECT_LONGS_EQUAL(expected.dim(), 9);
103 
104  Vector9 d;
105  d << 1, 2, 3, 4, 5, 6, 7, 8, 9;
106  Cal3DS2 actual = K.retract(d);
107  CHECK(assert_equal(expected, actual, 1e-7));
108  CHECK(assert_equal(d, K.localCoordinates(actual), 1e-7));
109 }
110 
111 /* ************************************************************************* */
113  Cal3DS2 cal(1, 2, 3, 4, 5, 6, 7, 8, 9);
114  std::stringstream os;
115  os << "fx: " << cal.fx() << ", fy: " << cal.fy() << ", s: " << cal.skew()
116  << ", px: " << cal.px() << ", py: " << cal.py() << ", k1: " << cal.k1()
117  << ", k2: " << cal.k2() << ", p1: " << cal.p1() << ", p2: " << cal.p2();
118 
119  EXPECT(assert_stdout_equal(os.str(), cal));
120 }
121 
122 /* ************************************************************************* */
123 int main() {
124  TestResult tr;
125  return TestRegistry::runAllTests(tr);
126 }
127 /* ************************************************************************* */
Vector localCoordinates(const Cal3DS2 &T2) const
Given a different calibration, calculate update to obtain it.
Definition: Cal3DS2.cpp:48
bool assert_stdout_equal(const std::string &expected, const V &actual)
double p2() const
Second tangential distortion coefficient.
Definition: Cal3DS2_Base.h:106
double fy() const
focal length y
Definition: Cal3.h:142
Provides additional testing facilities for common data structures.
Matrix2 D2d_intrinsic(const Point2 &p) const
Derivative of uncalibrate wrpt intrinsic coordinates.
#define CHECK(condition)
Definition: Test.h:109
Point2 calibrate_(const Cal3DS2 &k, const Point2 &pt)
Definition: testCal3DS2.cpp:77
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
static Cal3DS2 K(500, 100, 0.1, 320, 240, 1e-3, 2.0 *1e-3, 3.0 *1e-3, 4.0 *1e-3)
Matrix expected
Definition: testMatrix.cpp:974
Vector2 Point2
Definition: Point2.h:27
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
Calibration of a camera with radial distortion, calculations in base class Cal3DS2_Base.
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)
double p1() const
First tangential distortion coefficient.
Definition: Cal3DS2_Base.h:103
Matrix29 D2d_calibration(const Point2 &p) const
Derivative of uncalibrate wrpt the calibration parameters.
void g(const string &key, int i)
Definition: testBTree.cpp:43
size_t dim() const override
Return dimensions of calibration manifold object.
Definition: Cal3DS2.h:83
Point2 calibrate(const Point2 &p, OptionalJacobian< 2, 9 > Dcal=boost::none, OptionalJacobian< 2, 2 > Dp=boost::none) const
Convert (distorted) image coordinates uv to intrinsic coordinates xy.
Point2 uncalibrate_(const Cal3DS2 &k, const Point2 &pt)
Definition: testCal3DS2.cpp:53
Eigen::VectorXd Vector
Definition: Vector.h:38
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
static Point2 p(2, 3)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EIGEN_DEVICE_FUNC const Scalar & q
Cal3DS2 retract(const Vector &d) const
Given delta vector, update calibration.
Definition: Cal3DS2.cpp:43
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
double k1() const
First distortion coefficient.
Definition: Cal3DS2_Base.h:97
static size_t Dim()
Return dimensions of calibration manifold object.
Definition: Cal3DS2.h:86
Point2 uncalibrate(const Point2 &p, OptionalJacobian< 2, 9 > Dcal=boost::none, OptionalJacobian< 2, 2 > Dp=boost::none) const
#define GTSAM_CONCEPT_MANIFOLD_INST(T)
Definition: Manifold.h:180
int main()
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:155
ofstream os("timeSchurFactors.csv")
double k2() const
Second distortion coefficient.
Definition: Cal3DS2_Base.h:100
TEST(LPInitSolver, InfiniteLoopSingleVar)
double px() const
image center in x
Definition: Cal3.h:151
double fx() const
focal length x
Definition: Cal3.h:139
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


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