30 const double Cx =
cam.
cx();
31 const double Cy =
cam.
cy();
32 const double k1 =
cam.
k1();
33 const double k2 =
cam.
k2();
36 const double dy = 1.0 /
cam.
fy();
38 double xd = (
p.x - Cx) * dx;
39 double yd = (
p.y - Cy) * dy;
40 double rd2 = xd * xd + yd * yd;
41 double rd4 = rd2 * rd2;
43 J_undist.setSize(2, 2);
45 (1 + k1 * rd2 + k2 * rd4) +
46 (
p.x - Cx) * (k1 + 2 * k2 * rd2) * (2 * (
p.x - Cx) * dx * dx);
48 (1 + k1 * rd2 + k2 * rd4) +
49 (
p.y - Cy) * (k1 + 2 * k2 * rd2) * (2 * (
p.y - Cy) * dy * dy);
51 (
p.x - Cx) * (k1 + 2 * k2 * rd2) * (2 * (
p.y - Cy) * dy * dy);
53 (
p.y - Cy) * (k1 + 2 * k2 * rd2) * (2 * (
p.x - Cx) * dx * dx);
61 const double dx =
p.x -
cam.
cx();
62 const double dy =
p.y -
cam.
cy();
64 const double inv_f_15 = 1.0 / pow(f, 1.5);
74 J_undistor(0, 0) = (1 - 2 *
cam.
k1() *
square(dy)) * inv_f_15;
75 J_undistor(0, 1) = J_undistor(1, 0) = (2 *
cam.
k1() * dx * dy) * inv_f_15;
76 J_undistor(1, 1) = (1 - 2 *
cam.
k1() *
square(dx)) * inv_f_15;
111 const double dx = (
p.x -
cam.
cx());
114 const double dy = (
p.y -
cam.
cy());
118 const double fact = 1.0 / sqrt(1 + 2 *
cam.
k1() * r2);
120 distorted_p.
x =
cam.
cx() + dx * fact;
121 distorted_p.
y =
cam.
cy() + dy * fact;
129 std::vector<TPixelCoordf> in_p(1), out_p;
136 undistorted_p = out_p[0];
162 const double dx = (p3D.
x / p3D.
z) *
cam.
fx();
163 const double dy = (p3D.
y / p3D.
z) *
cam.
fy();
169 1.0 / sqrt(1 + 2 *
cam.
k1() * r2);
171 distorted_p.
x =
cam.
cx() + dx * fact;
172 distorted_p.
y =
cam.
cy() + dy * fact;
185 const double dx = distorted_p.
x -
cam.
cx();
186 const double dy = distorted_p.
y -
cam.
cy();
188 double factor = 1.0 / sqrt(1 - 2 *
cam.
k1() * r2);
190 p3D.
x = dx * factor /
cam.
fx();
191 p3D.
y = dy * factor /
cam.
fy();
212 du_dy(0, 0) =
cam.
fx() / p3D.
z;
214 du_dy(1, 1) =
cam.
fy() / p3D.
z;
226 const double ux = (p3D.
x / p3D.
z) *
228 const double uy = (p3D.
y / p3D.
z) *
cam.
fy();
230 const double ux_sqr =
square(ux);
231 const double uy_sqr =
square(uy);
233 const double r2 = ux_sqr + uy_sqr;
235 const double f = 1 + 2 *
cam.
k1() * r2;
236 const double f1_2 = sqrt(f);
237 const double f3_2 = f1_2 * f;
242 dh_du *= -2 *
cam.
k1() / f3_2;
243 dh_du(0, 0) += (1 / f1_2);
244 dh_du(1, 1) += (1 / f1_2);
253 dh_dy.multiply(dh_du, du_dy);
268 dy_du(0, 0) = 1.0 /
cam.
fx();
269 dy_du(1, 1) = 1.0 /
cam.
fy();
273 const double dx =
p.x -
cam.
cx();
274 const double dy =
p.y -
cam.
cy();
277 double f = 1 - 2 *
cam.
k1() * radi2;
278 double f1_2 = sqrt(f);
279 double f3_2 = f1_2 * f;
290 du_dh *= 2 *
cam.
k1() / f3_2;
291 du_dh(0, 0) += (1 / f1_2);
292 du_dh(1, 1) += (1 / f1_2);
295 dy_dh.multiply(dy_du, du_dh);
305 double cx = 0.0f, cy = 0.0f, fx = 0.0f, fy = 0.0f;
321 ASSERT_(DD.size() == 4 || DD.size() == 5);
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string §ion) override
This method load the options from a ".ini"-like file or memory-stored string list.
double fx() const
Get the value of the focal length x-value (in pixels).
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 ...
double fy() const
Get the value of the focal length y-value (in pixels).
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
A pair (x,y) of pixel coordinates (subpixel resolution).
double k2() const
Get the value of the k2 distortion parameter.
T square(const T x)
Inline function for the square of a number.
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates) ...
#define ASSERT_(f)
Defines an assertion mechanism.
This class allows loading and storing values and vectors of different types from a configuration text...
This base provides a set of functions for maths stuff.
double cy() const
Get the value of the principal point y-coordinate (in pixels).
void setDistortionParamsVector(const mrpt::math::CMatrixDouble15 &distParVector)
Set the whole vector of distortion params of the camera.
void jacob_undistor_fm(const mrpt::img::TPixelCoordf &uvd, math::CMatrixDouble &J_undist)
Jacobian for undistortion the image coordinates.
Classes for computer vision, detectors, features, etc.
double x
X,Y,Z coordinates.
GLsizei const GLchar ** string
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void unproject_3D_point(const mrpt::img::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...
double cx() const
Get the value of the principal point x-coordinate (in pixels).
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::img::TCamera cam
The parameters of a camera.
void dumpToTextStream(std::ostream &out) const override
This method displays clearly all the contents of the structure in textual form, sending it to a CStre...
void jacob_undistor(const mrpt::img::TPixelCoordf &p, mrpt::math::CMatrixDouble &J_undist)
Calculate the image coordinates undistorted.
void undistort_points(const std::vector< mrpt::img::TPixelCoordf > &srcDistortedPixels, std::vector< mrpt::img::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 undistort_point(const mrpt::img::TPixelCoordf &p, mrpt::img::TPixelCoordf &undistorted_p)
Return the pixel position undistorted by the camera The input values 'col' and 'row' will be replace ...
void project_3D_point(const mrpt::math::TPoint3D &p3D, mrpt::img::TPixelCoordf &distorted_p) const
Return the (distorted) pixel position of a 3D point given in coordinates relative to the camera (+Z p...
void distort_a_point(const mrpt::img::TPixelCoordf &p, mrpt::img::TPixelCoordf &distorted_p)
Return the pixel position distorted by the camera.
GLsizei GLsizei GLchar * source
void jacobian_unproject_with_distortion(const mrpt::img::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_...
dynamic_vector< double > CVectorDouble
Column vector, like Eigen::MatrixXd, but automatically initialized to zeros since construction...
double k1() const
Get the value of the k1 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...
CCamModel()
Default Constructor.
#define MRPT_LOAD_HERE_CONFIG_VAR_NO_DEFAULT( variableName, variableType, targetVariable, configFileObject, sectionNameStr)
std::vector< double > getDistortionParamsAsVector() const
Get a vector with the distortion params of the camera.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.