testCal3f.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  * -------------------------------------------------------------------------- */
17 #include <gtsam/base/Testable.h>
20 #include <gtsam/geometry/Cal3f.h>
21 
22 using namespace gtsam;
23 
26 
27 static Cal3f K(500.0, 1000.0, 2000.0); // f = 500, u0 = 1000, v0 = 2000
28 static Point2 p(2.0, 3.0);
29 
30 /* ************************************************************************* */
32  Cal3f K(1.0, 0.0, 0.0);
33  Vector expected(1);
34  expected << 1.0;
36 }
37 
38 /* ************************************************************************* */
39 TEST(Cal3f, Uncalibrate) {
40  // Expected output: apply the intrinsic calibration matrix to point p
41  Matrix3 K_matrix = K.K();
42  Vector3 p_homogeneous(p.x(), p.y(), 1.0);
43  Vector3 expected_homogeneous = K_matrix * p_homogeneous;
44  Point2 expected(expected_homogeneous.x() / expected_homogeneous.z(),
45  expected_homogeneous.y() / expected_homogeneous.z());
46 
47  Point2 actual = K.uncalibrate(p);
48  CHECK(assert_equal(expected, actual));
49 }
50 
51 /* ************************************************************************* */
52 TEST(Cal3f, Calibrate) {
53  Point2 pi = K.uncalibrate(p);
54  Point2 pn = K.calibrate(pi);
55  CHECK(traits<Point2>::Equals(p, pn, 1e-9));
56 }
57 
58 /* ************************************************************************* */
59 Point2 uncalibrate_(const Cal3f& k, const Point2& pt) {
60  return k.uncalibrate(pt);
61 }
62 
63 Point2 calibrate_(const Cal3f& k, const Point2& pt) { return k.calibrate(pt); }
64 
65 /* ************************************************************************* */
66 TEST(Cal3f, DUncalibrate) {
67  Cal3f K(500.0, 1000.0, 2000.0);
68  Matrix Dcal, Dp;
69  Point2 actual = K.uncalibrate(p, Dcal, Dp);
70 
71  // Expected value computed manually
72  Point2 expected = Point2(K.px() + K.fx() * p.x(), K.py() + K.fx() * p.y());
73  CHECK(assert_equal(expected, actual, 1e-9));
74 
75  // Compute numerical derivatives
78  CHECK(assert_equal(numerical1, Dcal, 1e-6));
79  CHECK(assert_equal(numerical2, Dp, 1e-6));
80 }
81 
82 /* ************************************************************************* */
83 TEST(Cal3f, DCalibrate) {
84  Point2 pi = K.uncalibrate(p);
85  Matrix Dcal, Dp;
86  Point2 actual = K.calibrate(pi, Dcal, Dp);
87  CHECK(assert_equal(p, actual, 1e-9));
88 
89  // Compute numerical derivatives
90  Matrix numerical1 = numericalDerivative21(calibrate_, K, pi);
91  Matrix numerical2 = numericalDerivative22(calibrate_, K, pi);
92  CHECK(assert_equal(numerical1, Dcal, 1e-6));
93  CHECK(assert_equal(numerical2, Dp, 1e-6));
94 }
95 
96 /* ************************************************************************* */
97 TEST(Cal3f, Manifold) {
98  Cal3f K1(500.0, 1000.0, 2000.0);
99  Vector1 delta;
100  delta << 10.0; // Increment focal length by 10
101 
102  Cal3f K2 = K1.retract(delta);
103  CHECK(assert_equal(510.0, K2.fx(), 1e-9));
104  CHECK(assert_equal(K1.px(), K2.px(), 1e-9));
105  CHECK(assert_equal(K1.py(), K2.py(), 1e-9));
106 
107  Vector1 delta_computed = K1.localCoordinates(K2);
108  CHECK(assert_equal(delta, delta_computed, 1e-9));
109 }
110 
111 /* ************************************************************************* */
112 TEST(Cal3f, Assert_equal) {
113  CHECK(assert_equal(K, K, 1e-9));
114  Cal3f K2(500.0, 1000.0, 2000.0);
115  CHECK(assert_equal(K, K2, 1e-9));
116 }
117 
118 /* ************************************************************************* */
120  Cal3f cal(500.0, 1000.0, 2000.0);
121  std::stringstream os;
122  os << "f: " << cal.fx() << ", px: " << cal.px() << ", py: " << cal.py();
123 
124  EXPECT(assert_stdout_equal(os.str(), cal));
125 }
126 
127 /* ************************************************************************* */
128 int main() {
129  TestResult tr;
130  return TestRegistry::runAllTests(tr);
131 }
132 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GTSAM_CONCEPT_TESTABLE_INST
#define GTSAM_CONCEPT_TESTABLE_INST(T)
Definition: Testable.h:176
Testable.h
Concept check for values that can be used in unit tests.
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
gtsam::Cal3f
Calibration model with a single focal length and zero skew.
Definition: Cal3f.h:35
gtsam::Cal3::py
double py() const
image center in y
Definition: Cal3.h:154
calibrate_
Point2 calibrate_(const Cal3f &k, const Point2 &pt)
Definition: testCal3f.cpp:63
gtsam::numericalDerivative22
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative22(std::function< Y(const X1 &, const X2 &)> h, const X1 &x1, const X2 &x2, double delta=1e-5)
Definition: numericalDerivative.h:195
pt
static const Point3 pt(1.0, 2.0, 3.0)
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:43
os
ofstream os("timeSchurFactors.csv")
K2
static const Cal3Bundler K2(625, 1e-3, 1e-3)
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
fixture::cal
const Cal3_S2 cal(focalLength, focalLength, 0.0, principalPoint.x(), principalPoint.y())
TestableAssertions.h
Provides additional testing facilities for common data structures.
numericalDerivative.h
Some functions to compute numerical derivatives.
gtsam::assert_stdout_equal
bool assert_stdout_equal(const std::string &expected, const V &actual)
Definition: TestableAssertions.h:330
gtsam.examples.PlanarManipulatorExample.delta
def delta(g0, g1)
Definition: PlanarManipulatorExample.py:45
uncalibrate_
Point2 uncalibrate_(const Cal3f &k, const Point2 &pt)
Definition: testCal3f.cpp:59
K
static Cal3f K(500.0, 1000.0, 2000.0)
main
int main()
Definition: testCal3f.cpp:128
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
Cal3f.h
Calibration model with a single focal length and zero skew.
p
static Point2 p(2.0, 3.0)
gtsam::Point2
Vector2 Point2
Definition: Point2.h:32
gtsam::Cal3::K
virtual Matrix3 K() const
return calibration matrix K
Definition: Cal3.h:167
K1
static Cal3_S2::shared_ptr K1(new Cal3_S2(fov, w, h))
TestResult
Definition: TestResult.h:26
gtsam::Cal3f::vector
Vector1 vector() const
vectorized form (column-wise)
Definition: Cal3f.cpp:55
gtsam::Cal3::fx
double fx() const
focal length x
Definition: Cal3.h:139
gtsam::Cal3f::calibrate
Point2 calibrate(const Point2 &pi, OptionalJacobian< 2, 1 > Dcal={}, OptionalJacobian< 2, 2 > Dp={}) const
Definition: Cal3f.cpp:84
gtsam
traits
Definition: SFMdata.h:40
gtsam::TEST
TEST(SmartFactorBase, Pinhole)
Definition: testSmartFactorBase.cpp:38
gtsam::traits
Definition: Group.h:36
CHECK
#define CHECK(condition)
Definition: Test.h:108
gtsam::numericalDerivative21
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative21(const std::function< Y(const X1 &, const X2 &)> &h, const X1 &x1, const X2 &x2, double delta=1e-5)
Definition: numericalDerivative.h:166
gtsam::Print
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
Definition: Key.cpp:65
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
GTSAM_CONCEPT_MANIFOLD_INST
#define GTSAM_CONCEPT_MANIFOLD_INST(T)
‍**
Definition: Manifold.h:177
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
gtsam::Cal3::px
double px() const
image center in x
Definition: Cal3.h:151
gtsam::Cal3f::uncalibrate
Point2 uncalibrate(const Point2 &p, OptionalJacobian< 2, 1 > Dcal={}, OptionalJacobian< 2, 2 > Dp={}) const
: convert intrinsic coordinates xy to image coordinates uv Version of uncalibrate with derivatives
Definition: Cal3f.cpp:62


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:19