ViSP  2.6.2
vpFeatureBuilderEllipse.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureBuilderEllipse.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  * Conversion between tracker and visual feature ellipse.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
49 #include <visp/vpFeatureBuilder.h>
50 
51 
52 #include <visp/vpMath.h>
53 
54 
55 
70 {
71  try
72  {
73 
74  // 3D data
75  double alpha = t.cP[0] ;
76  double beta = t.cP[1] ;
77  double gamma = t.cP[2] ;
78 
79  double X0 = t.cP[3] ;
80  double Y0 = t.cP[4] ;
81  double Z0 = t.cP[5] ;
82 
83  // equation p 318 prior eq (39)
84  double d = alpha*X0 + beta*Y0 + gamma*Z0 ;
85 
86  double A = alpha / d ;
87  double B = beta / d ;
88  double C = gamma / d ;
89 
90  s.setABC(A,B,C) ;
91 
92 
93  //2D data
94  s.buildFrom( t.p[0], t.p[1], t.p[2], t.p[3], t.p[4] ) ;
95 
96  }
97  catch(...)
98  {
99  vpERROR_TRACE("Error caught") ;
100  throw ;
101  }
102 
103 }
104 
105 
121 {
122  try
123  {
124 
125  // 3D data
126  double X0 = t.cP[0] ;
127  double Y0 = t.cP[1] ;
128  double Z0 = t.cP[2] ;
129  double R = t.cP[3] ;
130 
131  double d = vpMath::sqr(X0) + vpMath::sqr(Y0) + vpMath::sqr(Z0) -
132  vpMath::sqr(R) ;
133 
134 
135  double A = X0 / d ;
136  double B = Y0 / d ;
137  double C = Z0 / d ;
138 
139  s.setABC(A,B,C) ;
140 
141  //2D data
142  s.buildFrom( t.p[0], t.p[1], t.p[2], t.p[3], t.p[4] ) ;
143 
144 
145  }
146  catch(...)
147  {
148  vpERROR_TRACE("Error caught") ;
149  throw ;
150  }
151 }
152 
153 
171  const vpCameraParameters &cam,
172  const vpDot &t )
173 {
174  try
175  {
176 
177  unsigned int order = 3 ;
178  vpMatrix mp(order,order) ; mp =0 ;
179  vpMatrix m(order,order) ; m = 0 ;
180 
181  mp[0][0] = t.m00 ;
182  mp[1][0] = t.m10;
183  mp[0][1] = t.m01 ;
184  mp[2][0] = t.m20 ;
185  mp[1][1] = t.m11 ;
186  mp[0][2] = t.m02 ;
187 
188  vpPixelMeterConversion::convertMoment(cam,order,mp,m) ;
189 
190  double m00 = m[0][0] ;
191  double m01 = m[0][1] ;
192  double m10 = m[1][0] ;
193  double m02 = m[0][2] ;
194  double m11 = m[1][1] ;
195  double m20 = m[2][0] ;
196 
197  double xc = m10/m00 ; // sum j /S
198  double yc = m01/m00 ; // sum i /S
199 
200  double mu20 = 4*(m20 - m00*vpMath::sqr(xc))/(m00) ;
201  double mu02 = 4*(m02 - m00*vpMath::sqr(yc))/(m00) ;
202  double mu11 = 4*(m11 - m00*xc*yc)/(m00) ;
203 
204  s.buildFrom(xc, yc, mu20, mu11, mu02 ) ;
205  }
206  catch(...)
207  {
208  vpERROR_TRACE("Error caught") ;
209  throw ;
210  }
211 
212 }
213 
214 
215 
233  const vpCameraParameters &cam,
234  const vpDot2 &t )
235 {
236  try
237  {
238 
239  unsigned int order = 3 ;
240  vpMatrix mp(order,order) ; mp =0 ;
241  vpMatrix m(order,order) ; m = 0 ;
242 
243  mp[0][0] = t.m00 ;
244  mp[1][0] = t.m10;
245  mp[0][1] = t.m01 ;
246  mp[2][0] = t.m20 ;
247  mp[1][1] = t.m11 ;
248  mp[0][2] = t.m02 ;
249 
250  vpPixelMeterConversion::convertMoment(cam,order,mp,m) ;
251 
252  double m00 = m[0][0] ;
253  double m01 = m[0][1] ;
254  double m10 = m[1][0] ;
255  double m02 = m[0][2] ;
256  double m11 = m[1][1] ;
257  double m20 = m[2][0] ;
258 
259  double xc = m10/m00 ; // sum j /S
260  double yc = m01/m00 ; // sum i /S
261 
262  double mu20 = 4*(m20 - m00*vpMath::sqr(xc))/(m00) ;
263  double mu02 = 4*(m02 - m00*vpMath::sqr(yc))/(m00) ;
264  double mu11 = 4*(m11 - m00*xc*yc)/(m00) ;
265 
266  s.buildFrom(xc, yc, mu20, mu11, mu02 ) ;
267  }
268  catch(...)
269  {
270  vpERROR_TRACE("Error caught") ;
271  throw ;
272  }
273 
274 }
275 
293  const vpCameraParameters &cam,
294  const vpMeEllipse &t )
295 {
296  try
297  {
298 
299  unsigned int order = 3 ;
300  vpMatrix mp(order,order) ; mp =0 ;
301  vpMatrix m(order,order) ; m = 0 ;
302 
303  //The opposite of vpDot and vpDot2 because moments in vpMeEllipse
304  //are computed in the ij coordinate system whereas the moments in vpDot and vpDot2
305  //are computed in the uv coordinate system
306  mp[0][0] = t.get_m00() ;
307  mp[1][0] = t.get_m01();
308  mp[0][1] = t.get_m10() ;
309  mp[2][0] = t.get_m02() ;
310  mp[1][1] = t.get_m11() ;
311  mp[0][2] = t.get_m20() ;
312 
313  vpPixelMeterConversion::convertMoment(cam,order,mp,m) ;
314 
315  double m00 = m[0][0] ;
316  double m01 = m[0][1] ;
317  double m10 = m[1][0] ;
318  double m02 = m[0][2] ;
319  double m11 = m[1][1] ;
320  double m20 = m[2][0] ;
321 
322  double xc = m10/m00 ; // sum j /S
323  double yc = m01/m00 ; // sum i /S
324 
325  double mu20 = 4*(m20 - m00*vpMath::sqr(xc))/(m00) ;
326  double mu02 = 4*(m02 - m00*vpMath::sqr(yc))/(m00) ;
327  double mu11 = 4*(m11 - m00*xc*yc)/(m00) ;
328 
329  s.buildFrom(xc, yc, mu20, mu11, mu02 ) ;
330  }
331  catch(...)
332  {
333  vpERROR_TRACE("Error caught") ;
334  throw ;
335  }
336 
337 }
338 /*
339  * Local variables:
340  * c-basic-offset: 2
341  * End:
342  */
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
double m02
Definition: vpDot2.h:379
double m10
Definition: vpDot.h:109
#define vpERROR_TRACE
Definition: vpDebug.h:379
double m00
Definition: vpDot.h:95
Class that tracks an ellipse moving edges.
Definition: vpMeEllipse.h:135
double m11
Definition: vpDot2.h:363
Class that defines what is a sphere.
Definition: vpSphere.h:64
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:114
double m01
Definition: vpDot2.h:355
double m20
Definition: vpDot.h:125
double m11
Definition: vpDot.h:116
double get_m02() const
Definition: vpMeEllipse.h:215
vpColVector cP
Definition: vpTracker.h:82
double m01
Definition: vpDot.h:102
double m20
Definition: vpDot2.h:370
static double sqr(double x)
Definition: vpMath.h:106
Generic class defining intrinsic camera parameters.
double get_m01() const
Definition: vpMeEllipse.h:194
void setABC(const double A, const double B, const double C)
double m02
Definition: vpDot.h:134
double get_m00() const
Definition: vpMeEllipse.h:180
static void convertMoment(const vpCameraParameters &cam, unsigned int order, const vpMatrix &moment_pixel, vpMatrix &moment_meter)
double get_m20() const
Definition: vpMeEllipse.h:208
This tracker is meant to track a dot (connex pixels with same gray level) on a vpImage.
Definition: vpDot.h:80
double m10
Definition: vpDot2.h:347
void buildFrom(const double x, const double y, const double mu20, const double mu11, const double mu02)
double m00
Definition: vpDot2.h:336
Class that defines 2D ellipse visual feature.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines what is a circle.
Definition: vpCircle.h:61
double get_m10() const
Definition: vpMeEllipse.h:187
vpColVector p
Definition: vpTracker.h:78
double get_m11() const
Definition: vpMeEllipse.h:201