| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * SimpleCamera.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Created on: Aug 16, 2009 | 
					
						
							|  |  |  |  *      Author: dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "SimpleCamera.h"
 | 
					
						
							|  |  |  | #include "CalibratedCamera.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-14 00:09:54 +08:00
										 |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 	SimpleCamera::SimpleCamera(const Cal3_S2& K, | 
					
						
							|  |  |  | 			const CalibratedCamera& calibrated) : | 
					
						
							|  |  |  | 		calibrated_(calibrated), K_(K) { | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	SimpleCamera::SimpleCamera(const Cal3_S2& K, const Pose3& pose) : | 
					
						
							|  |  |  | 		calibrated_(pose), K_(K) { | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SimpleCamera::~SimpleCamera() { | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-14 00:09:54 +08:00
										 |  |  | 	pair<Point2, bool> SimpleCamera::projectSafe(const Point3& P) const { | 
					
						
							|  |  |  | 		Point3 cameraPoint = transform_to(calibrated_.pose(), P); | 
					
						
							|  |  |  | 		Point2 intrinsic = project_to_camera(cameraPoint); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		Point2 projection = uncalibrate(K_, intrinsic); | 
					
						
							| 
									
										
										
										
											2009-09-14 00:09:54 +08:00
										 |  |  | 		return pair<Point2, bool>(projection, cameraPoint.z() > 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Point2 SimpleCamera::project(const Point3 & P) const { | 
					
						
							|  |  |  | 		pair<Point2, bool> projected = projectSafe(P); | 
					
						
							|  |  |  | 		return projected.first; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-29 15:39:20 +08:00
										 |  |  | 	SimpleCamera SimpleCamera::level(const Cal3_S2& K, const Pose2& pose2, double height) { | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 		return SimpleCamera(K, CalibratedCamera::level(pose2, height)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	// measurement functions and derivatives
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-14 00:09:54 +08:00
										 |  |  | 	pair<Point2, bool> projectSafe(const SimpleCamera& camera, const Point3& point) { | 
					
						
							|  |  |  | 		return camera.projectSafe(point); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	Point2 project(const SimpleCamera& camera, const Point3& point) { | 
					
						
							|  |  |  | 		return camera.project(point); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	Matrix Dproject_pose(const SimpleCamera& camera, const Point3& point) { | 
					
						
							|  |  |  | 		Point2 intrinsic = project(camera.calibrated_, point); | 
					
						
							|  |  |  | 		Matrix D_intrinsic_pose = Dproject_pose(camera.calibrated_, point); | 
					
						
							|  |  |  | 		Matrix D_projection_intrinsic = Duncalibrate2(camera.K_, intrinsic); | 
					
						
							|  |  |  | 		Matrix D_projection_pose = D_projection_intrinsic * D_intrinsic_pose; | 
					
						
							|  |  |  | 		return D_projection_pose; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	Matrix Dproject_point(const SimpleCamera& camera, const Point3& point) { | 
					
						
							|  |  |  | 		Point2 intrinsic = project(camera.calibrated_, point); | 
					
						
							|  |  |  | 		Matrix D_intrinsic_point = Dproject_point(camera.calibrated_, point); | 
					
						
							|  |  |  | 		Matrix D_projection_intrinsic = Duncalibrate2(camera.K_, intrinsic); | 
					
						
							|  |  |  | 		Matrix D_projection_point = D_projection_intrinsic * D_intrinsic_point; | 
					
						
							|  |  |  | 		return D_projection_point; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-10-22 22:44:27 +08:00
										 |  |  | 	Point2 Dproject_pose_point(const SimpleCamera& camera, const Point3& point, | 
					
						
							|  |  |  | 			Matrix& D_projection_pose, Matrix& D_projection_point) { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Point2 intrinsic = project(camera.calibrated_, point); | 
					
						
							|  |  |  | 		Matrix D_intrinsic_pose = Dproject_pose(camera.calibrated_, point); | 
					
						
							|  |  |  | 		Matrix D_intrinsic_point = Dproject_point(camera.calibrated_, point); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 22:44:27 +08:00
										 |  |  | 		Point2 projection = uncalibrate(camera.K_, intrinsic); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		Matrix D_projection_intrinsic = Duncalibrate2(camera.K_, intrinsic); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		D_projection_pose = D_projection_intrinsic * D_intrinsic_pose; | 
					
						
							|  |  |  | 		D_projection_point = D_projection_intrinsic * D_intrinsic_point; | 
					
						
							| 
									
										
										
										
											2009-10-22 22:44:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return projection; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | } |