38#include <visp3/core/vpCameraParameters.h>
39#include <visp3/core/vpException.h>
40#include <visp3/core/vpMath.h>
41#include <visp3/core/vpPixelMeterConversion.h>
43#if defined(HAVE_OPENCV_IMGPROC) && \
44 (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_CALIB3D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_CALIB) && defined(HAVE_OPENCV_3D)))
46#if (VISP_HAVE_OPENCV_VERSION < 0x050000)
47#include <opencv2/calib3d/calib3d.hpp>
50#if (VISP_HAVE_OPENCV_VERSION >= 0x050000)
51#include <opencv2/calib.hpp>
52#include <opencv2/3d.hpp>
55#include <opencv2/imgproc/imgproc.hpp>
75 double n11_p,
double n02_p,
double &xc_m,
double &yc_m,
double &n20_m,
76 double &n11_m,
double &n02_m)
79 double px = cam.get_px();
80 double py = cam.get_py();
82 n20_m = n20_p / (px * px);
83 n11_m = n11_p / (px * py);
84 n02_m = n02_p / (py * py);
99 double &rho_m,
double &theta_m)
101 double co = cos(theta_p);
102 double si = sin(theta_p);
105 if (fabs(d) < 1e-6) {
108 theta_m = atan2(si * cam.m_py, co * cam.m_px);
109 rho_m = (rho_p - (cam.m_u0 * co) - (cam.m_v0 * si)) / sqrt(d);
153 double yc = -cam.m_v0;
154 double xc = -cam.m_u0;
156 for (
unsigned int k = 0; k < order; ++k) {
157 for (
unsigned int p = 0; p < order; ++p) {
158 for (
unsigned int q = 0; q < order; ++q) {
161 for (
unsigned int r = 0; r <= p; ++r) {
162 for (
unsigned int t = 0; t <= q; ++t) {
164 pow(xc,
static_cast<int>(p - r)) * pow(yc,
static_cast<int>(q - t)) * moment_pixel[r][t];
172 for (
unsigned int k = 0; k < order; ++k) {
173 for (
unsigned int p = 0; p < order; ++p) {
174 for (
unsigned int q = 0; q < order; ++q) {
176 m[p][q] *= pow(cam.m_inv_px,
static_cast<int>(1 + p)) * pow(cam.m_inv_py,
static_cast<int>(1 + q));
182 for (
unsigned int k = 0; k < order; ++k) {
183 for (
unsigned int p = 0; p < order; ++p) {
184 for (
unsigned int q = 0; q < order; ++q) {
186 moment_meter[p][q] = m[p][q];
193#if defined(HAVE_OPENCV_IMGPROC) && \
194 (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_CALIB3D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_CALIB) && defined(HAVE_OPENCV_3D)))
214 const vpImagePoint ¢er_p,
double n20_p,
double n11_p,
double n02_p,
215 double &xc_m,
double &yc_m,
double &n20_m,
double &n11_m,
double &n02_m)
218 double px = cameraMatrix.at<
double>(0, 0);
219 double py = cameraMatrix.at<
double>(1, 1);
221 n20_m = n20_p / (px * px);
222 n11_m = n11_p / (px * py);
223 n02_m = n02_p / (py * py);
238 double &rho_m,
double &theta_m)
240 double co = cos(theta_p);
241 double si = sin(theta_p);
242 double px = cameraMatrix.at<
double>(0, 0);
243 double py = cameraMatrix.at<
double>(1, 1);
244 double u0 = cameraMatrix.at<
double>(0, 2);
245 double v0 = cameraMatrix.at<
double>(1, 2);
249 if (fabs(d) < 1e-6) {
252 theta_m = atan2(si * py, co * px);
253 rho_m = (rho_p - u0 * co - v0 * si) / sqrt(d);
269 double inv_px = 1. / cameraMatrix.at<
double>(0, 0);
270 double inv_py = 1. / cameraMatrix.at<
double>(1, 1);
271 double u0 = cameraMatrix.at<
double>(0, 2);
272 double v0 = cameraMatrix.at<
double>(1, 2);
278 for (
unsigned int k = 0; k < order; ++k) {
279 for (
unsigned int p = 0; p < order; ++p) {
280 for (
unsigned int q = 0; q < order; ++q) {
283 for (
unsigned int r = 0; r <= p; ++r) {
284 for (
unsigned int t = 0; t <= q; ++t) {
286 pow(xc,
static_cast<int>(p - r)) * pow(yc,
static_cast<int>(q - t)) * moment_pixel[r][t];
294 for (
unsigned int k = 0; k < order; ++k) {
295 for (
unsigned int p = 0; p < order; ++p) {
296 for (
unsigned int q = 0; q < order; ++q) {
298 m[p][q] *= pow(inv_px,
static_cast<int>(1 + p)) * pow(inv_py,
static_cast<int>(1 + q));
304 for (
unsigned int k = 0; k < order; ++k) {
305 for (
unsigned int p = 0; p < order; ++p) {
306 for (
unsigned int q = 0; q < order; ++q) {
308 moment_meter[p][q] = m[p][q];
330 const double &v,
double &x,
double &y)
332 std::vector<cv::Point2d> imagePoints_vec;
333 imagePoints_vec.push_back(cv::Point2d(u, v));
334 std::vector<cv::Point2d> objectPoints_vec;
335 cv::undistortPoints(imagePoints_vec, objectPoints_vec, cameraMatrix, distCoeffs);
336 x = objectPoints_vec[0].x;
337 y = objectPoints_vec[0].y;
356 std::vector<cv::Point2d> imagePoints_vec;
357 imagePoints_vec.push_back(cv::Point2d(iP.
get_u(), iP.
get_v()));
358 std::vector<cv::Point2d> objectPoints_vec;
359 cv::undistortPoints(imagePoints_vec, objectPoints_vec, cameraMatrix, distCoeffs);
360 x = objectPoints_vec[0].x;
361 y = objectPoints_vec[0].y;
Generic class defining intrinsic camera parameters.
error that can be emitted by ViSP classes.
@ divideByZeroError
Division by zero.
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 long double comb(unsigned int n, unsigned int p)
Implementation of a matrix and operations on matrices.
static void convertMoment(const vpCameraParameters &cam, unsigned int order, const vpMatrix &moment_pixel, vpMatrix &moment_meter)
static void convertLine(const vpCameraParameters &cam, const double &rho_p, const double &theta_p, double &rho_m, double &theta_m)
static void convertEllipse(const vpCameraParameters &cam, const vpImagePoint ¢er_p, double n20_p, double n11_p, double n02_p, double &xc_m, double &yc_m, double &n20_m, double &n11_m, double &n02_m)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)