testSimpleCamera.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 
19 #include <gtsam/geometry/Pose2.h>
20 #include <gtsam/base/Testable.h>
23 #include <cmath>
24 #include <iostream>
25 
26 using namespace std;
27 using namespace gtsam;
28 
29 #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V41
30 
31 static const Cal3_S2 K(625, 625, 0, 0, 0);
32 
33 static const Pose3 pose1(Rot3(Vector3(1, -1, -1).asDiagonal()),
34  Point3(0, 0, 0.5));
35 
36 static const SimpleCamera camera(pose1, K);
37 
38 static const Point3 point1(-0.08,-0.08, 0.0);
39 static const Point3 point2(-0.08, 0.08, 0.0);
40 static const Point3 point3( 0.08, 0.08, 0.0);
41 static const Point3 point4( 0.08,-0.08, 0.0);
42 
43 /* ************************************************************************* */
44 TEST( SimpleCamera, constructor)
45 {
46  CHECK(assert_equal( camera.calibration(), K));
48 }
49 
50 /* ************************************************************************* */
51 TEST( SimpleCamera, level2)
52 {
53  // Create a level camera, looking in Y-direction
54  Pose2 pose2(0.4,0.3,M_PI/2.0);
55  SimpleCamera camera = SimpleCamera::Level(K, pose2, 0.1);
56 
57  // expected
58  Point3 x(1,0,0),y(0,0,-1),z(0,1,0);
59  Rot3 wRc(x,y,z);
60  Pose3 expected(wRc,Point3(0.4,0.3,0.1));
61  CHECK(assert_equal( camera.pose(), expected));
62 }
63 
64 /* ************************************************************************* */
65 TEST( SimpleCamera, lookat)
66 {
67  // Create a level camera, looking in Y-direction
68  Point3 C(10,0,0);
69  SimpleCamera camera = SimpleCamera::Lookat(C, Point3(0,0,0), Point3(0,0,1));
70 
71  // expected
72  Point3 xc(0,1,0),yc(0,0,-1),zc(-1,0,0);
73  Pose3 expected(Rot3(xc,yc,zc),C);
74  CHECK(assert_equal( camera.pose(), expected));
75 
76  Point3 C2(30,0,10);
77  SimpleCamera camera2 = SimpleCamera::Lookat(C2, Point3(0,0,0), Point3(0,0,1));
78 
79  Matrix R = camera2.pose().rotation().matrix();
80  Matrix I = trans(R)*R;
81  CHECK(assert_equal(I, I_3x3));
82 }
83 
84 /* ************************************************************************* */
85 TEST( SimpleCamera, project)
86 {
87  CHECK(assert_equal( camera.project(point1), Point2(-100, 100) ));
88  CHECK(assert_equal( camera.project(point2), Point2(-100, -100) ));
89  CHECK(assert_equal( camera.project(point3), Point2( 100, -100) ));
90  CHECK(assert_equal( camera.project(point4), Point2( 100, 100) ));
91 }
92 
93 /* ************************************************************************* */
94 TEST( SimpleCamera, backproject)
95 {
96  CHECK(assert_equal( camera.backproject(Point2(-100, 100), 0.5), point1));
97  CHECK(assert_equal( camera.backproject(Point2(-100, -100), 0.5), point2));
98  CHECK(assert_equal( camera.backproject(Point2( 100, -100), 0.5), point3));
99  CHECK(assert_equal( camera.backproject(Point2( 100, 100), 0.5), point4));
100 }
101 
102 /* ************************************************************************* */
103 TEST( SimpleCamera, backproject2)
104 {
105  Point3 origin(0,0,0);
106  Rot3 rot(1., 0., 0., 0., 0., 1., 0., -1., 0.); // a camera looking down
107  SimpleCamera camera(Pose3(rot, origin), K);
108 
109  Point3 actual = camera.backproject(Point2(0,0), 1.);
110  Point3 expected(0., 1., 0.);
111  pair<Point2, bool> x = camera.projectSafe(expected);
112 
113  CHECK(assert_equal(expected, actual));
114  CHECK(assert_equal(Point2(0,0), x.first));
115  CHECK(x.second);
116 }
117 
118 /* ************************************************************************* */
119 static Point2 project2(const Pose3& pose, const Point3& point) {
120  return SimpleCamera(pose,K).project(point);
121 }
122 
123 TEST( SimpleCamera, Dproject_point_pose)
124 {
125  Matrix Dpose, Dpoint;
126  Point2 result = camera.project(point1, Dpose, Dpoint, boost::none);
127  Matrix numerical_pose = numericalDerivative21(project2, pose1, point1);
128  Matrix numerical_point = numericalDerivative22(project2, pose1, point1);
129  CHECK(assert_equal(result, Point2(-100, 100) ));
130  CHECK(assert_equal(Dpose, numerical_pose, 1e-7));
131  CHECK(assert_equal(Dpoint, numerical_point,1e-7));
132 }
133 
134 /* ************************************************************************* */
135 TEST( SimpleCamera, simpleCamera)
136 {
137  Cal3_S2 K(468.2,427.2,91.2,300,200);
138  Rot3 R(
139  0.41380,0.90915,0.04708,
140  -0.57338,0.22011,0.78917,
141  0.70711,-0.35355,0.61237);
142  Point3 T(1000,2000,1500);
143  SimpleCamera expected(Pose3(R.inverse(),T),K);
144  // H&Z example, 2nd edition, page 163
145  Matrix P = (Matrix(3,4) <<
146  3.53553e2, 3.39645e2, 2.77744e2, -1.44946e6,
147  -1.03528e2, 2.33212e1, 4.59607e2, -6.32525e5,
148  7.07107e-1, -3.53553e-1,6.12372e-1, -9.18559e2).finished();
149  SimpleCamera actual = simpleCamera(P);
150  // Note precision of numbers given in book
151  CHECK(assert_equal(expected, actual,1e-1));
152 }
153 
154 #endif
155 
156 /* ************************************************************************* */
157 int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
158 /* ************************************************************************* */
159 
160 
static Point2 project2(const CalibratedCamera &camera, const Point3 &point)
int EIGEN_BLAS_FUNC() rot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
#define CHECK(condition)
Definition: Test.h:109
static Point2 project(const Pose3 &pose, const Unit3 &pointAtInfinity, const Cal3_S2::shared_ptr &cal)
Scalar * y
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Eigen::Vector3d Vector3
Definition: Vector.h:43
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set origin
Matrix expected
Definition: testMatrix.cpp:974
Vector2 Point2
Definition: Point2.h:27
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
#define M_PI
Definition: main.h:78
Rot2 R(Rot2::fromAngle(0.1))
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
Definition: Half.h:150
static char trans
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)
int main()
const Pose3 & pose() const
return pose, constant version
static Point3 backproject(const Pose3 &pose, const Point2 &point, const double &depth)
Point3 point(10, 0,-5)
PinholeCamera< Cal3_S2 > camera2(pose2,*sharedCal)
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative22(boost::function< Y(const X1 &, const X2 &)> h, const X1 &x1, const X2 &x2, double delta=1e-5)
Values result
static const Pose3 pose(Rot3(Vector3(1,-1,-1).asDiagonal()), Point3(0, 0, 0.5))
Eigen::Triplet< double > T
Matrix2 matrix() const
Definition: Rot2.cpp:89
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static const Point3 point3(0.08, 0.08, 0.0)
static const Point3 point2(-0.08, 0.08, 0.0)
static const Matrix I
Definition: lago.cpp:35
static const Pose3 pose1(Rot3(), Point3(0, 1, 0.5))
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:37
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
A simple camera class with a Cal3_S2 calibration.
static const Point3 point4(0.08,-0.08, 0.0)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
static const Pose3 pose2
const Point3 point1(3.0, 4.0, 2.0)
Vector3 Point3
Definition: Point3.h:35
2D Pose
static const CalibratedCamera camera(kDefaultPose)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
#define TEST(testGroup, testName)
Definition: Test.h:63


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:49:32