39 #ifndef VP_METER_PIXEL_CONVERSION_H
40 #define VP_METER_PIXEL_CONVERSION_H
42 #include <visp3/core/vpCameraParameters.h>
43 #include <visp3/core/vpCircle.h>
44 #include <visp3/core/vpException.h>
45 #include <visp3/core/vpImagePoint.h>
46 #include <visp3/core/vpMath.h>
47 #include <visp3/core/vpSphere.h>
49 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_CALIB3D)
50 #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.m_projModel) {
109 convertPointWithoutDistortion(cam, x, y, u, v);
112 convertPointWithDistortion(cam, x, y, u, v);
115 convertPointWithKannalaBrandtDistortion(cam, x, y, u, v);
118 std::cerr <<
"projection model not identified" << std::endl;
151 switch (cam.m_projModel) {
153 convertPointWithoutDistortion(cam, x, y, iP);
156 convertPointWithDistortion(cam, x, y, iP);
159 convertPointWithKannalaBrandtDistortion(cam, x, y, iP);
162 std::cerr <<
"projection model not identified" << std::endl;
166 #ifndef DOXYGEN_SHOULD_SKIP_THIS
176 inline static void convertPointWithoutDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
177 double &u,
double &v)
179 u = (x * cam.m_px) + cam.m_u0;
180 v = (y * cam.m_py) + cam.m_v0;
193 inline static void convertPointWithoutDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
196 iP.
set_u((x * cam.m_px) + cam.m_u0);
197 iP.
set_v((y * cam.m_py) + cam.m_v0);
216 inline static void convertPointWithDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
217 double &u,
double &v)
219 double r2 = 1. + (cam.m_kud * ((x * x) + (y * y)));
220 u = cam.m_u0 + (cam.m_px * x * r2);
221 v = cam.m_v0 + (cam.m_py * y * r2);
240 inline static void convertPointWithDistortion(
const vpCameraParameters &cam,
const double &x,
const double &y,
243 double r2 = 1. + (cam.m_kud * ((x * x) + (y * y)));
244 iP.
set_u(cam.m_u0 + (cam.m_px * x * r2));
245 iP.
set_v(cam.m_v0 + (cam.m_py * y * r2));
270 inline static void convertPointWithKannalaBrandtDistortion(
const vpCameraParameters &cam,
const double &x,
271 const double &y,
double &u,
double &v)
274 double theta = atan(r);
275 const unsigned int index_0 = 0;
276 const unsigned int index_1 = 1;
277 const unsigned int index_2 = 2;
278 const unsigned int index_3 = 3;
282 double theta2 = theta * theta, theta3 = theta2 * theta, theta4 = theta2 * theta2, theta5 = theta4 * theta,
283 theta6 = theta3 * theta3, theta7 = theta6 * theta, theta8 = theta4 * theta4, theta9 = theta8 * theta;
285 double r_d = theta + (k[index_0] * theta3) + (k[index_1] * theta5) + (k[index_2] * theta7) + (k[index_3] * theta9);
287 double scale = (std::fabs(r) < std::numeric_limits<double>::epsilon()) ? 1.0 : (r_d / r);
289 double x_d = x * scale;
290 double y_d = y * scale;
292 u = (cam.m_px * x_d) + cam.m_u0;
293 v = (cam.m_py * y_d) + cam.m_v0;
317 inline static void convertPointWithKannalaBrandtDistortion(
const vpCameraParameters &cam,
const double &x,
321 double theta = atan(r);
322 const unsigned int index_0 = 0;
323 const unsigned int index_1 = 1;
324 const unsigned int index_2 = 2;
325 const unsigned int index_3 = 3;
329 double theta2 = theta * theta, theta3 = theta2 * theta, theta4 = theta2 * theta2, theta5 = theta4 * theta,
330 theta6 = theta3 * theta3, theta7 = theta6 * theta, theta8 = theta4 * theta4, theta9 = theta8 * theta;
332 double r_d = theta + (k[index_0] * theta3) + (k[index_1] * theta5) + (k[index_2] * theta7) + (k[index_3] * theta9);
334 double scale = (std::fabs(r) < std::numeric_limits<double>::epsilon()) ? 1.0 : (r_d / r);
336 double x_d = x * scale;
337 double y_d = y * scale;
339 iP.
set_u((cam.m_px * x_d) + cam.m_u0);
340 iP.
set_v((cam.m_py * y_d) + cam.m_v0);
346 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_CALIB3D)
349 static void convertEllipse(
const cv::Mat &cameraMatrix,
const vpCircle &circle,
vpImagePoint ¢er,
double &n20_p,
350 double &n11_p,
double &n02_p);
351 static void convertEllipse(
const cv::Mat &cameraMatrix,
const vpSphere &sphere,
vpImagePoint ¢er,
double &n20_p,
352 double &n11_p,
double &n02_p);
353 static void convertEllipse(
const cv::Mat &cameraMatrix,
double xc_m,
double yc_m,
double n20_m,
double n11_m,
354 double n02_m,
vpImagePoint ¢er_p,
double &n20_p,
double &n11_p,
double &n02_p);
355 static void convertLine(
const cv::Mat &cameraMatrix,
const double &rho_m,
const double &theta_m,
double &rho_p,
357 static void convertPoint(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
const double &x,
const double &y,
358 double &u,
double &v);
359 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...