40 #ifndef vpPixelMeterConversion_H
41 #define vpPixelMeterConversion_H
48 #include <visp3/core/vpCameraParameters.h>
49 #include <visp3/core/vpDebug.h>
50 #include <visp3/core/vpException.h>
51 #include <visp3/core/vpImagePoint.h>
52 #include <visp3/core/vpMath.h>
54 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
55 #include <opencv2/calib3d/calib3d.hpp>
56 #include <opencv2/imgproc/imgproc.hpp>
77 double n02_p,
double &xc_m,
double &yc_m,
double &n20_m,
double &n11_m,
double &n02_m);
78 static void convertLine(
const vpCameraParameters &cam,
const double &rho_p,
const double &theta_p,
double &rho_m,
110 switch (cam.projModel) {
112 convertPointWithoutDistortion(cam, u, v, x, y);
115 convertPointWithDistortion(cam, u, v, x, y);
118 convertPointWithKannalaBrandtDistortion(cam, u, v, x, y);
152 switch (cam.projModel) {
154 convertPointWithoutDistortion(cam, iP, x, y);
157 convertPointWithDistortion(cam, iP, x, y);
160 convertPointWithKannalaBrandtDistortion(cam, iP, x, y);
165 #ifndef DOXYGEN_SHOULD_SKIP_THIS
178 inline static void convertPointWithoutDistortion(
const vpCameraParameters &cam,
const double &u,
const double &v,
179 double &x,
double &y)
181 x = (u - cam.u0) * cam.inv_px;
182 y = (v - cam.v0) * cam.inv_py;
203 x = (iP.
get_u() - cam.u0) * cam.inv_px;
204 y = (iP.
get_v() - cam.v0) * cam.inv_py;
221 inline static void convertPointWithDistortion(
const vpCameraParameters &cam,
const double &u,
const double &v,
222 double &x,
double &y)
224 double r2 = 1. + cam.kdu * (
vpMath::sqr((u - cam.u0) * cam.inv_px) +
vpMath::sqr((v - cam.v0) * cam.inv_py));
225 x = (u - cam.u0) * r2 * cam.inv_px;
226 y = (v - cam.v0) * r2 * cam.inv_py;
248 double r2 = 1. + cam.kdu * (
vpMath::sqr((iP.
get_u() - cam.u0) * cam.inv_px) +
250 x = (iP.
get_u() - cam.u0) * r2 * cam.inv_px;
251 y = (iP.
get_v() - cam.v0) * r2 * cam.inv_py;
274 inline static void convertPointWithKannalaBrandtDistortion(
const vpCameraParameters &cam,
const double &u,
275 const double &v,
double &x,
double &y)
277 double x_d = (u - cam.u0) / cam.px, y_d = (v - cam.v0) / cam.py;
281 r_d = std::min(std::max(-M_PI, r_d), M_PI);
285 const double EPS = 1e-8;
291 for (
int j = 0; j < 10; j++) {
292 double theta2 = theta * theta, theta4 = theta2 * theta2, theta6 = theta4 * theta2, theta8 = theta6 * theta2;
293 double k0_theta2 = k[0] * theta2, k1_theta4 = k[1] * theta4, k2_theta6 = k[2] * theta6,
294 k3_theta8 = k[3] * theta8;
296 double theta_fix = (theta * (1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8) - r_d) /
297 (1 + 3 * k0_theta2 + 5 * k1_theta4 + 7 * k2_theta6 + 9 * k3_theta8);
298 theta = theta - theta_fix;
299 if (fabs(theta_fix) < EPS)
303 scale = std::tan(theta) / r_d;
330 double &x,
double &y)
332 double x_d = (iP.
get_u() - cam.u0) / cam.px, y_d = (iP.
get_v() - cam.v0) / cam.py;
336 r_d = std::min(std::max(-M_PI, r_d), M_PI);
340 const double EPS = 1e-8;
346 for (
int j = 0; j < 10; j++) {
347 double theta2 = theta * theta, theta4 = theta2 * theta2, theta6 = theta4 * theta2, theta8 = theta6 * theta2;
348 double k0_theta2 = k[0] * theta2, k1_theta4 = k[1] * theta4, k2_theta6 = k[2] * theta6,
349 k3_theta8 = k[3] * theta8;
351 double theta_fix = (theta * (1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8) - r_d) /
352 (1 + 3 * k0_theta2 + 5 * k1_theta4 + 7 * k2_theta6 + 9 * k3_theta8);
353 theta = theta - theta_fix;
354 if (fabs(theta_fix) < EPS)
358 scale = std::tan(theta) / r_d;
367 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
370 static void convertEllipse(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
const vpImagePoint ¢er_p,
371 double n20_p,
double n11_p,
double n02_p,
double &xc_m,
double &yc_m,
double &n20_m,
372 double &n11_m,
double &n02_m);
373 static void convertLine(
const cv::Mat &cameraMatrix,
const double &rho_p,
const double &theta_p,
double &rho_m,
375 static void convertMoment(
const cv::Mat &cameraMatrix,
unsigned int order,
const vpMatrix &moment_pixel,
377 static void convertPoint(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
const double &u,
const double &v,
378 double &x,
double &y);
379 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
@ ProjWithKannalaBrandtDistortion
@ perspectiveProjWithoutDistortion
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)