testInvDepthCamera3.cpp
Go to the documentation of this file.
1 /*
2  * testInvDepthFactor.cpp
3  *
4  * Created on: Apr 13, 2012
5  * Author: cbeall3
6  */
7 
9 
11 #include <gtsam/base/Testable.h>
13 #include <gtsam/geometry/Cal3_S2.h>
14 
16 
17 using namespace std;
18 using namespace gtsam;
19 
20 static Cal3_S2::shared_ptr K(new Cal3_S2(1500, 1200, 0, 640, 480));
21 Pose3 level_pose = Pose3(Rot3::Ypr(-M_PI/2, 0., -M_PI/2), gtsam::Point3(0,0,1));
23 
24 /* ************************************************************************* */
25 TEST( InvDepthFactor, Project1) {
26 
27  // landmark 5 meters infront of camera
28  Point3 landmark(5, 0, 1);
29 
30  Point2 expected_uv = level_camera.project(landmark);
31 
32  InvDepthCamera3<Cal3_S2> inv_camera(level_pose, K);
33  Vector5 inv_landmark((Vector(5) << 1., 0., 1., 0., 0.).finished());
34  double inv_depth(1./4);
35  Point2 actual_uv = inv_camera.project(inv_landmark, inv_depth);
36  EXPECT(assert_equal(expected_uv, actual_uv,1e-8));
37  EXPECT(assert_equal(Point2(640,480), actual_uv));
38 }
39 
40 /* ************************************************************************* */
41 TEST( InvDepthFactor, Project2) {
42 
43  // landmark 1m to the left and 1m up from camera
44  // inv landmark xyz is same as camera xyz, so depth actually doesn't matter
45  Point3 landmark(1, 1, 2);
46  Point2 expected = level_camera.project(landmark);
47 
48  InvDepthCamera3<Cal3_S2> inv_camera(level_pose, K);
49  Vector5 diag_landmark((Vector(5) << 0., 0., 1., M_PI/4., atan(1.0/sqrt(2.0))).finished());
50  double inv_depth(1/sqrt(3.0));
51  Point2 actual = inv_camera.project(diag_landmark, inv_depth);
52  EXPECT(assert_equal(expected, actual));
53 }
54 
55 /* ************************************************************************* */
56 TEST( InvDepthFactor, Project3) {
57 
58  // landmark 1m to the left and 1m up from camera
59  // inv depth landmark xyz at origion
60  Point3 landmark(1, 1, 2);
61  Point2 expected = level_camera.project(landmark);
62 
63  InvDepthCamera3<Cal3_S2> inv_camera(level_pose, K);
64  Vector5 diag_landmark((Vector(5) << 0., 0., 0., M_PI/4., atan(2./sqrt(2.0))).finished());
65  double inv_depth( 1./sqrt(1.0+1+4));
66  Point2 actual = inv_camera.project(diag_landmark, inv_depth);
67  EXPECT(assert_equal(expected, actual));
68 }
69 
70 /* ************************************************************************* */
71 TEST( InvDepthFactor, Project4) {
72 
73  // landmark 4m to the left and 1m up from camera
74  // inv depth landmark xyz at origion
75  Point3 landmark(1, 4, 2);
76  Point2 expected = level_camera.project(landmark);
77 
78  InvDepthCamera3<Cal3_S2> inv_camera(level_pose, K);
79  Vector5 diag_landmark((Vector(5) << 0., 0., 0., atan(4.0/1), atan(2./sqrt(1.+16.))).finished());
80  double inv_depth(1./sqrt(1.+16.+4.));
81  Point2 actual = inv_camera.project(diag_landmark, inv_depth);
82  EXPECT(assert_equal(expected, actual));
83 }
84 
85 
86 /* ************************************************************************* */
87 Point2 project_(const Pose3& pose, const Vector5& landmark, const double& inv_depth) {
88  return InvDepthCamera3<Cal3_S2>(pose,K).project(landmark, inv_depth); }
89 
90 TEST( InvDepthFactor, Dproject_pose)
91 {
92  Vector5 landmark((Vector(5) << 0.1,0.2,0.3, 0.1,0.2).finished());
93  double inv_depth(1./4);
94  Matrix expected = numericalDerivative31(project_,level_pose, landmark, inv_depth);
95  InvDepthCamera3<Cal3_S2> inv_camera(level_pose,K);
96  Matrix actual;
97  inv_camera.project(landmark, inv_depth, actual, boost::none, boost::none);
98  EXPECT(assert_equal(expected,actual,1e-6));
99 }
100 
101 /* ************************************************************************* */
102 TEST( InvDepthFactor, Dproject_landmark)
103 {
104  Vector5 landmark((Vector(5) << 0.1,0.2,0.3, 0.1,0.2).finished());
105  double inv_depth(1./4);
106  Matrix expected = numericalDerivative32(project_,level_pose, landmark, inv_depth);
107  InvDepthCamera3<Cal3_S2> inv_camera(level_pose,K);
108  Matrix actual;
109  inv_camera.project(landmark, inv_depth, boost::none, actual, boost::none);
110  EXPECT(assert_equal(expected,actual,1e-7));
111 }
112 
113 /* ************************************************************************* */
114 TEST( InvDepthFactor, Dproject_inv_depth)
115 {
116  Vector5 landmark((Vector(5) << 0.1,0.2,0.3, 0.1,0.2).finished());
117  double inv_depth(1./4);
118  Matrix expected = numericalDerivative33(project_,level_pose, landmark, inv_depth);
119  InvDepthCamera3<Cal3_S2> inv_camera(level_pose,K);
120  Matrix actual;
121  inv_camera.project(landmark, inv_depth, boost::none, boost::none, actual);
122  EXPECT(assert_equal(expected,actual,1e-7));
123 }
124 
125 /* ************************************************************************* */
126 TEST(InvDepthFactor, backproject)
127 {
128  Vector expected((Vector(5) << 0.,0.,1., 0.1,0.2).finished());
129  double inv_depth(1./4);
130  InvDepthCamera3<Cal3_S2> inv_camera(level_pose,K);
131  Point2 z = inv_camera.project(expected, inv_depth);
132 
133  Vector5 actual_vec;
134  double actual_inv;
135  boost::tie(actual_vec, actual_inv) = inv_camera.backproject(z, 4);
136  EXPECT(assert_equal(expected,actual_vec,1e-7));
137  EXPECT_DOUBLES_EQUAL(inv_depth,actual_inv,1e-7);
138 }
139 
140 /* ************************************************************************* */
141 TEST(InvDepthFactor, backproject2)
142 {
143  // backwards facing camera
144  Vector expected((Vector(5) << -5.,-5.,2., 3., -0.1).finished());
145  double inv_depth(1./10);
146  InvDepthCamera3<Cal3_S2> inv_camera(Pose3(Rot3::Ypr(1.5,0.1, -1.5), Point3(-5, -5, 2)),K);
147  Point2 z = inv_camera.project(expected, inv_depth);
148 
149  Vector5 actual_vec;
150  double actual_inv;
151  boost::tie(actual_vec, actual_inv) = inv_camera.backproject(z, 10);
152  EXPECT(assert_equal(expected,actual_vec,1e-7));
153  EXPECT_DOUBLES_EQUAL(inv_depth,actual_inv,1e-7);
154 }
155 
156 /* ************************************************************************* */
157 int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
158 /* ************************************************************************* */
TEST(InvDepthFactor, Project1)
static Cal3_S2::shared_ptr K(new Cal3_S2(1500, 1200, 0, 640, 480))
static Point2 project(const Pose3 &pose, const Unit3 &pointAtInfinity, const Cal3_S2::shared_ptr &cal)
PinholeCamera< Cal3_S2 > level_camera(level_pose,*K)
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Matrix expected
Definition: testMatrix.cpp:974
Vector2 Point2
Definition: Point2.h:27
std::pair< Vector5, double > backproject(const gtsam::Point2 &pi, const double depth) const
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
#define M_PI
Definition: main.h:78
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition: Half.h:150
internal::FixedSizeMatrix< Y, X3 >::type numericalDerivative33(boost::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
Some functions to compute numerical derivatives.
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative31(boost::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:162
static Point3 backproject(const Pose3 &pose, const Point2 &point, const double &depth)
static Point3 landmark(0, 0, 5)
Base class for all pinhole cameras.
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative32(boost::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
static Point2 Project2(const Unit3 &point)
Eigen::VectorXd Vector
Definition: Vector.h:38
gtsam::Point2 project(const Vector5 &pw, double rho, boost::optional< gtsam::Matrix & > H1=boost::none, boost::optional< gtsam::Matrix & > H2=boost::none, boost::optional< gtsam::Matrix & > H3=boost::none) const
Point2 project_(const Pose3 &pose, const Vector5 &landmark, const double &inv_depth)
static const Pose3 pose(Rot3(Vector3(1,-1,-1).asDiagonal()), Point3(0, 0, 0.5))
#define EXPECT(condition)
Definition: Test.h:151
Pose3 level_pose
EIGEN_DEVICE_FUNC const AtanReturnType atan() const
Inverse Depth Camera based on Civera09tro, Montiel06rss. Landmarks are initialized from the first cam...
Array< double, 1, 3 > e(1./3., 0.5, 2.)
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
static Point2 Project1(const Point3 &point)
Vector3 Point3
Definition: Point3.h:35
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
boost::shared_ptr< Cal3_S2 > shared_ptr
Definition: Cal3_S2.h:39
int main()
The most common 5DOF 3D->2D calibration.


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:47:27