| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * SimpleCamera.h | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Created on: Aug 16, 2009 | 
					
						
							|  |  |  |  *      Author: dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef SIMPLECAMERA_H_
 | 
					
						
							|  |  |  | #define SIMPLECAMERA_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "CalibratedCamera.h"
 | 
					
						
							|  |  |  | #include "Cal3_S2.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * A simple camera class with a Cal3_S2 calibration | 
					
						
							|  |  |  | 	 * Basically takes a Calibrated camera and adds calibration information | 
					
						
							|  |  |  | 	 * to produce measurements in pixels. | 
					
						
							|  |  |  | 	 * Not a sublass as a SimpleCamera *is not* a CalibratedCamera. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	class SimpleCamera { | 
					
						
							|  |  |  | 	private: | 
					
						
							|  |  |  | 		CalibratedCamera calibrated_; // Calibrated camera
 | 
					
						
							|  |  |  | 		Cal3_S2 K_; // Calibration
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 		SimpleCamera(const Cal3_S2& K, const CalibratedCamera& calibrated); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		SimpleCamera(const Cal3_S2& K, const Pose3& pose); | 
					
						
							|  |  |  | 		virtual ~SimpleCamera(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const Pose3& pose() const { | 
					
						
							|  |  |  | 			return calibrated_.pose(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const Cal3_S2& calibration() const { | 
					
						
							|  |  |  | 			return K_; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-14 00:09:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * project a 3d point to the camera and also check the depth | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		std::pair<Point2,bool> projectSafe(const Point3& P) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * project a 3d point to the camera | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		Point2 project(const Point3& P) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * Create a level camera at the given 2D pose and height | 
					
						
							| 
									
										
										
										
											2009-09-12 04:51:49 +08:00
										 |  |  | 		 * @param pose2 specifies the location and viewing direction | 
					
						
							|  |  |  | 		 * (theta 0 = looking in direction of positive X axis) | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2009-08-29 15:39:20 +08:00
										 |  |  | 		static SimpleCamera level(const Cal3_S2& K, const Pose2& pose2, double height); | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		// Friends
 | 
					
						
							|  |  |  | 		friend Matrix Dproject_pose(const SimpleCamera& camera,  const Point3& point); | 
					
						
							|  |  |  | 		friend Matrix Dproject_point(const SimpleCamera& camera, const Point3& point); | 
					
						
							| 
									
										
										
										
											2009-10-22 22:44:27 +08:00
										 |  |  | 		friend 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
										 |  |  | 
 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	// measurement functions and derivatives
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-14 00:09:54 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * This function receives the camera pose and the landmark location and | 
					
						
							| 
									
										
										
										
											2009-10-22 22:44:27 +08:00
										 |  |  | 	 * returns the location the point is supposed to appear in the image | 
					
						
							|  |  |  | 	 * as well as the sign of the depth. | 
					
						
							| 
									
										
										
										
											2009-09-14 00:09:54 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	std::pair<Point2, bool> projectSafe(const SimpleCamera& camera, const Point3& point); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * This function receives the camera pose and the landmark location and | 
					
						
							| 
									
										
										
										
											2009-10-22 22:44:27 +08:00
										 |  |  | 	 * returns the location the point is supposed to appear in the image | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	Point2 project(const SimpleCamera& camera, const Point3& point); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Derivatives of project. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	Matrix Dproject_pose(const SimpleCamera& camera, const Point3& point); | 
					
						
							|  |  |  | 	Matrix Dproject_point(const SimpleCamera& camera, const Point3& point); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * super-duper combined evaluation + derivatives | 
					
						
							|  |  |  | 	 * saves a lot of time because a lot of computation is shared | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* SIMPLECAMERA_H_ */
 |