Visual Servoing Platform  version 3.1.0
vpMeterPixelConversion.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 
45 #include <visp3/core/vpCameraParameters.h>
46 #include <visp3/core/vpDebug.h>
47 #include <visp3/core/vpException.h>
48 #include <visp3/core/vpMath.h>
49 #include <visp3/core/vpMeterPixelConversion.h>
50 
52 void vpMeterPixelConversion::convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m,
53  double &rho_p, double &theta_p)
54 {
55  double co = cos(theta_m);
56  double si = sin(theta_m);
57  double d = sqrt(vpMath::sqr(cam.py * co) + vpMath::sqr(cam.px * si));
58 
59  if (fabs(d) < 1e-6) {
60  vpERROR_TRACE("division by zero");
61  throw(vpException(vpException::divideByZeroError, "division by zero"));
62  }
63 
64  theta_p = atan2(cam.px * si, cam.py * co);
65  rho_p = (cam.px * cam.py * rho_m + cam.u0 * cam.py * co + cam.v0 * cam.px * si);
66  rho_p /= d;
67 }
68 
93  double &mu20_p, double &mu11_p, double &mu02_p)
94 {
95  // Get the parameters of the ellipse in the image plane
96  double xc_m = circle.p[0];
97  double yc_m = circle.p[1];
98  double mu20_m = circle.p[2];
99  double mu11_m = circle.p[3];
100  double mu02_m = circle.p[4];
101 
102  // Convert from meter to pixels
103  vpMeterPixelConversion::convertPoint(cam, xc_m, yc_m, center);
104  mu20_p = mu20_m * vpMath::sqr(cam.get_px());
105  mu11_p = mu11_m * cam.get_px() * cam.get_py();
106  mu02_p = mu02_m * vpMath::sqr(cam.get_py());
107 }
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
#define vpERROR_TRACE
Definition: vpDebug.h:393
error that can be emited by ViSP classes.
Definition: vpException.h:71
static double sqr(double x)
Definition: vpMath.h:108
Generic class defining intrinsic camera parameters.
static void convertEllipse(const vpCameraParameters &cam, const vpCircle &circle, vpImagePoint &center, double &mu20_p, double &mu11_p, double &mu02_p)
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
Line coordinates conversion (rho,theta).
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
vpColVector p
Definition: vpTracker.h:71