34 #ifndef _vpMeterPixelConversion_h_
35 #define _vpMeterPixelConversion_h_
43 #include <visp3/core/vpCameraParameters.h>
44 #include <visp3/core/vpCircle.h>
45 #include <visp3/core/vpException.h>
46 #include <visp3/core/vpImagePoint.h>
47 #include <visp3/core/vpMath.h>
48 #include <visp3/core/vpSphere.h>
50 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_CALIB3D)
51 #include <opencv2/calib3d/calib3d.hpp>
72 double &n20_p,
double &n11_p,
double &n02_p);
74 double &n20_p,
double &n11_p,
double &n02_p);
75 static void convertEllipse(
const vpCameraParameters &cam,
double xc_m,
double yc_m,
double n20_m,
double n11_m,
76 double n02_m,
vpImagePoint ¢er_p,
double &n20_p,
double &n11_p,
double &n02_p);
77 static void convertLine(
const vpCameraParameters &cam,
const double &rho_m,
const double &theta_m,
double &rho_p,
107 switch (cam.projModel) {
109 convertPointWithoutDistortion(cam, x, y, u, v);
112 convertPointWithDistortion(cam, x, y, u, v);
115 convertPointWithKannalaBrandtDistortion(cam, x, y, u, v);
149 switch (cam.projModel) {
151 convertPointWithoutDistortion(cam, x, y, iP);
154 convertPointWithDistortion(cam, x, y, iP);
157 convertPointWithKannalaBrandtDistortion(cam, x, y, iP);
162 #ifndef DOXYGEN_SHOULD_SKIP_THIS
172 inline static void convertPointWithoutDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
173 double &u,
double &v)
175 u = x * cam.px + cam.u0;
176 v = y * cam.py + cam.v0;
189 inline static void convertPointWithoutDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
192 iP.
set_u(x * cam.px + cam.u0);
193 iP.
set_v(y * cam.py + cam.v0);
212 inline static void convertPointWithDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
213 double &u,
double &v)
215 double r2 = 1. + cam.kud * (x * x + y * y);
216 u = cam.u0 + cam.px * x * r2;
217 v = cam.v0 + cam.py * y * r2;
236 inline static void convertPointWithDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
239 double r2 = 1. + cam.kud * (x * x + y * y);
240 iP.
set_u(cam.u0 + cam.px * x * r2);
241 iP.
set_v(cam.v0 + cam.py * y * r2);
266 inline static void convertPointWithKannalaBrandtDistortion(
const vpCameraParameters &cam,
const double &x,
267 const double &y,
double &u,
double &v)
270 double theta = atan(r);
274 double theta2 = theta * theta, theta3 = theta2 * theta, theta4 = theta2 * theta2, theta5 = theta4 * theta,
275 theta6 = theta3 * theta3, theta7 = theta6 * theta, theta8 = theta4 * theta4, theta9 = theta8 * theta;
277 double r_d = theta + k[0] * theta3 + k[1] * theta5 + k[2] * theta7 + k[3] * theta9;
279 double scale = (std::fabs(r) < std::numeric_limits<double>::epsilon()) ? 1.0 : r_d / r;
281 double x_d = x * scale;
282 double y_d = y * scale;
284 u = cam.px * x_d + cam.u0;
285 v = cam.py * y_d + cam.v0;
309 inline static void convertPointWithKannalaBrandtDistortion(
const vpCameraParameters &cam,
const double &x,
313 double theta = atan(r);
317 double theta2 = theta * theta, theta3 = theta2 * theta, theta4 = theta2 * theta2, theta5 = theta4 * theta,
318 theta6 = theta3 * theta3, theta7 = theta6 * theta, theta8 = theta4 * theta4, theta9 = theta8 * theta;
320 double r_d = theta + k[0] * theta3 + k[1] * theta5 + k[2] * theta7 + k[3] * theta9;
322 double scale = (std::fabs(r) < std::numeric_limits<double>::epsilon()) ? 1.0 : r_d / r;
324 double x_d = x * scale;
325 double y_d = y * scale;
327 iP.
set_u(cam.px * x_d + cam.u0);
328 iP.
set_v(cam.py * y_d + cam.v0);
334 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_CALIB3D)
337 static void convertEllipse(
const cv::Mat &cameraMatrix,
const vpCircle &circle,
vpImagePoint ¢er,
double &n20_p,
338 double &n11_p,
double &n02_p);
339 static void convertEllipse(
const cv::Mat &cameraMatrix,
const vpSphere &sphere,
vpImagePoint ¢er,
double &n20_p,
340 double &n11_p,
double &n02_p);
341 static void convertEllipse(
const cv::Mat &cameraMatrix,
double xc_m,
double yc_m,
double n20_m,
double n11_m,
342 double n02_m,
vpImagePoint ¢er_p,
double &n20_p,
double &n11_p,
double &n02_p);
343 static void convertLine(
const cv::Mat &cameraMatrix,
const double &rho_m,
const double &theta_m,
double &rho_p,
345 static void convertPoint(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
const double &x,
const double &y,
346 double &u,
double &v);
347 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
Perspective projection with distortion model.
@ ProjWithKannalaBrandtDistortion
Projection with Kannala-Brandt distortion model.
@ perspectiveProjWithoutDistortion
Perspective projection without distortion model.
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...