Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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>
16
17namespace 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
27 /** Project a set of 3D points into a camera at an arbitrary 6D pose using its calibration matrix (undistorted projection model)
28 * \param in_points_3D [IN] The list of 3D points in world coordinates (meters) to project.
29 * \param cameraPose [IN] The pose of the camera in the world.
30 * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
31 * \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.
32 * \param accept_points_behind [IN] See the note below.
33 *
34 * \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.
35 *
36 * \sa projectPoints_with_distortion, projectPoint_no_distortion
37 */
39 const std::vector<mrpt::math::TPoint3D> &in_points_3D,
40 const mrpt::poses::CPose3D &cameraPose,
41 const mrpt::math::CMatrixDouble33 & intrinsicParams,
42 std::vector<mrpt::utils::TPixelCoordf> &projectedPoints,
43 bool accept_points_behind = false
44 );
45
46 /** Project a single 3D point with global coordinates P into a camera at pose F, without distortion parameters.
47 * The template argument INVERSE_CAM_POSE is related on how the camera pose "F" is stored:
48 * - INVERSE_CAM_POSE:false -> The local coordinates of the feature wrt the camera F are: \f$ P \ominus F \f$
49 * - INVERSE_CAM_POSE:true -> The local coordinates of the feature wrt the camera F are: \f$ F \oplus P \f$
50 */
51 template <bool INVERSE_CAM_POSE>
53 const mrpt::utils::TCamera &cam_params,
54 const mrpt::poses::CPose3D &F,
55 const mrpt::math::TPoint3D &P)
56 {
57 double x,y,z; // wrt cam (local coords)
58 if (INVERSE_CAM_POSE)
59 F.composePoint(P.x,P.y,P.z, x,y,z);
60 else
61 F.inverseComposePoint(P.x,P.y,P.z, x,y,z);
62 ASSERT_(z!=0)
63 // Pinhole model:
65 cam_params.cx() + cam_params.fx() * x/z,
66 cam_params.cy() + cam_params.fy() * y/z );
67 }
68
69 //! \overload
70 template <typename POINT>
72 const POINT &in_point_wrt_cam,
73 const mrpt::utils::TCamera &cam_params,
74 mrpt::utils::TPixelCoordf &out_projectedPoints )
75 {
76 ASSERT_(in_point_wrt_cam.z!=0)
77 // Pinhole model:
78 out_projectedPoints.x = cam_params.cx() + cam_params.fx() * in_point_wrt_cam.x/in_point_wrt_cam.z;
79 out_projectedPoints.y = cam_params.cy() + cam_params.fy() * in_point_wrt_cam.y/in_point_wrt_cam.z;
80 }
81
82
83 /** 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)
84 * \param in_points_3D [IN] The list of 3D points in world coordinates (meters) to project.
85 * \param cameraPose [IN] The pose of the camera in the world.
86 * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
87 * \param distortionParams [IN] The 4-length vector with the distortion parameters [k1 k2 p1 p2]. See http://www.mrpt.org/Camera_Parameters
88 * \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.
89 * \param accept_points_behind [IN] See the note below.
90 *
91 * \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.
92 *
93 * \sa projectPoint_with_distortion, projectPoints_no_distortion
94 */
96 const std::vector<mrpt::math::TPoint3D> &in_points_3D,
97 const mrpt::poses::CPose3D &cameraPose,
98 const mrpt::math::CMatrixDouble33 & intrinsicParams,
99 const std::vector<double> & distortionParams,
100 std::vector<mrpt::utils::TPixelCoordf> &projectedPoints,
101 bool accept_points_behind = false
102 );
103
104 /** Project one 3D point into a camera using its calibration matrix and distortion parameters (radial and tangential distortions projection model)
105 * \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.
106 * \param in_cam_params [IN] The camera parameters. See http://www.mrpt.org/Camera_Parameters
107 * \param out_projectedPoints [OUT] The projected point, in pixel units.
108 * \param accept_points_behind [IN] See the note below.
109 *
110 * \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.
111 *
112 * \sa projectPoints_with_distortion
113 */
115 const mrpt::math::TPoint3D &in_point_wrt_cam,
116 const mrpt::utils::TCamera &in_cam_params,
117 mrpt::utils::TPixelCoordf &out_projectedPoints,
118 bool accept_points_behind = false
119 );
120
121 //! \overload
123 const std::vector<mrpt::math::TPoint3D> &P,
124 const mrpt::utils::TCamera &params,
125 const mrpt::poses::CPose3DQuat &cameraPose,
126 std::vector<mrpt::utils::TPixelCoordf> &pixels,
127 bool accept_points_behind = false
128 );
129
130
131 /** Undistort a list of points given by their pixel coordinates, provided the camera matrix and distortion coefficients.
132 * \param srcDistortedPixels [IN] The pixel coordinates as in the distorted image.
133 * \param dstUndistortedPixels [OUT] The computed pixel coordinates without distortion.
134 * \param intrinsicParams [IN] The 3x3 calibration matrix. See http://www.mrpt.org/Camera_Parameters
135 * \param distortionParams [IN] The 4-length vector with the distortion parameters [k1 k2 p1 p2]. See http://www.mrpt.org/Camera_Parameters
136 * \sa undistort_point
137 */
139 const std::vector<mrpt::utils::TPixelCoordf> &srcDistortedPixels,
140 std::vector<mrpt::utils::TPixelCoordf> &dstUndistortedPixels,
141 const mrpt::math::CMatrixDouble33 & intrinsicParams,
142 const std::vector<double> & distortionParams );
143
144 /** Undistort a list of points given by their pixel coordinates, provided the camera matrix and distortion coefficients.
145 * \param srcDistortedPixels [IN] The pixel coordinates as in the distorted image.
146 * \param dstUndistortedPixels [OUT] The computed pixel coordinates without distortion.
147 * \param cameraModel [IN] The camera parameters.
148 * \sa undistort_point
149 */
151 const std::vector<mrpt::utils::TPixelCoordf> &srcDistortedPixels,
152 std::vector<mrpt::utils::TPixelCoordf> &dstUndistortedPixels,
153 const mrpt::utils::TCamera &cameraModel);
154
155 /** Undistort one point given by its pixel coordinates and the camera parameters.
156 * \sa undistort_points
157 */
159 const mrpt::utils::TPixelCoordf &inPt,
161 const mrpt::utils::TCamera &cameraModel);
162
163 /** @} */ // end of grouping
164 }
165 }
166}
167
168#endif
A numeric matrix of compile-time fixed size.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:73
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 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 .
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,...
Definition: CPose3DQuat.h:42
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:32
double cx() const
Get the value of the principal point x-coordinate (in pixels).
Definition: TCamera.h:154
double fx() const
Get the value of the focal length x-value (in pixels).
Definition: TCamera.h:158
double cy() const
Get the value of the principal point y-coordinate (in pixels).
Definition: TCamera.h:156
double fy() const
Get the value of the focal length y-value (in pixels).
Definition: TCamera.h:160
void VISION_IMPEXP undistort_points(const std::vector< mrpt::utils::TPixelCoordf > &srcDistortedPixels, std::vector< mrpt::utils::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 undistort_point(const mrpt::utils::TPixelCoordf &inPt, mrpt::utils::TPixelCoordf &outPt, const mrpt::utils::TCamera &cameraModel)
Undistort one point given by its pixel coordinates and the camera parameters.
void VISION_IMPEXP projectPoint_with_distortion(const mrpt::math::TPoint3D &in_point_wrt_cam, const mrpt::utils::TCamera &in_cam_params, mrpt::utils::TPixelCoordf &out_projectedPoints, bool accept_points_behind=false)
Project one 3D point into a camera using its calibration matrix and distortion parameters (radial and...
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< mrpt::utils::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...
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< mrpt::utils::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...
mrpt::utils::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:52
#define ASSERT_(f)
Definition: mrpt_macros.h:261
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Lightweight 3D point.
double z
X,Y,Z coordinates.
A pair (x,y) of pixel coordinates (subpixel resolution).
Definition: TPixelCoord.h:22



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Wed Mar 22 08:20:48 UTC 2023