Main MRPT website > C++ reference
MRPT logo
pinhole.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2014, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #ifndef mrpt_vision_pinhole_H
11 #define mrpt_vision_pinhole_H
12 
13 #include <mrpt/utils/TCamera.h>
14 #include <mrpt/vision/utils.h>
15 #include <mrpt/poses/poses_frwds.h>
16 
17 namespace mrpt
18 {
19  namespace vision
20  {
21  /** Functions related to pinhole camera models, point projections, etc. \ingroup mrpt_vision_grp */
22  namespace pinhole
23  {
24  /** \addtogroup mrpt_vision_grp
25  * @{ */
26 
28 
29  /** Project a set of 3D points into a camera at an arbitrary 6D pose using its calibration matrix (undistorted projection model)
30  * \param in_points_3D [IN] The list of 3D points in world coordinates (meters) to project.
31  * \param cameraPose [IN] The pose of the camera in the world.
32  * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
33  * \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.
34  * \param accept_points_behind [IN] See the note below.
35  *
36  * \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.
37  *
38  * \sa projectPoints_with_distortion, projectPoint_no_distortion
39  */
41  const std::vector<mrpt::math::TPoint3D> &in_points_3D,
42  const mrpt::poses::CPose3D &cameraPose,
43  const mrpt::math::CMatrixDouble33 & intrinsicParams,
44  std::vector<TPixelCoordf> &projectedPoints,
45  bool accept_points_behind = false
46  );
47 
48  /** Project a single 3D point with global coordinates P into a camera at pose F, without distortion parameters.
49  * The template argument INVERSE_CAM_POSE is related on how the camera pose "F" is stored:
50  * - INVERSE_CAM_POSE:false -> The local coordinates of the feature wrt the camera F are: \f$ P \ominus F \f$
51  * - INVERSE_CAM_POSE:true -> The local coordinates of the feature wrt the camera F are: \f$ F \oplus P \f$
52  */
53  template <bool INVERSE_CAM_POSE>
55  const mrpt::utils::TCamera &cam_params,
56  const mrpt::poses::CPose3D &F,
57  const mrpt::math::TPoint3D &P)
58  {
59  double x,y,z; // wrt cam (local coords)
60  if (INVERSE_CAM_POSE)
61  F.composePoint(P.x,P.y,P.z, x,y,z);
62  else
63  F.inverseComposePoint(P.x,P.y,P.z, x,y,z);
64  ASSERT_(z!=0)
65  // Pinhole model:
66  return TPixelCoordf(
67  cam_params.cx() + cam_params.fx() * x/z,
68  cam_params.cy() + cam_params.fy() * y/z );
69  }
70 
71  //! \overload
72  template <typename POINT>
74  const POINT &in_point_wrt_cam,
75  const mrpt::utils::TCamera &cam_params,
76  TPixelCoordf &out_projectedPoints )
77  {
78  ASSERT_(in_point_wrt_cam.z!=0)
79  // Pinhole model:
80  out_projectedPoints.x = cam_params.cx() + cam_params.fx() * in_point_wrt_cam.x/in_point_wrt_cam.z;
81  out_projectedPoints.y = cam_params.cy() + cam_params.fy() * in_point_wrt_cam.y/in_point_wrt_cam.z;
82  }
83 
84 
85  /** 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)
86  * \param in_points_3D [IN] The list of 3D points in world coordinates (meters) to project.
87  * \param cameraPose [IN] The pose of the camera in the world.
88  * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
89  * \param distortionParams [IN] The 4-length vector with the distortion parameters [k1 k2 p1 p2]. See http://www.mrpt.org/Camera_Parameters
90  * \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.
91  * \param accept_points_behind [IN] See the note below.
92  *
93  * \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.
94  *
95  * \sa projectPoint_with_distortion, projectPoints_no_distortion
96  */
98  const std::vector<mrpt::math::TPoint3D> &in_points_3D,
99  const mrpt::poses::CPose3D &cameraPose,
100  const mrpt::math::CMatrixDouble33 & intrinsicParams,
101  const std::vector<double> & distortionParams,
102  std::vector<TPixelCoordf> &projectedPoints,
103  bool accept_points_behind = false
104  );
105 
106  /** Project one 3D point into a camera using its calibration matrix and distortion parameters (radial and tangential distortions projection model)
107  * \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.
108  * \param in_cam_params [IN] The camera parameters. See http://www.mrpt.org/Camera_Parameters
109  * \param out_projectedPoints [OUT] The projected point, in pixel units.
110  * \param accept_points_behind [IN] See the note below.
111  *
112  * \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.
113  *
114  * \sa projectPoints_with_distortion
115  */
117  const mrpt::math::TPoint3D &in_point_wrt_cam,
118  const mrpt::utils::TCamera &in_cam_params,
119  TPixelCoordf &out_projectedPoints,
120  bool accept_points_behind = false
121  );
122 
123  //! \overload
125  const std::vector<mrpt::math::TPoint3D> &P,
126  const mrpt::utils::TCamera &params,
127  const mrpt::poses::CPose3DQuat &cameraPose,
128  std::vector<TPixelCoordf> &pixels,
129  bool accept_points_behind = false
130  );
131 
132 
133  /** Undistort a list of points given by their pixel coordinates, provided the camera matrix and distortion coefficients.
134  * \param srcDistortedPixels [IN] The pixel coordinates as in the distorted image.
135  * \param dstUndistortedPixels [OUT] The computed pixel coordinates without distortion.
136  * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
137  * \param distortionParams [IN] The 4-length vector with the distortion parameters [k1 k2 p1 p2]. See http://www.mrpt.org/Camera_Parameters
138  * \sa undistort_point
139  */
141  const std::vector<TPixelCoordf> &srcDistortedPixels,
142  std::vector<TPixelCoordf> &dstUndistortedPixels,
143  const mrpt::math::CMatrixDouble33 & intrinsicParams,
144  const std::vector<double> & distortionParams );
145 
146  /** Undistort a list of points given by their pixel coordinates, provided the camera matrix and distortion coefficients.
147  * \param srcDistortedPixels [IN] The pixel coordinates as in the distorted image.
148  * \param dstUndistortedPixels [OUT] The computed pixel coordinates without distortion.
149  * \param cameraModel [IN] The camera parameters.
150  * \sa undistort_point
151  */
153  const std::vector<TPixelCoordf> &srcDistortedPixels,
154  std::vector<TPixelCoordf> &dstUndistortedPixels,
155  const mrpt::utils::TCamera &cameraModel);
156 
157  /** Undistort one point given by its pixel coordinates and the camera parameters.
158  * \sa undistort_points
159  */
161  const TPixelCoordf &inPt,
162  TPixelCoordf &outPt,
163  const mrpt::utils::TCamera &cameraModel);
164 
165  /** @} */ // end of grouping
166  }
167  }
168 }
169 
170 #endif
TPixelCoordf projectPoint_no_distortion(const mrpt::utils::TCamera &cam_params, const mrpt::poses::CPose3D &F, const mrpt::math::TPoint3D &P)
Project a single 3D point with global coordinates P into a camera at pose F, without distortion param...
Definition: pinhole.h:54
A pair (x,y) of pixel coordinates (subpixel resolution).
Definition: TPixelCoord.h:21
double z
X,Y,Z coordinates.
void VISION_IMPEXP projectPoints_with_distortion(const std::vector< mrpt::math::TPoint3D > &in_points_3D, const mrpt::poses::CPose3D &cameraPose, const mrpt::math::CMatrixDouble33 &intrinsicParams, const std::vector< double > &distortionParams, std::vector< TPixelCoordf > &projectedPoints, bool accept_points_behind=false)
Project a set of 3D points into a camera at an arbitrary 6D pose using its calibration matrix and dis...
double fy() const
Get the value of the focal length y-value (in pixels).
Definition: TCamera.h:155
A numeric matrix of compile-time fixed size.
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
void VISION_IMPEXP undistort_point(const TPixelCoordf &inPt, TPixelCoordf &outPt, const mrpt::utils::TCamera &cameraModel)
Undistort one point given by its pixel coordinates and the camera parameters.
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
Definition: CPose3DQuat.h:41
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void inverseComposePoint(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL) const
Computes the 3D point L such as .
void VISION_IMPEXP projectPoint_with_distortion(const mrpt::math::TPoint3D &in_point_wrt_cam, const mrpt::utils::TCamera &in_cam_params, TPixelCoordf &out_projectedPoints, bool accept_points_behind=false)
Project one 3D point into a camera using its calibration matrix and distortion parameters (radial and...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
#define ASSERT_(f)
double fx() const
Get the value of the focal length x-value (in pixels).
Definition: TCamera.h:153
void VISION_IMPEXP undistort_points(const std::vector< TPixelCoordf > &srcDistortedPixels, std::vector< TPixelCoordf > &dstUndistortedPixels, const mrpt::math::CMatrixDouble33 &intrinsicParams, const std::vector< double > &distortionParams)
Undistort a list of points given by their pixel coordinates, provided the camera matrix and distortio...
void VISION_IMPEXP projectPoints_no_distortion(const std::vector< mrpt::math::TPoint3D > &in_points_3D, const mrpt::poses::CPose3D &cameraPose, const mrpt::math::CMatrixDouble33 &intrinsicParams, std::vector< TPixelCoordf > &projectedPoints, bool accept_points_behind=false)
Project a set of 3D points into a camera at an arbitrary 6D pose using its calibration matrix (undist...
Lightweight 3D point.
double cx() const
Get the value of the principal point x-coordinate (in pixels).
Definition: TCamera.h:149
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:31
double cy() const
Get the value of the principal point y-coordinate (in pixels).
Definition: TCamera.h:151



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014