Visual Servoing Platform  version 3.1.0
vpPixelMeterConversion.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  * Pixel to meter conversion.
33  *
34  * Authors:
35  * Eric Marchand
36  * Anthony Saunier
37  *
38  *****************************************************************************/
39 
44 #include <visp3/core/vpCameraParameters.h>
45 #include <visp3/core/vpDebug.h>
46 #include <visp3/core/vpException.h>
47 #include <visp3/core/vpMath.h>
48 #include <visp3/core/vpPixelMeterConversion.h>
49 
51 void vpPixelMeterConversion::convertLine(const vpCameraParameters &cam, const double &rho_p, const double &theta_p,
52  double &rho_m, double &theta_m)
53 {
54  double co = cos(theta_p);
55  double si = sin(theta_p);
56  double d = vpMath::sqr(cam.px * co) + vpMath::sqr(cam.py * si);
57 
58  if (fabs(d) < 1e-6) {
59  vpERROR_TRACE("division by zero");
60  throw(vpException(vpException::divideByZeroError, "division by zero"));
61  }
62  theta_m = atan2(si * cam.py, co * cam.px);
63  rho_m = (rho_p - cam.u0 * co - cam.v0 * si) / sqrt(d);
64 }
65 
66 void vpPixelMeterConversion::convertMoment(const vpCameraParameters &cam, unsigned int order,
67  const vpMatrix &moment_pixel, vpMatrix &moment_meter)
68 {
69 
70  vpMatrix m(order, order);
71  double yc = -cam.v0;
72  double xc = -cam.u0;
73 
74  for (unsigned int k = 0; k < order; k++) // iteration correspondant e l'ordre du moment
75  {
76  for (unsigned int p = 0; p < order; p++) // iteration en X
77  for (unsigned int q = 0; q < order; q++) // iteration en Y
78  if (p + q == k) // on est bien dans la matrice triangulaire superieure
79  {
80  m[p][q] = 0; // initialisation e 0
81  for (unsigned int r = 0; r <= p; r++) // somme externe
82  for (unsigned int t = 0; t <= q; t++) // somme interne
83  {
84  m[p][q] += static_cast<double>(vpMath::comb(p, r)) * static_cast<double>(vpMath::comb(q, t)) *
85  pow(xc, (int)(p - r)) * pow(yc, (int)(q - t)) * moment_pixel[r][t];
86  }
87  }
88  }
89 
90  for (unsigned int k = 0; k < order; k++) // iteration correspondant e l'ordre du moment
91  for (unsigned int p = 0; p < order; p++)
92  for (unsigned int q = 0; q < order; q++)
93  if (p + q == k) {
94  m[p][q] *= pow(cam.inv_px, (int)(1 + p)) * pow(cam.inv_py, (int)(1 + q));
95  }
96 
97  for (unsigned int k = 0; k < order; k++) // iteration correspondant e l'ordre du moment
98  for (unsigned int p = 0; p < order; p++)
99  for (unsigned int q = 0; q < order; q++)
100  if (p + q == k) {
101  moment_meter[p][q] = m[p][q];
102  }
103 }
104 
105 /*
106  * Local variables:
107  * c-basic-offset: 2
108  * End:
109  */
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
#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 convertMoment(const vpCameraParameters &cam, unsigned int order, const vpMatrix &moment_pixel, vpMatrix &moment_meter)
static long double comb(unsigned int n, unsigned int p)
Definition: vpMath.h:220
static void convertLine(const vpCameraParameters &cam, const double &rho_p, const double &theta_p, double &rho_m, double &theta_m)
line coordinates conversion (rho,theta)