Main MRPT website > C++ reference
MRPT logo
pinhole.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 
29 #ifndef mrpt_vision_pinhole_H
30 #define mrpt_vision_pinhole_H
31 
32 #include <mrpt/utils/TCamera.h>
33 #include <mrpt/vision/utils.h>
34 
35 namespace mrpt
36 {
37  namespace vision
38  {
39  /** Functions related to pinhole camera models, point projections, etc. \ingroup mrpt_vision_grp */
40  namespace pinhole
41  {
42  /** \addtogroup mrpt_vision_grp
43  * @{ */
44 
46 
47  /** Project a set of 3D points into a camera at an arbitrary 6D pose using its calibration matrix (undistorted projection model)
48  * \param in_points_3D [IN] The list of 3D points in world coordinates (meters) to project.
49  * \param cameraPose [IN] The pose of the camera in the world.
50  * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
51  * \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.
52  * \param accept_points_behind [IN] See the note below.
53  *
54  * \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.
55  *
56  * \sa projectPoints_with_distortion, projectPoint_no_distortion
57  */
59  const std::vector<mrpt::poses::CPoint3D> &in_points_3D,
60  const mrpt::poses::CPose3D &cameraPose,
61  const mrpt::math::CMatrixDouble33 & intrinsicParams,
62  std::vector<TPixelCoordf> &projectedPoints,
63  bool accept_points_behind = false
64  );
65 
66  /** Project a single 3D point with global coordinates P into a camera at pose F, without distortion parameters.
67  * The template argument INVERSE_CAM_POSE is related on how the camera pose "F" is stored:
68  * - INVERSE_CAM_POSE:false -> The local coordinates of the feature wrt the camera F are: \f$ P \ominus F \f$
69  * - INVERSE_CAM_POSE:true -> The local coordinates of the feature wrt the camera F are: \f$ F \oplus P \f$
70  */
71  template <bool INVERSE_CAM_POSE>
73  const mrpt::utils::TCamera &cam_params,
74  const mrpt::poses::CPose3D &F,
75  const mrpt::math::TPoint3D &P)
76  {
77  double x,y,z; // wrt cam (local coords)
78  if (INVERSE_CAM_POSE)
79  F.composePoint(P.x,P.y,P.z, x,y,z);
80  else
81  F.inverseComposePoint(P.x,P.y,P.z, x,y,z);
82  ASSERT_(z!=0)
83  // Pinhole model:
84  return TPixelCoordf(
85  cam_params.cx() + cam_params.fx() * x/z,
86  cam_params.cy() + cam_params.fy() * y/z );
87  }
88 
89  //! \overload
90  template <typename POINT>
92  const POINT &in_point_wrt_cam,
93  const mrpt::utils::TCamera &cam_params,
94  TPixelCoordf &out_projectedPoints )
95  {
96  ASSERT_(in_point_wrt_cam.z!=0)
97  // Pinhole model:
98  out_projectedPoints.x = cam_params.cx() + cam_params.fx() * in_point_wrt_cam.x/in_point_wrt_cam.z;
99  out_projectedPoints.y = cam_params.cy() + cam_params.fy() * in_point_wrt_cam.y/in_point_wrt_cam.z;
100  }
101 
102 
103  /** 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)
104  * \param in_points_3D [IN] The list of 3D points in world coordinates (meters) to project.
105  * \param cameraPose [IN] The pose of the camera in the world.
106  * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
107  * \param distortionParams [IN] The 4-length vector with the distortion parameters [k1 k2 p1 p2]. See http://www.mrpt.org/Camera_Parameters
108  * \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.
109  * \param accept_points_behind [IN] See the note below.
110  *
111  * \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.
112  *
113  * \sa projectPoint_with_distortion, projectPoints_no_distortion
114  */
116  const std::vector<mrpt::poses::CPoint3D> &in_points_3D,
117  const mrpt::poses::CPose3D &cameraPose,
118  const mrpt::math::CMatrixDouble33 & intrinsicParams,
119  const std::vector<double> & distortionParams,
120  std::vector<TPixelCoordf> &projectedPoints,
121  bool accept_points_behind = false
122  );
123 
124  /** Project one 3D point into a camera using its calibration matrix and distortion parameters (radial and tangential distortions projection model)
125  * \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.
126  * \param in_cam_params [IN] The camera parameters. See http://www.mrpt.org/Camera_Parameters
127  * \param out_projectedPoints [OUT] The projected point, in pixel units.
128  * \param accept_points_behind [IN] See the note below.
129  *
130  * \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.
131  *
132  * \sa projectPoints_with_distortion
133  */
135  const mrpt::math::TPoint3D &in_point_wrt_cam,
136  const mrpt::utils::TCamera &in_cam_params,
137  TPixelCoordf &out_projectedPoints,
138  bool accept_points_behind = false
139  );
140 
141  //! \overload
143  const std::vector<mrpt::math::TPoint3D> &P,
144  const mrpt::utils::TCamera &params,
145  const CPose3DQuat &cameraPose,
146  std::vector<TPixelCoordf> &pixels,
147  bool accept_points_behind = false
148  );
149 
150 
151  /** Undistort a list of points given by their pixel coordinates, provided the camera matrix and distortion coefficients.
152  * \param srcDistortedPixels [IN] The pixel coordinates as in the distorted image.
153  * \param dstUndistortedPixels [OUT] The computed pixel coordinates without distortion.
154  * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
155  * \param distortionParams [IN] The 4-length vector with the distortion parameters [k1 k2 p1 p2]. See http://www.mrpt.org/Camera_Parameters
156  * \sa undistort_point
157  */
159  const std::vector<TPixelCoordf> &srcDistortedPixels,
160  std::vector<TPixelCoordf> &dstUndistortedPixels,
161  const mrpt::math::CMatrixDouble33 & intrinsicParams,
162  const std::vector<double> & distortionParams );
163 
164  /** Undistort a list of points given by their pixel coordinates, provided the camera matrix and distortion coefficients.
165  * \param srcDistortedPixels [IN] The pixel coordinates as in the distorted image.
166  * \param dstUndistortedPixels [OUT] The computed pixel coordinates without distortion.
167  * \param cameraModel [IN] The camera parameters.
168  * \sa undistort_point
169  */
171  const std::vector<TPixelCoordf> &srcDistortedPixels,
172  std::vector<TPixelCoordf> &dstUndistortedPixels,
173  const mrpt::utils::TCamera &cameraModel);
174 
175  /** Undistort one point given by its pixel coordinates and the camera parameters.
176  * \sa undistort_points
177  */
179  const TPixelCoordf &inPt,
180  TPixelCoordf &outPt,
181  const mrpt::utils::TCamera &cameraModel);
182 
183  /** @} */ // end of grouping
184  }
185  }
186 }
187 
188 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013