Main MRPT website > C++ reference
MRPT logo

pinhole.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 
00029 #ifndef mrpt_vision_pinhole_H
00030 #define mrpt_vision_pinhole_H
00031 
00032 #include <mrpt/utils/TCamera.h>
00033 #include <mrpt/vision/utils.h>
00034 
00035 namespace mrpt
00036 {
00037         namespace vision
00038         {
00039                 /** Functions related to pinhole camera models, point projections, etc. */
00040                 namespace pinhole
00041                 {
00042                         using mrpt::utils::TPixelCoordf;
00043 
00044                         /** Project a set of 3D points into a camera at an arbitrary 6D pose using its calibration matrix (undistorted projection model)
00045                           * \param in_points_3D [IN] The list of 3D points in world coordinates (meters) to project.
00046                           * \param cameraPose [IN] The pose of the camera in the world.
00047                           * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
00048                           * \param projectedPoints [OUT] The list of image coordinates (in pixels) for the projected points. At output this list is resized to the same number of input points.
00049                           * \param accept_points_behind [IN] See the note below.
00050                           *
00051                           * \note Points "behind" the camera (which couldn't be physically seen in the real world) are marked with pixel coordinates (-1,-1) to detect them as invalid, unless accept_points_behind is true. In that case they'll be projected normally.
00052                           *
00053                           * \sa projectPoints_with_distortion, projectPoint_no_distortion
00054                           */
00055                         void VISION_IMPEXP projectPoints_no_distortion(
00056                                 const std::vector<mrpt::poses::CPoint3D> &in_points_3D,
00057                                 const mrpt::poses::CPose3D &cameraPose,
00058                                 const mrpt::math::CMatrixDouble33 & intrinsicParams,
00059                                 std::vector<TPixelCoordf> &projectedPoints,
00060                                 bool accept_points_behind = false
00061                                 );
00062 
00063                         /** Project a single 3D point with global coordinates P into a camera at pose F, without distortion parameters.
00064                           *  The template argument INVERSE_CAM_POSE is related on how the camera pose "F" is stored:
00065                           *             - INVERSE_CAM_POSE:false -> The local coordinates of the feature wrt the camera F are: \f$ P \ominus F \f$
00066                           *             - INVERSE_CAM_POSE:true  -> The local coordinates of the feature wrt the camera F are: \f$ F \oplus P \f$
00067                           */
00068                         template <bool INVERSE_CAM_POSE>
00069                         inline TPixelCoordf projectPoint_no_distortion(
00070                                 const mrpt::utils::TCamera  &cam_params,
00071                                 const mrpt::poses::CPose3D  &F,
00072                                 const mrpt::math::TPoint3D &P)
00073                         {
00074                                 double x,y,z; // wrt cam (local coords)
00075                                 if (INVERSE_CAM_POSE)
00076                                         F.composePoint(P.x,P.y,P.z,  x,y,z);
00077                                 else
00078                                         F.inverseComposePoint(P.x,P.y,P.z, x,y,z);
00079                                 ASSERT_(z!=0)
00080                                 // Pinhole model:
00081                                 return TPixelCoordf(
00082                                         cam_params.cx() + cam_params.fx() * x/z,
00083                                         cam_params.cy() + cam_params.fy() * y/z );
00084                         }
00085 
00086                         /** Project a set of 3D points into a camera at an arbitrary 6D pose using its calibration matrix and distortion parameters (radial and tangential distortions projection model)
00087                           * \param in_points_3D [IN] The list of 3D points in world coordinates (meters) to project.
00088                           * \param cameraPose [IN] The pose of the camera in the world.
00089                           * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
00090                           * \param distortionParams [IN] The 4-length vector with the distortion parameters [k1 k2 p1 p2]. See http://www.mrpt.org/Camera_Parameters
00091                           * \param projectedPoints [OUT] The list of image coordinates (in pixels) for the projected points. At output this list is resized to the same number of input points.
00092                           * \param accept_points_behind [IN] See the note below.
00093                           *
00094                           * \note Points "behind" the camera (which couldn't be physically seen in the real world) are marked with pixel coordinates (-1,-1) to detect them as invalid, unless accept_points_behind is true. In that case they'll be projected normally.
00095                           *
00096                           * \sa projectPoint_with_distortion, projectPoints_no_distortion
00097                           */
00098                         void VISION_IMPEXP projectPoints_with_distortion(
00099                                 const std::vector<mrpt::poses::CPoint3D> &in_points_3D,
00100                                 const mrpt::poses::CPose3D &cameraPose,
00101                                 const mrpt::math::CMatrixDouble33 & intrinsicParams,
00102                                 const std::vector<double> & distortionParams,
00103                                 std::vector<TPixelCoordf> &projectedPoints,
00104                                 bool accept_points_behind = false
00105                                 );
00106 
00107                         /** Project one 3D point into a camera using its calibration matrix and distortion parameters (radial and tangential distortions projection model)
00108                           * \param in_point_wrt_cam [IN] The 3D point wrt the camera focus, with +Z=optical axis, +X=righthand in the image plane, +Y=downward in the image plane.
00109                           * \param in_cam_params [IN] The camera parameters. See http://www.mrpt.org/Camera_Parameters
00110                           * \param out_projectedPoints [OUT] The projected point, in pixel units.
00111                           * \param accept_points_behind [IN] See the note below.
00112                           *
00113                           * \note Points "behind" the camera (which couldn't be physically seen in the real world) are marked with pixel coordinates (-1,-1) to detect them as invalid, unless accept_points_behind is true. In that case they'll be projected normally.
00114                           *
00115                           * \sa projectPoints_with_distortion
00116                           */
00117                         void VISION_IMPEXP projectPoint_with_distortion(
00118                                 const mrpt::math::TPoint3D  &in_point_wrt_cam,
00119                                 const mrpt::utils::TCamera  &in_cam_params,
00120                                 TPixelCoordf  &out_projectedPoints,
00121                                 bool accept_points_behind = false
00122                                 );
00123 
00124                         //! \overload
00125                         void VISION_IMPEXP projectPoints_with_distortion(
00126                                 const std::vector<mrpt::math::TPoint3D>  &P,
00127                                 const mrpt::utils::TCamera  &params,
00128                                 const CPose3DQuat &cameraPose,
00129                                 std::vector<TPixelCoordf>  &pixels,
00130                                 bool accept_points_behind = false
00131                                 );
00132 
00133 
00134                         /** Undistort a list of points given by their pixel coordinates, provided the camera matrix and distortion coefficients.
00135                           * \param srcDistortedPixels [IN] The pixel coordinates as in the distorted image.
00136                           * \param dstUndistortedPixels [OUT] The computed pixel coordinates without distortion.
00137                           * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
00138                           * \param distortionParams [IN] The 4-length vector with the distortion parameters [k1 k2 p1 p2]. See http://www.mrpt.org/Camera_Parameters
00139                           * \sa undistort_point
00140                           */
00141                         void VISION_IMPEXP undistort_points(
00142                                 const std::vector<TPixelCoordf>  &srcDistortedPixels,
00143                                 std::vector<TPixelCoordf> &dstUndistortedPixels,
00144                                 const mrpt::math::CMatrixDouble33 & intrinsicParams,
00145                                 const std::vector<double> & distortionParams );
00146 
00147                         /** Undistort a list of points given by their pixel coordinates, provided the camera matrix and distortion coefficients.
00148                           * \param srcDistortedPixels [IN] The pixel coordinates as in the distorted image.
00149                           * \param dstUndistortedPixels [OUT] The computed pixel coordinates without distortion.
00150                           * \param cameraModel [IN] The camera parameters.
00151                           * \sa undistort_point
00152                           */
00153                         void VISION_IMPEXP undistort_points(
00154                                 const std::vector<TPixelCoordf>  &srcDistortedPixels,
00155                                 std::vector<TPixelCoordf> &dstUndistortedPixels,
00156                                 const mrpt::utils::TCamera  &cameraModel);
00157 
00158                         /** Undistort one point given by its pixel coordinates and the camera parameters.
00159                           * \sa undistort_points
00160                           */
00161                         void VISION_IMPEXP undistort_point(
00162                                 const TPixelCoordf  &inPt,
00163                                 TPixelCoordf        &outPt,
00164                                 const mrpt::utils::TCamera  &cameraModel);
00165 
00166                         /** Undistort a list of points given by their pixel coordinates, provided the camera matrix and distortion coefficients.
00167                           * \param inputPixels [IN] The pixel coordinates as in the distorted image.
00168                           * \param dstUndistortedPixels [OUT] The computed pixel coordinates without distortion.
00169                           * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
00170                           * \param distortionParams [IN] The 4-length vector with the distortion parameters [k1 k2 p1 p2]. See http://www.mrpt.org/Camera_Parameters
00171                           */
00172                         //void VISION_IMPEXP undistort_points(
00173                         //      const std::vector<TPixelCoordf> &inputPixels,           /* distorted pixels in image */
00174                         //      const mrpt::math::CMatrixDouble33                               &intrinsicParams,       /* intrinsic parameters of the camera */
00175                         //      const std::vector<double>                                               &distortionParams,      /* k1 k2 p1 p2 */
00176                         //      const unsigned int                                                              &resX,                          /* X-resolution of the image */
00177                         //      const unsigned int                                                              &resY,                          /* Y-resolution of the image */
00178                         //      std::vector<TPixelCoordf>                       &outputPixels           /* estimated undistorted pixels in image */
00179                         //      );
00180 
00181                 }
00182         }
00183 }
00184 
00185 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011