| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * CalibratedCamera.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Created on: Aug 17, 2009 | 
					
						
							|  |  |  |  *      Author: dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 04:51:03 +08:00
										 |  |  | #include "Point2.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | #include "CalibratedCamera.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	// Auxiliary functions
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Point2 project_to_camera(const Point3& P) { | 
					
						
							|  |  |  | 		return Point2(P.x() / P.z(), P.y() / P.z()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Matrix Dproject_to_camera1(const Point3& P) { | 
					
						
							|  |  |  | 		double d = 1.0 / P.z(), d2 = d * d; | 
					
						
							|  |  |  | 		return Matrix_(2, 3, d, 0.0, -P.x() * d2, 0.0, d, -P.y() * d2); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	// Methods
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CalibratedCamera::CalibratedCamera(const Pose3& pose) : | 
					
						
							|  |  |  | 		pose_(pose) { | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CalibratedCamera::~CalibratedCamera() { | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 	CalibratedCamera CalibratedCamera::level(const Pose2& pose2, double height) { | 
					
						
							|  |  |  | 		double st = sin(pose2.theta()), ct = cos(pose2.theta()); | 
					
						
							|  |  |  | 		Point3 x(st, -ct, 0), y(0, 0, -1), z(ct, st, 0); | 
					
						
							|  |  |  | 		Rot3 wRc(x, y, z); | 
					
						
							|  |  |  | 		Point3 t(pose2.x(), pose2.y(), height); | 
					
						
							|  |  |  | 		Pose3 pose3(wRc, t); | 
					
						
							|  |  |  | 		return CalibratedCamera(pose3); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	Point2 CalibratedCamera::project(const Point3 & P) const { | 
					
						
							|  |  |  | 		Point3 cameraPoint = transform_to(pose_, P); | 
					
						
							|  |  |  | 		Point2 intrinsic = project_to_camera(cameraPoint); | 
					
						
							|  |  |  | 		return intrinsic; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 	// measurement functions and derivatives
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	Point2 project(const CalibratedCamera& camera, const Point3& point) { | 
					
						
							|  |  |  | 		return camera.project(point); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	Matrix Dproject_pose(const CalibratedCamera& camera, const Point3& point) { | 
					
						
							|  |  |  | 		Point3 cameraPoint = transform_to(camera.pose(), point); | 
					
						
							|  |  |  | 		Matrix D_cameraPoint_pose = Dtransform_to1(camera.pose(), point); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Point2 intrinsic = project_to_camera(cameraPoint); | 
					
						
							|  |  |  | 		Matrix D_intrinsic_cameraPoint = Dproject_to_camera1(cameraPoint); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Matrix D_intrinsic_pose = D_intrinsic_cameraPoint * D_cameraPoint_pose; | 
					
						
							|  |  |  | 		return D_intrinsic_pose; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	Matrix Dproject_point(const CalibratedCamera& camera, const Point3& point) { | 
					
						
							| 
									
										
										
										
											2009-12-18 13:36:53 +08:00
										 |  |  | 		Point3 cameraPoint = transform_to(camera.pose(),point); | 
					
						
							|  |  |  | 		Matrix D_cameraPoint_point = Dtransform_to2(camera.pose(),point); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Point2 intrinsic = project_to_camera(cameraPoint); | 
					
						
							|  |  |  | 		Matrix D_intrinsic_cameraPoint = Dproject_to_camera1(cameraPoint); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Matrix D_intrinsic_point = D_intrinsic_cameraPoint * D_cameraPoint_point; | 
					
						
							|  |  |  | 		return D_intrinsic_point; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-10-22 22:44:27 +08:00
										 |  |  | 	Point2 Dproject_pose_point(const CalibratedCamera& camera, const Point3& point, | 
					
						
							|  |  |  | 			Matrix& D_intrinsic_pose, Matrix& D_intrinsic_point) { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Point3 cameraPoint = transform_to(camera.pose(), point); | 
					
						
							| 
									
										
										
										
											2009-12-18 13:36:53 +08:00
										 |  |  | 		Matrix D_cameraPoint_pose = Dtransform_to1(camera.pose(),point); // 3*6
 | 
					
						
							|  |  |  | 		Matrix D_cameraPoint_point = Dtransform_to2(camera.pose(),point); // 3*3
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 22:44:27 +08:00
										 |  |  | 		Point2 intrinsic = project_to_camera(cameraPoint); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		Matrix D_intrinsic_cameraPoint = Dproject_to_camera1(cameraPoint); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		D_intrinsic_pose = D_intrinsic_cameraPoint * D_cameraPoint_pose; // 2*6
 | 
					
						
							|  |  |  | 		D_intrinsic_point = D_intrinsic_cameraPoint * D_cameraPoint_point; // 2*3
 | 
					
						
							| 
									
										
										
										
											2009-10-22 22:44:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return intrinsic; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | } |