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/imgproc/imgproc.hpp> 56 # include <opencv2/calib3d/calib3d.hpp> 77 const vpImagePoint ¢er_p,
double n20_p,
double n11_p,
double n02_p,
78 double &xc_m,
double &yc_m,
double &n20_m,
double &n11_m,
double &n02_m);
79 static void convertLine(
const vpCameraParameters &cam,
const double &rho_p,
const double &theta_p,
double &rho_m,
110 const double &u,
const double &v,
double &x,
double &y)
112 switch (cam.projModel) {
114 convertPointWithoutDistortion(cam, u, v, x, y);
117 convertPointWithDistortion(cam, u, v, x, y);
120 convertPointWithKannalaBrandtDistortion(cam, u, v, x, y);
155 switch (cam.projModel) {
157 convertPointWithoutDistortion(cam, iP, x, y);
160 convertPointWithDistortion(cam, iP, x, y);
163 convertPointWithKannalaBrandtDistortion(cam, iP, x, y);
168 #ifndef DOXYGEN_SHOULD_SKIP_THIS 182 const double &u,
const double &v,
double &x,
double &y)
184 x = (u - cam.u0) * cam.inv_px;
185 y = (v - cam.v0) * cam.inv_py;
206 x = (iP.
get_u() - cam.u0) * cam.inv_px;
207 y = (iP.
get_v() - cam.v0) * cam.inv_py;
225 const double &u,
const double &v,
double &x,
double &y)
227 double r2 = 1. + cam.kdu * (
vpMath::sqr((u - cam.u0) * cam.inv_px) +
vpMath::sqr((v - cam.v0) * cam.inv_py));
228 x = (u - cam.u0) * r2 * cam.inv_px;
229 y = (v - cam.v0) * r2 * cam.inv_py;
251 double r2 = 1. + cam.kdu * (
vpMath::sqr((iP.
get_u() - cam.u0) * cam.inv_px) +
253 x = (iP.
get_u() - cam.u0) * r2 * cam.inv_px;
254 y = (iP.
get_v() - cam.v0) * r2 * cam.inv_py;
277 inline static void convertPointWithKannalaBrandtDistortion(
const vpCameraParameters &cam,
const double &u,
278 const double &v,
double &x,
double &y)
280 double x_d = (u - cam.u0) / cam.px, y_d = (v - cam.v0) / cam.py;
284 r_d = std::min(std::max(-M_PI, r_d), M_PI);
288 const double EPS = 1e-8;
295 for (
int j = 0; j < 10; j++)
297 double theta2 = theta*theta, theta4 = theta2*theta2, theta6 = theta4*theta2, theta8 = theta6*theta2;
298 double k0_theta2 = k[0] * theta2, k1_theta4 = k[1] * theta4, k2_theta6 = k[2] * theta6, k3_theta8 = k[3] * theta8;
300 double theta_fix = (theta * (1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8) - r_d) /
301 (1 + 3*k0_theta2 + 5*k1_theta4 + 7*k2_theta6 + 9*k3_theta8);
302 theta = theta - theta_fix;
303 if (fabs(theta_fix) < EPS)
307 scale = std::tan(theta) / r_d;
334 double &x,
double &y)
336 double x_d = (iP.
get_u() - cam.u0) / cam.px, y_d = (iP.
get_v() - cam.v0) / cam.py;
340 r_d = std::min(std::max(-M_PI, r_d), M_PI);
344 const double EPS = 1e-8;
351 for (
int j = 0; j < 10; j++)
353 double theta2 = theta*theta, theta4 = theta2*theta2, theta6 = theta4*theta2, theta8 = theta6*theta2;
354 double k0_theta2 = k[0] * theta2, k1_theta4 = k[1] * theta4, k2_theta6 = k[2] * theta6, k3_theta8 = k[3] * theta8;
356 double theta_fix = (theta * (1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8) - r_d) /
357 (1 + 3*k0_theta2 + 5*k1_theta4 + 7*k2_theta6 + 9*k3_theta8);
358 theta = theta - theta_fix;
359 if (fabs(theta_fix) < EPS)
363 scale = std::tan(theta) / r_d;
369 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS 372 #if VISP_HAVE_OPENCV_VERSION >= 0x020300 375 static void convertEllipse(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
376 const vpImagePoint ¢er_p,
double n20_p,
double n11_p,
double n02_p,
377 double &xc_m,
double &yc_m,
double &n20_m,
double &n11_m,
double &n02_m);
378 static void convertLine(
const cv::Mat &cameraMatrix,
379 const double &rho_p,
const double &theta_p,
380 double &rho_m,
double &theta_m);
381 static void convertMoment(
const cv::Mat &cameraMatrix,
382 unsigned int order,
const vpMatrix &moment_pixel,
384 static void convertPoint(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
385 const double &u,
const double &v,
double &x,
double &y);
386 static void convertPoint(
const cv::Mat &cameraMatrix,
const cv::Mat &distCoeffs,
Implementation of a matrix and operations on matrices.
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
static double sqr(double x)
Generic class defining intrinsic camera parameters.
std::vector< double > getKannalaBrandtDistortionCoefficients() const
static void convertPoint(const vpCameraParameters &cam, const vpImagePoint &iP, double &x, double &y)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...