Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpMeterPixelConversion.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  * Meter to pixel conversion.
33  *
34  * Authors:
35  * Eric Marchand
36  * Anthony Saunier
37  *
38  *****************************************************************************/
39 
40 #ifndef vpMeterPixelConversion_H
41 #define vpMeterPixelConversion_H
42 
49 #include <visp3/core/vpCameraParameters.h>
50 #include <visp3/core/vpCircle.h>
51 #include <visp3/core/vpSphere.h>
52 #include <visp3/core/vpException.h>
53 #include <visp3/core/vpImagePoint.h>
54 #include <visp3/core/vpMath.h>
55 
56 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
57 # include <opencv2/calib3d/calib3d.hpp>
58 #endif
59 
72 class VISP_EXPORT vpMeterPixelConversion
73 {
74 public:
77  static void convertEllipse(const vpCameraParameters &cam, const vpSphere &sphere, vpImagePoint &center,
78  double &mu20_p, double &mu11_p, double &mu02_p);
79  static void convertEllipse(const vpCameraParameters &cam, const vpCircle &circle, vpImagePoint &center,
80  double &mu20_p, double &mu11_p, double &mu02_p);
81  static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p,
82  double &theta_p);
83 
107  inline static void convertPoint(const vpCameraParameters &cam,
108  const double &x, const double &y, double &u, double &v)
109  {
110  switch (cam.projModel) {
112  convertPointWithoutDistortion(cam, x, y, u, v);
113  break;
115  convertPointWithDistortion(cam, x, y, u, v);
116  break;
117  }
118  }
119 
144  inline static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, vpImagePoint &iP)
145  {
146  switch (cam.projModel) {
148  convertPointWithoutDistortion(cam, x, y, iP);
149  break;
151  convertPointWithDistortion(cam, x, y, iP);
152  break;
153  }
154  }
155 
156 #ifndef DOXYGEN_SHOULD_SKIP_THIS
157 
166  inline static void convertPointWithoutDistortion(const vpCameraParameters &cam, const double &x, const double &y,
167  double &u, double &v)
168  {
169  u = x * cam.px + cam.u0;
170  v = y * cam.py + cam.v0;
171  }
172 
183  inline static void convertPointWithoutDistortion(const vpCameraParameters &cam, const double &x, const double &y,
184  vpImagePoint &iP)
185  {
186  iP.set_u(x * cam.px + cam.u0);
187  iP.set_v(y * cam.py + cam.v0);
188  }
189 
206  inline static void convertPointWithDistortion(const vpCameraParameters &cam, const double &x, const double &y,
207  double &u, double &v)
208  {
209  double r2 = 1. + cam.kud * (x * x + y * y);
210  u = cam.u0 + cam.px * x * r2;
211  v = cam.v0 + cam.py * y * r2;
212  }
213 
230  inline static void convertPointWithDistortion(const vpCameraParameters &cam, const double &x, const double &y,
231  vpImagePoint &iP)
232  {
233  double r2 = 1. + cam.kud * (x * x + y * y);
234  iP.set_u(cam.u0 + cam.px * x * r2);
235  iP.set_v(cam.v0 + cam.py * y * r2);
236  }
237 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
238 
239 
240 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
241 
243  static void convertEllipse(const cv::Mat &cameraMatrix,
244  const vpCircle &circle, vpImagePoint &center,
245  double &mu20_p, double &mu11_p, double &mu02_p);
246  static void convertEllipse(const cv::Mat &cameraMatrix,
247  const vpSphere &sphere, vpImagePoint &center,
248  double &mu20_p, double &mu11_p, double &mu02_p);
249  static void convertLine(const cv::Mat &cameraMatrix,
250  const double &rho_m, const double &theta_m,
251  double &rho_p, double &theta_p);
252  static void convertPoint(const cv::Mat &cameraMatrix, const cv::Mat &distCoeffs,
253  const double &x, const double &y, double &u, double &v);
254  static void convertPoint(const cv::Mat &cameraMatrix, const cv::Mat &distCoeffs,
255  const double &x, const double &y, vpImagePoint &iP);
257 #endif
258 };
259 
260 #endif
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, vpImagePoint &iP)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Class that defines what is a sphere.
Definition: vpSphere.h:60
void set_u(const double u)
Definition: vpImagePoint.h:226
void set_v(const double v)
Definition: vpImagePoint.h:237
Generic class defining intrinsic camera parameters.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
Class that defines what is a circle.
Definition: vpCircle.h:58