Visual Servoing Platform  version 3.0.0
vpMeterPixelConversion.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Meter to pixel conversion.
32  *
33  * Authors:
34  * Eric Marchand
35  * Anthony Saunier
36  *
37  *****************************************************************************/
38 
44 #include <visp3/core/vpMeterPixelConversion.h>
45 #include <visp3/core/vpCameraParameters.h>
46 #include <visp3/core/vpException.h>
47 #include <visp3/core/vpMath.h>
48 #include <visp3/core/vpDebug.h>
49 
51 void
53  const double &rho_m, const double &theta_m,
54  double &rho_p, double &theta_p)
55 {
56  double co = cos(theta_m) ;
57  double si = sin(theta_m) ;
58  double d = sqrt(vpMath::sqr(cam.py*co) + vpMath::sqr(cam.px*si)) ;
59 
60  if (fabs(d)<1e-6)
61  {
62  vpERROR_TRACE("division by zero") ;
64  "division by zero")) ;
65  }
66 
67  theta_p = atan2(cam.px*si, cam.py*co) ;
68  rho_p = (cam.px*cam.py*rho_m + cam.u0*cam.py*co + cam.v0*cam.px*si) ;
69  rho_p /= d ;
70 }
71 
94 void
96  const vpCircle &circle, vpImagePoint &center,
97  double &mu20_p, double &mu11_p, double &mu02_p)
98 {
99  // Get the parameters of the ellipse in the image plane
100  double xc_m = circle.p[0];
101  double yc_m = circle.p[1];
102  double mu20_m = circle.p[2];
103  double mu11_m = circle.p[3];
104  double mu02_m = circle.p[4];
105 
106  // Convert from meter to pixels
107  vpMeterPixelConversion::convertPoint(cam, xc_m, yc_m, center);
108  mu20_p = mu20_m*vpMath::sqr(cam.get_px());
109  mu11_p = mu11_m*cam.get_px()*cam.get_py();
110  mu02_p = mu02_m*vpMath::sqr(cam.get_py());
111 }
112 
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:391
error that can be emited by ViSP classes.
Definition: vpException.h:73
double get_py() const
static double sqr(double x)
Definition: vpMath.h:110
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)
double get_px() const
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:57
vpColVector p
Definition: vpTracker.h:73