39 #ifndef VP_PIXEL_METER_CONVERSION_H
40 #define VP_PIXEL_METER_CONVERSION_H
42 #include <visp3/core/vpCameraParameters.h>
43 #include <visp3/core/vpException.h>
44 #include <visp3/core/vpImagePoint.h>
45 #include <visp3/core/vpMath.h>
47 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_CALIB3D) && defined(HAVE_OPENCV_IMGPROC)
48 #include <opencv2/calib3d/calib3d.hpp>
49 #include <opencv2/imgproc/imgproc.hpp>
71 double n02_p,
double &xc_m,
double &yc_m,
double &n20_m,
double &n11_m,
double &n02_m);
72 static void convertLine(
const vpCameraParameters &cam,
const double &rho_p,
const double &theta_p,
double &rho_m,
104 switch (cam.m_projModel) {
106 convertPointWithoutDistortion(cam, u, v, x, y);
109 convertPointWithDistortion(cam, u, v, x, y);
112 convertPointWithKannalaBrandtDistortion(cam, u, v, x, y);
115 std::cerr <<
"projection model not identified" << std::endl;
148 switch (cam.m_projModel) {
150 convertPointWithoutDistortion(cam, iP, x, y);
153 convertPointWithDistortion(cam, iP, x, y);
156 convertPointWithKannalaBrandtDistortion(cam, iP, x, y);
159 std::cerr <<
"projection model not identified" << std::endl;
163 #ifndef DOXYGEN_SHOULD_SKIP_THIS
176 inline static void convertPointWithoutDistortion(
const vpCameraParameters &cam,
const double &u,
const double &v,
177 double &x,
double &y)
179 x = (u - cam.m_u0) * cam.m_inv_px;
180 y = (v - cam.m_v0) * cam.m_inv_py;
201 x = (iP.
get_u() - cam.m_u0) * cam.m_inv_px;
202 y = (iP.
get_v() - cam.m_v0) * cam.m_inv_py;
219 inline static void convertPointWithDistortion(
const vpCameraParameters &cam,
const double &u,
const double &v,
220 double &x,
double &y)
222 double r2 = 1. + (cam.m_kdu * (
vpMath::sqr((u - cam.m_u0) * cam.m_inv_px) +
vpMath::sqr((v - cam.m_v0) * cam.m_inv_py)));
223 x = (u - cam.m_u0) * r2 * cam.m_inv_px;
224 y = (v - cam.m_v0) * r2 * cam.m_inv_py;
246 double r2 = 1. + (cam.m_kdu * (
vpMath::sqr((iP.
get_u() - cam.m_u0) * cam.m_inv_px) +
248 x = (iP.
get_u() - cam.m_u0) * r2 * cam.m_inv_px;
249 y = (iP.
get_v() - cam.m_v0) * r2 * cam.m_inv_py;
272 inline static void convertPointWithKannalaBrandtDistortion(
const vpCameraParameters &cam,
const double &u,
273 const double &v,
double &x,
double &y)
275 double x_d = (u - cam.m_u0) / cam.m_px, y_d = (v - cam.m_v0) / cam.m_py;
278 const unsigned int index_0 = 0;
279 const unsigned int index_1 = 1;
280 const unsigned int index_2 = 2;
281 const unsigned int index_3 = 3;
282 const unsigned int val_1 = 1;
283 const unsigned int val_3 = 3;
284 const unsigned int val_5 = 5;
285 const unsigned int val_7 = 7;
286 const unsigned int val_9 = 9;
287 const unsigned int val_10 = 10;
289 r_d = std::min<double>(std::max<double>(-M_PI, r_d), M_PI);
293 const double EPS = 1e-8;
299 for (
unsigned int j = 0; j < val_10; ++j) {
300 double theta2 = theta * theta;
301 double theta4 = theta2 * theta2;
302 double theta6 = theta4 * theta2;
303 double theta8 = theta6 * theta2;
304 double k0_theta2 = k[index_0] * theta2;
305 double k1_theta4 = k[index_1] * theta4;
306 double k2_theta6 = k[index_2] * theta6,
307 k3_theta8 = k[index_3] * theta8;
311 double theta_fix = ((theta * (val_1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8)) - r_d)
312 / (val_1 + (val_3 * k0_theta2) + (val_5 * k1_theta4) + (val_7 * k2_theta6) + (val_9 * k3_theta8));
313 theta = theta - theta_fix;
314 if (fabs(theta_fix) < EPS) {
319 scale = std::tan(theta) / r_d;
346 double &x,
double &y)
348 double x_d = (iP.
get_u() - cam.m_u0) / cam.m_px, y_d = (iP.
get_v() - cam.m_v0) / cam.m_py;
351 const unsigned int index_0 = 0;
352 const unsigned int index_1 = 1;
353 const unsigned int index_2 = 2;
354 const unsigned int index_3 = 3;
355 const unsigned int val_1 = 1;
356 const unsigned int val_3 = 3;
357 const unsigned int val_5 = 5;
358 const unsigned int val_7 = 7;
359 const unsigned int val_9 = 9;
360 const unsigned int val_10 = 10;
362 r_d = std::min<double>(std::max<double>(-M_PI, r_d), M_PI);
366 const double EPS = 1e-8;
372 for (
unsigned int j = 0; j < val_10; ++j) {
373 double theta2 = theta * theta;
374 double theta4 = theta2 * theta2;
375 double theta6 = theta4 * theta2;
376 double theta8 = theta6 * theta2;
377 double k0_theta2 = k[index_0] * theta2;
378 double k1_theta4 = k[index_1] * theta4;
379 double k2_theta6 = k[index_2] * theta6;
380 double k3_theta8 = k[index_3] * theta8;
384 double theta_fix = ((theta * (val_1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8)) - r_d) /
385 (val_1 + (val_3 * k0_theta2) + (val_5 * k1_theta4) + (val_7 * k2_theta6) + (val_9 * k3_theta8));
386 theta = theta - theta_fix;
387 if (fabs(theta_fix) < EPS) {
392 scale = std::tan(theta) / r_d;
401 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_CALIB3D) && defined(HAVE_OPENCV_IMGPROC)
404 static void convertEllipse(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
const vpImagePoint ¢er_p,
405 double n20_p,
double n11_p,
double n02_p,
double &xc_m,
double &yc_m,
double &n20_m,
406 double &n11_m,
double &n02_m);
407 static void convertLine(
const cv::Mat &cameraMatrix,
const double &rho_p,
const double &theta_p,
double &rho_m,
409 static void convertMoment(
const cv::Mat &cameraMatrix,
unsigned int order,
const vpMatrix &moment_pixel,
411 static void convertPoint(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
const double &u,
const double &v,
412 double &x,
double &y);
413 static void convertPoint(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
const vpImagePoint &iP,
double &x,
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 2D point in an image. This class is useful for image processing and stores only ...
static double sqr(double x)
Implementation of a matrix and operations on matrices.
static void convertPoint(const vpCameraParameters &cam, const vpImagePoint &iP, double &x, double &y)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)