| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Frank Dellaert | 
					
						
							|  |  |  |  * brief: test SimpleCamera class | 
					
						
							|  |  |  |  * based on testVSLAMFactor.cpp | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | #include <math.h>
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | #include <iostream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/CppUnitLite/TestHarness.h>
 | 
					
						
							|  |  |  | #include <gtsam/base/numericalDerivative.h>
 | 
					
						
							|  |  |  | #include <gtsam/geometry/SimpleCamera.h>
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Cal3_S2 K(625, 625, 0, 0, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Pose3 pose1(Matrix_(3,3, | 
					
						
							|  |  |  | 				      1., 0., 0., | 
					
						
							|  |  |  | 				      0.,-1., 0., | 
					
						
							|  |  |  | 				      0., 0.,-1. | 
					
						
							|  |  |  | 				      ), | 
					
						
							| 
									
										
										
										
											2009-09-06 04:35:09 +08:00
										 |  |  | 			      Point3(0,0,0.5)); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |   | 
					
						
							|  |  |  | const SimpleCamera camera(K, pose1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-06 04:35:09 +08:00
										 |  |  | const Point3 point1(-0.08,-0.08, 0.0); | 
					
						
							|  |  |  | const Point3 point2(-0.08, 0.08, 0.0); | 
					
						
							|  |  |  | const Point3 point3( 0.08, 0.08, 0.0); | 
					
						
							|  |  |  | const Point3 point4( 0.08,-0.08, 0.0); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( SimpleCamera, constructor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   CHECK(assert_equal( camera.calibration(), K)); | 
					
						
							|  |  |  |   CHECK(assert_equal( camera.pose(), pose1)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-29 15:39:20 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( SimpleCamera, level2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Create a level camera, looking in Y-direction
 | 
					
						
							| 
									
										
										
										
											2009-09-06 04:35:09 +08:00
										 |  |  | 	Pose2 pose2(0.4,0.3,M_PI_2); | 
					
						
							|  |  |  | 	SimpleCamera camera = SimpleCamera::level(K, pose2, 0.1); | 
					
						
							| 
									
										
										
										
											2009-08-29 15:39:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// expected
 | 
					
						
							|  |  |  | 	Point3 x(1,0,0),y(0,0,-1),z(0,1,0); | 
					
						
							|  |  |  | 	Rot3 wRc(x,y,z); | 
					
						
							| 
									
										
										
										
											2009-09-06 04:35:09 +08:00
										 |  |  | 	Pose3 expected(wRc,Point3(0.4,0.3,0.1)); | 
					
						
							| 
									
										
										
										
											2009-08-29 15:39:20 +08:00
										 |  |  |   CHECK(assert_equal( camera.pose(), expected)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( SimpleCamera, project) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   CHECK(assert_equal( camera.project(point1), Point2(-100,  100) )); | 
					
						
							|  |  |  |   CHECK(assert_equal( camera.project(point2), Point2(-100, -100) )); | 
					
						
							|  |  |  |   CHECK(assert_equal( camera.project(point3), Point2( 100, -100) )); | 
					
						
							|  |  |  |   CHECK(assert_equal( camera.project(point4), Point2( 100,  100) )); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-19 16:32:55 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( SimpleCamera, backproject) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   CHECK(assert_equal( camera.backproject(Point2(-100,  100), 0.5),  point1)); | 
					
						
							|  |  |  |   CHECK(assert_equal( camera.backproject(Point2(-100, -100), 0.5),  point2)); | 
					
						
							|  |  |  |   CHECK(assert_equal( camera.backproject(Point2( 100, -100), 0.5),  point3)); | 
					
						
							|  |  |  |   CHECK(assert_equal( camera.backproject(Point2( 100,  100), 0.5),  point4)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-24 10:20:54 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( SimpleCamera, backproject2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Point3 origin; | 
					
						
							|  |  |  | 	Rot3 rot(1., 0., 0., 0., 0., 1., 0., -1., 0.); // a camera looking down
 | 
					
						
							|  |  |  | 	SimpleCamera camera(K, Pose3(rot, origin)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Point3 actual = camera.backproject(Point2(), 1.); | 
					
						
							|  |  |  | 	Point3 expected(0., 1., 0.); | 
					
						
							|  |  |  | 	pair<Point2, bool> x = camera.projectSafe(expected); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CHECK(assert_equal(expected, actual)); | 
					
						
							|  |  |  | 	CHECK(assert_equal(Point2(), x.first)); | 
					
						
							|  |  |  | 	CHECK(x.second); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | Point2 project2(const Pose3& pose, const Point3& point) { | 
					
						
							| 
									
										
										
										
											2010-08-23 05:45:53 +08:00
										 |  |  | 	return SimpleCamera(K,pose).project(point); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST( SimpleCamera, Dproject_point_pose) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Matrix Dpose, Dpoint; | 
					
						
							| 
									
										
										
										
											2010-08-23 05:45:53 +08:00
										 |  |  | 	Point2 result = camera.project(point1, Dpose, Dpoint); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	Matrix numerical_pose  = numericalDerivative21(project2, pose1, point1); | 
					
						
							|  |  |  | 	Matrix numerical_point = numericalDerivative22(project2, pose1, point1); | 
					
						
							| 
									
										
										
										
											2010-08-23 05:45:53 +08:00
										 |  |  | 	CHECK(assert_equal(result, Point2(-100,  100) )); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	CHECK(assert_equal(Dpose,  numerical_pose, 1e-7)); | 
					
						
							|  |  |  | 	CHECK(assert_equal(Dpoint, numerical_point,1e-7)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-02-21 06:22:45 +08:00
										 |  |  | int main() { TestResult tr; return TestRegistry::runAllTests(tr); } | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |