ViSP  2.6.2
vpPixelMeterConversion.cpp
1 /****************************************************************************
2  *
3  * $Id: vpPixelMeterConversion.cpp 3530 2012-01-03 10:52:12Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Pixel to meter conversion.
36  *
37  * Authors:
38  * Eric Marchand
39  * Anthony Saunier
40  *
41  *****************************************************************************/
42 
47 #include<visp/vpPixelMeterConversion.h>
48 #include<visp/vpCameraParameters.h>
49 #include<visp/vpException.h>
50 #include<visp/vpMath.h>
51 #include<visp/vpDebug.h>
52 
53 
55 void
57  const double &rho_p, const double &theta_p,
58  double &rho_m, double &theta_m)
59 {
60  double co = cos(theta_p) ;
61  double si = sin(theta_p) ;
62  double d = vpMath::sqr(cam.px*co)+vpMath::sqr(cam.py*si) ;
63 
64  if (fabs(d)<1e-6)
65  {
66  vpERROR_TRACE("division by zero") ;
68  "division by zero")) ;
69  }
70  theta_m = atan2(si*cam.py, co*cam.px) ;
71  rho_m = (rho_p - cam.u0*co-cam.v0*si)/sqrt(d) ;
72 }
73 
74 
75 void
77  unsigned int order,
78  const vpMatrix &moment_pixel,
79  vpMatrix &moment_meter)
80 {
81 
82  vpMatrix m(order, order);
83  double yc = -cam.v0 ;
84  double xc = -cam.u0 ;
85 
86  for (unsigned int k=0; k<order; k++) // itération correspondant à l'ordre du moment
87  {
88  for (unsigned int p=0 ; p<order; p++) // itération en X
89  for (unsigned int q=0; q<order; q++) // itération en Y
90  if (p+q==k) // on est bien dans la matrice triangulaire supérieure
91  {
92  m[p][q] = 0; // initialisation à 0
93  for(unsigned int r=0; r<=p; r++) // somme externe
94  for(unsigned int t=0; t<=q; t++) // somme interne
95  {
96  m[p][q] +=
97  static_cast<double>(vpMath::comb(p, r))
98  * static_cast<double>(vpMath::comb(q, t))
99  * pow(xc, (int)(p-r)) * pow(yc, (int)(q-t))
100  * moment_pixel[r][t];
101 
102  }
103  }
104 
105  }
106 
107  for (unsigned int k=0; k<order; k++) // itération correspondant à l'ordre du moment
108  for (unsigned int p=0 ; p<order; p++)
109  for (unsigned int q=0; q<order; q++)
110  if (p+q==k)
111  {
112  m[p][q] *= pow(cam.inv_px,(int)(1+p)) * pow(cam.inv_py,(int)(1+q));
113  }
114 
115  for (unsigned int k=0; k<order; k++) // itération correspondant à l'ordre du moment
116  for (unsigned int p=0 ; p<order; p++)
117  for (unsigned int q=0; q<order; q++)
118  if (p+q==k)
119  {
120  moment_meter[p][q] = m[p][q];
121  }
122 
123 }
124 
125 
126 /*
127  * Local variables:
128  * c-basic-offset: 2
129  * End:
130  */
131 
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
#define vpERROR_TRACE
Definition: vpDebug.h:379
static double sqr(double x)
Definition: vpMath.h:106
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:213
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)