Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vpPixelMeterConversion.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Pixel to meter conversion.
33  *
34  * Authors:
35  * Eric Marchand
36  * Anthony Saunier
37  *
38  *****************************************************************************/
39 
40 #ifndef vpPixelMeterConversion_H
41 #define vpPixelMeterConversion_H
42 
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>
53 
54 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
55 # include <opencv2/imgproc/imgproc.hpp>
56 # include <opencv2/calib3d/calib3d.hpp>
57 #endif
58 
71 class VISP_EXPORT vpPixelMeterConversion
72 {
73 public:
76  static void convertLine(const vpCameraParameters &cam, const double &rho_p, const double &theta_p, double &rho_m,
77  double &theta_m);
78 
79  static void convertMoment(const vpCameraParameters &cam, unsigned int order, const vpMatrix &moment_pixel,
80  vpMatrix &moment_meter);
103  inline static void convertPoint(const vpCameraParameters &cam,
104  const double &u, const double &v, double &x, double &y)
105  {
106  switch (cam.projModel) {
108  convertPointWithoutDistortion(cam, u, v, x, y);
109  break;
111  convertPointWithDistortion(cam, u, v, x, y);
112  break;
113  }
114  }
115 
140  inline static void convertPoint(const vpCameraParameters &cam,
141  const vpImagePoint &iP, double &x, double &y)
142  {
143  switch (cam.projModel) {
145  convertPointWithoutDistortion(cam, iP, x, y);
146  break;
148  convertPointWithDistortion(cam, iP, x, y);
149  break;
150  }
151  }
152 
153 #ifndef DOXYGEN_SHOULD_SKIP_THIS
154 
166  inline static void convertPointWithoutDistortion(const vpCameraParameters &cam,
167  const double &u, const double &v, double &x, double &y)
168  {
169  x = (u - cam.u0) * cam.inv_px;
170  y = (v - cam.v0) * cam.inv_py;
171  }
172 
188  inline static void convertPointWithoutDistortion(const vpCameraParameters &cam,
189  const vpImagePoint &iP, double &x, double &y)
190  {
191  x = (iP.get_u() - cam.u0) * cam.inv_px;
192  y = (iP.get_v() - cam.v0) * cam.inv_py;
193  }
194 
209  inline static void convertPointWithDistortion(const vpCameraParameters &cam,
210  const double &u, const double &v, double &x, double &y)
211  {
212  double r2 = 1. + cam.kdu * (vpMath::sqr((u - cam.u0) * cam.inv_px) + vpMath::sqr((v - cam.v0) * cam.inv_py));
213  x = (u - cam.u0) * r2 * cam.inv_px;
214  y = (v - cam.v0) * r2 * cam.inv_py;
215  }
216 
233  inline static void convertPointWithDistortion(const vpCameraParameters &cam,
234  const vpImagePoint &iP, double &x, double &y)
235  {
236  double r2 = 1. + cam.kdu * (vpMath::sqr((iP.get_u() - cam.u0) * cam.inv_px) +
237  vpMath::sqr((iP.get_v() - cam.v0) * cam.inv_py));
238  x = (iP.get_u() - cam.u0) * r2 * cam.inv_px;
239  y = (iP.get_v() - cam.v0) * r2 * cam.inv_py;
240  }
241 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
242 
243 
244 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
245 
247  static void convertLine(const cv::Mat &cameraMatrix,
248  const double &rho_p, const double &theta_p,
249  double &rho_m, double &theta_m);
250  static void convertMoment(const cv::Mat &cameraMatrix,
251  unsigned int order, const vpMatrix &moment_pixel,
252  vpMatrix &moment_meter);
253  static void convertPoint(const cv::Mat &cameraMatrix, const cv::Mat &distCoeffs,
254  const double &u, const double &v, double &x, double &y);
255  static void convertPoint(const cv::Mat &cameraMatrix, const cv::Mat &distCoeffs,
256  const vpImagePoint &iP, double &x, double &y);
258 #endif
259 };
260 
261 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:164
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
double get_u() const
Definition: vpImagePoint.h:263
static double sqr(double x)
Definition: vpMath.h:114
Generic class defining intrinsic camera parameters.
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 ...
Definition: vpImagePoint.h:88
double get_v() const
Definition: vpImagePoint.h:274