40 #ifndef vpMeterPixelConversion_H
41 #define vpMeterPixelConversion_H
49 #include <visp3/core/vpCameraParameters.h>
50 #include <visp3/core/vpCircle.h>
51 #include <visp3/core/vpException.h>
52 #include <visp3/core/vpImagePoint.h>
53 #include <visp3/core/vpMath.h>
54 #include <visp3/core/vpSphere.h>
56 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
57 #include <opencv2/calib3d/calib3d.hpp>
78 double &n20_p,
double &n11_p,
double &n02_p);
80 double &n20_p,
double &n11_p,
double &n02_p);
81 static void convertEllipse(
const vpCameraParameters &cam,
double xc_m,
double yc_m,
double n20_m,
double n11_m,
82 double n02_m,
vpImagePoint ¢er_p,
double &n20_p,
double &n11_p,
double &n02_p);
83 static void convertLine(
const vpCameraParameters &cam,
const double &rho_m,
const double &theta_m,
double &rho_p,
113 switch (cam.projModel) {
115 convertPointWithoutDistortion(cam, x, y, u, v);
118 convertPointWithDistortion(cam, x, y, u, v);
121 convertPointWithKannalaBrandtDistortion(cam, x, y, u, v);
155 switch (cam.projModel) {
157 convertPointWithoutDistortion(cam, x, y, iP);
160 convertPointWithDistortion(cam, x, y, iP);
163 convertPointWithKannalaBrandtDistortion(cam, x, y, iP);
168 #ifndef DOXYGEN_SHOULD_SKIP_THIS
178 inline static void convertPointWithoutDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
179 double &u,
double &v)
181 u = x * cam.px + cam.u0;
182 v = y * cam.py + cam.v0;
195 inline static void convertPointWithoutDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
198 iP.
set_u(x * cam.px + cam.u0);
199 iP.
set_v(y * cam.py + cam.v0);
218 inline static void convertPointWithDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
219 double &u,
double &v)
221 double r2 = 1. + cam.kud * (x * x + y * y);
222 u = cam.u0 + cam.px * x * r2;
223 v = cam.v0 + cam.py * y * r2;
242 inline static void convertPointWithDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
245 double r2 = 1. + cam.kud * (x * x + y * y);
246 iP.
set_u(cam.u0 + cam.px * x * r2);
247 iP.
set_v(cam.v0 + cam.py * y * r2);
272 inline static void convertPointWithKannalaBrandtDistortion(
const vpCameraParameters &cam,
const double &x,
273 const double &y,
double &u,
double &v)
276 double theta = atan(r);
280 double theta2 = theta * theta, theta3 = theta2 * theta, theta4 = theta2 * theta2, theta5 = theta4 * theta,
281 theta6 = theta3 * theta3, theta7 = theta6 * theta, theta8 = theta4 * theta4, theta9 = theta8 * theta;
283 double r_d = theta + k[0] * theta3 + k[1] * theta5 + k[2] * theta7 + k[3] * theta9;
285 double scale = (std::fabs(r) < std::numeric_limits<double>::epsilon()) ? 1.0 : r_d / r;
287 double x_d = x * scale;
288 double y_d = y * scale;
290 u = cam.px * x_d + cam.u0;
291 v = cam.py * y_d + cam.v0;
315 inline static void convertPointWithKannalaBrandtDistortion(
const vpCameraParameters &cam,
const double &x,
319 double theta = atan(r);
323 double theta2 = theta * theta, theta3 = theta2 * theta, theta4 = theta2 * theta2, theta5 = theta4 * theta,
324 theta6 = theta3 * theta3, theta7 = theta6 * theta, theta8 = theta4 * theta4, theta9 = theta8 * theta;
326 double r_d = theta + k[0] * theta3 + k[1] * theta5 + k[2] * theta7 + k[3] * theta9;
328 double scale = (std::fabs(r) < std::numeric_limits<double>::epsilon()) ? 1.0 : r_d / r;
330 double x_d = x * scale;
331 double y_d = y * scale;
333 iP.
set_u(cam.px * x_d + cam.u0);
334 iP.
set_v(cam.py * y_d + cam.v0);
340 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
343 static void convertEllipse(
const cv::Mat &cameraMatrix,
const vpCircle &circle,
vpImagePoint ¢er,
double &n20_p,
344 double &n11_p,
double &n02_p);
345 static void convertEllipse(
const cv::Mat &cameraMatrix,
const vpSphere &sphere,
vpImagePoint ¢er,
double &n20_p,
346 double &n11_p,
double &n02_p);
347 static void convertEllipse(
const cv::Mat &cameraMatrix,
double xc_m,
double yc_m,
double n20_m,
double n11_m,
348 double n02_m,
vpImagePoint ¢er_p,
double &n20_p,
double &n11_p,
double &n02_p);
349 static void convertLine(
const cv::Mat &cameraMatrix,
const double &rho_m,
const double &theta_m,
double &rho_p,
351 static void convertPoint(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
const double &x,
const double &y,
352 double &u,
double &v);
353 static void convertPoint(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
const double &x,
const double &y,
Generic class defining intrinsic camera parameters.
std::vector< double > getKannalaBrandtDistortionCoefficients() const
@ perspectiveProjWithDistortion
@ ProjWithKannalaBrandtDistortion
@ perspectiveProjWithoutDistortion
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static double sqr(double x)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, vpImagePoint &iP)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...