pinhole_camera_model.h
Go to the documentation of this file.
00001 #ifndef IMAGE_GEOMETRY_PINHOLE_CAMERA_MODEL_H
00002 #define IMAGE_GEOMETRY_PINHOLE_CAMERA_MODEL_H
00003 
00004 #include <sensor_msgs/CameraInfo.h>
00005 #include <opencv2/core/core.hpp>
00006 #include <opencv2/imgproc/imgproc.hpp>
00007 #include <opencv2/calib3d/calib3d.hpp>
00008 #include <stdexcept>
00009 
00010 namespace image_geometry {
00011 
00012 class Exception : public std::runtime_error
00013 {
00014 public:
00015   Exception(const std::string& description) : std::runtime_error(description) {}
00016 };
00017 
00022 class PinholeCameraModel
00023 {
00024 public:
00025   
00026   PinholeCameraModel();
00027 
00028   PinholeCameraModel(const PinholeCameraModel& other);
00029 
00033   bool fromCameraInfo(const sensor_msgs::CameraInfo& msg);
00034 
00038   bool fromCameraInfo(const sensor_msgs::CameraInfoConstPtr& msg);
00039 
00043   std::string tfFrame() const;
00044 
00048   ros::Time stamp() const;
00049 
00056   cv::Size fullResolution() const;
00057 
00065   cv::Size reducedResolution() const;
00066 
00067   cv::Point2d toFullResolution(const cv::Point2d& uv_reduced) const;
00068 
00069   cv::Rect toFullResolution(const cv::Rect& roi_reduced) const;
00070 
00071   cv::Point2d toReducedResolution(const cv::Point2d& uv_full) const;
00072 
00073   cv::Rect toReducedResolution(const cv::Rect& roi_full) const;
00074 
00078   cv::Rect rawRoi() const;
00079 
00083   cv::Rect rectifiedRoi() const;
00084 
00086   void project3dToPixel(const cv::Point3d& xyz, cv::Point2d& uv_rect) const ROS_DEPRECATED;
00087   
00096   cv::Point2d project3dToPixel(const cv::Point3d& xyz) const;
00097 
00098   void projectPixelTo3dRay(const cv::Point2d& uv_rect, cv::Point3d& ray) const ROS_DEPRECATED;
00099 
00111   cv::Point3d projectPixelTo3dRay(const cv::Point2d& uv_rect) const;
00112 
00116   void rectifyImage(const cv::Mat& raw, cv::Mat& rectified,
00117                     int interpolation = CV_INTER_LINEAR) const;
00118 
00122   void unrectifyImage(const cv::Mat& rectified, cv::Mat& raw,
00123                       int interpolation = CV_INTER_LINEAR) const;
00124 
00125   void rectifyPoint(const cv::Point2d& uv_raw, cv::Point2d& uv_rect) const ROS_DEPRECATED;
00126   
00130   cv::Point2d rectifyPoint(const cv::Point2d& uv_raw) const;
00131 
00132   void unrectifyPoint(const cv::Point2d& uv_rect, cv::Point2d& uv_raw) const ROS_DEPRECATED;
00133   
00137   cv::Point2d unrectifyPoint(const cv::Point2d& uv_rect) const;
00138 
00142   cv::Rect rectifyRoi(const cv::Rect& roi_raw) const;
00143 
00147   cv::Rect unrectifyRoi(const cv::Rect& roi_rect) const;
00148   
00152   const cv::Mat_<double>& intrinsicMatrix() const;
00153 
00157   const cv::Mat_<double>& distortionCoeffs() const;
00158 
00162   const cv::Mat_<double>& rotationMatrix() const;
00163 
00167   const cv::Mat_<double>& projectionMatrix() const;
00168 
00172   const cv::Mat_<double>& fullIntrinsicMatrix() const;
00173 
00177   const cv::Mat_<double>& fullProjectionMatrix() const;
00178 
00182   double fx() const;
00183 
00187   double fy() const;
00188 
00192   double cx() const;
00193 
00197   double cy() const;
00198 
00202   double Tx() const;
00203 
00207   double Ty() const;
00208 
00212   uint32_t height() const ROS_DEPRECATED;
00213 
00217   uint32_t width() const ROS_DEPRECATED;
00218 
00222   uint32_t binningX() const;
00223 
00227   uint32_t binningY() const;
00228   
00237   double getDeltaU(double deltaX, double Z) const;
00238 
00247   double getDeltaV(double deltaY, double Z) const;
00248 
00257   double getDeltaX(double deltaU, double Z) const;
00258 
00267   double getDeltaY(double deltaV, double Z) const;
00268 
00272   bool initialized() const { return cache_; }
00273 
00274 protected:
00275   sensor_msgs::CameraInfo cam_info_;
00276   cv::Mat_<double> D_, R_;           // Unaffected by binning, ROI
00277   cv::Mat_<double> K_, P_;           // Describe current image (includes binning, ROI)
00278   cv::Mat_<double> K_full_, P_full_; // Describe full-res image, needed for full maps
00279 
00280   // Use PIMPL here so we can change internals in patch updates if needed
00281   struct Cache;
00282   boost::shared_ptr<Cache> cache_; // Holds cached data for internal use
00283 
00284   void initRectificationMaps() const;
00285 
00286   friend class StereoCameraModel;
00287 };
00288 
00289 
00290 /* Trivial inline functions */
00291 inline std::string PinholeCameraModel::tfFrame() const
00292 {
00293   assert( initialized() );
00294   return cam_info_.header.frame_id;
00295 }
00296 
00297 inline ros::Time PinholeCameraModel::stamp() const
00298 {
00299   assert( initialized() );
00300   return cam_info_.header.stamp;
00301 }
00302 
00303 inline const cv::Mat_<double>& PinholeCameraModel::intrinsicMatrix() const  { return K_; }
00304 inline const cv::Mat_<double>& PinholeCameraModel::distortionCoeffs() const { return D_; }
00305 inline const cv::Mat_<double>& PinholeCameraModel::rotationMatrix() const   { return R_; }
00306 inline const cv::Mat_<double>& PinholeCameraModel::projectionMatrix() const { return P_; }
00307 inline const cv::Mat_<double>& PinholeCameraModel::fullIntrinsicMatrix() const  { return K_full_; }
00308 inline const cv::Mat_<double>& PinholeCameraModel::fullProjectionMatrix() const { return P_full_; }
00309 
00310 inline double PinholeCameraModel::fx() const { return P_(0,0); }
00311 inline double PinholeCameraModel::fy() const { return P_(1,1); }
00312 inline double PinholeCameraModel::cx() const { return P_(0,2); }
00313 inline double PinholeCameraModel::cy() const { return P_(1,2); }
00314 inline double PinholeCameraModel::Tx() const { return P_(0,3); }
00315 inline double PinholeCameraModel::Ty() const { return P_(1,3); }
00316 inline uint32_t PinholeCameraModel::height() const { return cam_info_.height; }
00317 inline uint32_t PinholeCameraModel::width() const  { return cam_info_.width; }
00318 
00319 inline uint32_t PinholeCameraModel::binningX() const { return cam_info_.binning_x; }
00320 inline uint32_t PinholeCameraModel::binningY() const { return cam_info_.binning_y; }
00321 
00322 inline double PinholeCameraModel::getDeltaU(double deltaX, double Z) const
00323 {
00324   assert( initialized() );
00325   return fx() * deltaX / Z;
00326 }
00327 
00328 inline double PinholeCameraModel::getDeltaV(double deltaY, double Z) const
00329 {
00330   assert( initialized() );
00331   return fy() * deltaY / Z;
00332 }
00333 
00334 inline double PinholeCameraModel::getDeltaX(double deltaU, double Z) const
00335 {
00336   assert( initialized() );
00337   return Z * deltaU / fx();
00338 }
00339 
00340 inline double PinholeCameraModel::getDeltaY(double deltaV, double Z) const
00341 {
00342   assert( initialized() );
00343   return Z * deltaV / fy();
00344 }
00345 
00346 } //namespace image_geometry
00347 
00348 #endif


image_geometry
Author(s): Patrick Mihelich
autogenerated on Sat Dec 28 2013 17:44:01