32 const double Cx =
cam.
cx();
33 const double Cy =
cam.
cy();
34 const double k1 =
cam.
k1();
35 const double k2 =
cam.
k2();
36 const double dx = 1.0 /
cam.
fx();
37 const double dy = 1.0 /
cam.
fy();
39 double xd = (
p.x-Cx)*dx;
40 double yd = (
p.y-Cy)*dy;
41 double rd2=xd*xd+yd*yd;
44 J_undist.setSize(2,2);
45 J_undist(0,0) = (1+k1*rd2+k2*rd4) + (
p.x-Cx) * (k1+2*k2*rd2) * (2*(
p.x-Cx)*dx*dx);
46 J_undist(1,1) = (1+k1*rd2+k2*rd4) + (
p.y-Cy) * (k1+2*k2*rd2) * (2*(
p.y-Cy)*dy*dy);
47 J_undist(0,1) = (
p.x-Cx) * (k1+2*k2*rd2) * (2*(
p.y-Cy)*dy*dy);
48 J_undist(1,0) = (
p.y-Cy) * (k1+2*k2*rd2) * (2*(
p.x-Cx)*dx*dx);
57 const double dx =
p.x-
cam.
cx();
58 const double dy =
p.y-
cam.
cy();
60 const double inv_f_15 = 1.0/pow(f,1.5);
70 J_undistor(0,0) = ( 1 - 2*
cam.
k1()*
square(dy) ) * inv_f_15;
72 J_undistor(1,0) = ( 2*
cam.
k1()*dx*dy ) * inv_f_15;
73 J_undistor(1,1) = ( 1 - 2*
cam.
k1()*
square(dx) ) * inv_f_15;
108 const double dx = (
p.x-
cam.
cx());
109 const double dy = (
p.y-
cam.
cy());
113 const double fact = 1.0/sqrt(1+2*
cam.
k1()*r2);
115 distorted_p.
x =
cam.
cx() + dx*fact;
116 distorted_p.
y =
cam.
cy() + dy*fact;
123 std::vector<TPixelCoordf> in_p(1), out_p;
134 undistorted_p = out_p[0];
158 const double dx = (p3D.
x / p3D.
z)*
cam.
fx();
159 const double dy = (p3D.
y / p3D.
z)*
cam.
fy();
164 const double fact = 1.0/sqrt(1+2*
cam.
k1()*r2);
166 distorted_p.
x =
cam.
cx() + dx*fact;
167 distorted_p.
y =
cam.
cy() + dy*fact;
178 const double dx = distorted_p.
x -
cam.
cx();
179 const double dy = distorted_p.
y -
cam.
cy();
181 double factor = 1.0/sqrt(1 - 2*
cam.
k1()*r2);
183 p3D.
x = dx * factor /
cam.
fx();
184 p3D.
y = dy * factor /
cam.
fy();
216 const double ux = (p3D.
x / p3D.
z)*
cam.
fx();
217 const double uy = (p3D.
y / p3D.
z)*
cam.
fy();
219 const double ux_sqr =
square(ux);
220 const double uy_sqr =
square(uy);
222 const double r2 = ux_sqr + uy_sqr;
224 const double f = 1+2*
cam.
k1()*r2;
225 const double f1_2 = sqrt(f);
226 const double f3_2 = f1_2 * f;
231 dh_du *= -2 *
cam.
k1() / f3_2;
232 dh_du(0,0) += (1/f1_2);
233 dh_du(1,1) += (1/f1_2);
242 dh_dy.multiply( dh_du, du_dy );
253 dy_du(0,0) = 1.0/
cam.
fx();
254 dy_du(1,1) = 1.0/
cam.
fy();
258 const double dx =
p.x-
cam.
cx();
259 const double dy =
p.y-
cam.
cy();
262 double f = 1 - 2 *
cam.
k1() * radi2;
263 double f1_2 = sqrt(f);
264 double f3_2 = f1_2 * f;
275 du_dh *= 2 *
cam.
k1() / f3_2;
276 du_dh(0,0) += (1/f1_2);
277 du_dh(1,1) += (1/f1_2);
280 dy_dh.multiply( dy_du, du_dh );
291 double cx = 0.0f, cy = 0.0f, fx = 0.0f, fy = 0.0f;
305 ASSERT_( DD.size()==4 || DD.size()==5 )
#define MRPT_LOAD_HERE_CONFIG_VAR_NO_DEFAULT(variableName, variableType, targetVariable, configFileObject, sectionNameStr)
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
This class allows loading and storing values and vectors of different types from a configuration text...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
void setDistortionParamsVector(const mrpt::math::CMatrixDouble15 &distParVector)
Set the whole vector of distortion params of the camera.
std::vector< double > getDistortionParamsAsVector() const
Get a vector with the distortion params of the camera
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates)
double cx() const
Get the value of the principal point x-coordinate (in pixels).
double fx() const
Get the value of the focal length x-value (in pixels).
double cy() const
Get the value of the principal point y-coordinate (in pixels).
double fy() const
Get the value of the focal length y-value (in pixels).
double k1() const
Get the value of the k1 distortion parameter.
double k2() const
Get the value of the k2 distortion parameter.
void setIntrinsicParamsFromValues(double fx, double fy, double cx, double cy)
Set the matrix of intrinsic params of the camera from the individual values of focal length and princ...
void project_3D_point(const mrpt::math::TPoint3D &p3D, mrpt::utils::TPixelCoordf &distorted_p) const
Return the (distorted) pixel position of a 3D point given in coordinates relative to the camera (+Z p...
void jacob_undistor(const mrpt::utils::TPixelCoordf &p, mrpt::math::CMatrixDouble &J_undist)
Calculate the image coordinates undistorted.
void distort_a_point(const mrpt::utils::TPixelCoordf &p, mrpt::utils::TPixelCoordf &distorted_p)
Return the pixel position distorted by the camera.
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string §ion) MRPT_OVERRIDE
This method load the options from a ".ini"-like file or memory-stored string list.
void unproject_3D_point(const mrpt::utils::TPixelCoordf &distorted_p, mrpt::math::TPoint3D &p3D) const
Return the 3D location of a point (at a fixed distance z=1), for the given (distorted) pixel position...
mrpt::utils::TCamera cam
The parameters of a camera.
CCamModel()
Default Constructor.
void jacobian_unproject_with_distortion(const mrpt::utils::TPixelCoordf &p, math::CMatrixDouble &dy_dh) const
Jacobian of the unprojection of a pixel (with distortion) back into a 3D point, as done in unproject_...
void dumpToTextStream(mrpt::utils::CStream &out) const MRPT_OVERRIDE
This method displays clearly all the contents of the structure in textual form, sending it to a CStre...
void undistort_point(const mrpt::utils::TPixelCoordf &p, mrpt::utils::TPixelCoordf &undistorted_p)
Return the pixel position undistorted by the camera The input values 'col' and 'row' will be replace ...
void jacob_undistor_fm(const mrpt::utils::TPixelCoordf &uvd, math::CMatrixDouble &J_undist)
Jacobian for undistortion the image coordinates.
void jacobian_project_with_distortion(const mrpt::math::TPoint3D &p3D, math::CMatrixDouble &dh_dy) const
Jacobian of the projection of 3D points (with distortion), as done in project_3D_point ,...
GLsizei const GLchar ** string
GLsizei GLsizei GLchar * source
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...
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
This base provides a set of functions for maths stuff.
dynamic_vector< double > CVectorDouble
Column vector, like Eigen::MatrixXd, but automatically initialized to zeros since construction.
T square(const T x)
Inline function for the square of a number.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
Classes for computer vision, detectors, features, etc.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double z
X,Y,Z coordinates.
A pair (x,y) of pixel coordinates (subpixel resolution).