Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpFeatureBuilderEllipse.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
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  * Conversion between tracker and visual feature ellipse.
32  *
33  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
38 
45 #include <visp3/visual_features/vpFeatureBuilder.h>
46 #include <visp3/core/vpMath.h>
47 
48 
49 
64 {
65  try
66  {
67 
68  // 3D data
69  double alpha = t.cP[0] ;
70  double beta = t.cP[1] ;
71  double gamma = t.cP[2] ;
72 
73  double X0 = t.cP[3] ;
74  double Y0 = t.cP[4] ;
75  double Z0 = t.cP[5] ;
76 
77  // equation p 318 prior eq (39)
78  double d = alpha*X0 + beta*Y0 + gamma*Z0 ;
79 
80  double A = alpha / d ;
81  double B = beta / d ;
82  double C = gamma / d ;
83 
84  s.setABC(A,B,C) ;
85 
86 
87  //2D data
88  s.buildFrom( t.p[0], t.p[1], t.p[2], t.p[3], t.p[4] ) ;
89 
90  }
91  catch(...)
92  {
93  vpERROR_TRACE("Error caught") ;
94  throw ;
95  }
96 
97 }
98 
99 
115 {
116  try
117  {
118 
119  // 3D data
120  double X0 = t.cP[0] ;
121  double Y0 = t.cP[1] ;
122  double Z0 = t.cP[2] ;
123  double R = t.cP[3] ;
124 
125  double d = vpMath::sqr(X0) + vpMath::sqr(Y0) + vpMath::sqr(Z0) -
126  vpMath::sqr(R) ;
127 
128 
129  double A = X0 / d ;
130  double B = Y0 / d ;
131  double C = Z0 / d ;
132 
133  s.setABC(A,B,C) ;
134 
135  //2D data
136  s.buildFrom( t.p[0], t.p[1], t.p[2], t.p[3], t.p[4] ) ;
137 
138 
139  }
140  catch(...)
141  {
142  vpERROR_TRACE("Error caught") ;
143  throw ;
144  }
145 }
146 
147 
148 #ifdef VISP_HAVE_MODULE_BLOB
149 
166  const vpCameraParameters &cam,
167  const vpDot &t )
168 {
169  try
170  {
171 
172  unsigned int order = 3 ;
173  vpMatrix mp(order,order) ; mp =0 ;
174  vpMatrix m(order,order) ; m = 0 ;
175 
176  mp[0][0] = t.m00 ;
177  mp[1][0] = t.m10;
178  mp[0][1] = t.m01 ;
179  mp[2][0] = t.m20 ;
180  mp[1][1] = t.m11 ;
181  mp[0][2] = t.m02 ;
182 
183  vpPixelMeterConversion::convertMoment(cam,order,mp,m) ;
184 
185  double m00 = m[0][0] ;
186  double m01 = m[0][1] ;
187  double m10 = m[1][0] ;
188  double m02 = m[0][2] ;
189  double m11 = m[1][1] ;
190  double m20 = m[2][0] ;
191 
192  double xc = m10/m00 ; // sum j /S
193  double yc = m01/m00 ; // sum i /S
194 
195  double mu20 = 4*(m20 - m00*vpMath::sqr(xc))/(m00) ;
196  double mu02 = 4*(m02 - m00*vpMath::sqr(yc))/(m00) ;
197  double mu11 = 4*(m11 - m00*xc*yc)/(m00) ;
198 
199  s.buildFrom(xc, yc, mu20, mu11, mu02 ) ;
200  }
201  catch(...)
202  {
203  vpERROR_TRACE("Error caught") ;
204  throw ;
205  }
206 }
207 
225  const vpCameraParameters &cam,
226  const vpDot2 &t )
227 {
228  try
229  {
230 
231  unsigned int order = 3 ;
232  vpMatrix mp(order,order) ; mp =0 ;
233  vpMatrix m(order,order) ; m = 0 ;
234 
235  mp[0][0] = t.m00 ;
236  mp[1][0] = t.m10;
237  mp[0][1] = t.m01 ;
238  mp[2][0] = t.m20 ;
239  mp[1][1] = t.m11 ;
240  mp[0][2] = t.m02 ;
241 
242  vpPixelMeterConversion::convertMoment(cam,order,mp,m) ;
243 
244  double m00 = m[0][0] ;
245  double m01 = m[0][1] ;
246  double m10 = m[1][0] ;
247  double m02 = m[0][2] ;
248  double m11 = m[1][1] ;
249  double m20 = m[2][0] ;
250 
251  double xc = m10/m00 ; // sum j /S
252  double yc = m01/m00 ; // sum i /S
253 
254  double mu20 = 4*(m20 - m00*vpMath::sqr(xc))/(m00) ;
255  double mu02 = 4*(m02 - m00*vpMath::sqr(yc))/(m00) ;
256  double mu11 = 4*(m11 - m00*xc*yc)/(m00) ;
257 
258  s.buildFrom(xc, yc, mu20, mu11, mu02 ) ;
259  }
260  catch(...)
261  {
262  vpERROR_TRACE("Error caught") ;
263  throw ;
264  }
265 }
266 #endif //#ifdef VISP_HAVE_MODULE_BLOB
267 
268 #ifdef VISP_HAVE_MODULE_ME
269 
286  const vpCameraParameters &cam,
287  const vpMeEllipse &t )
288 {
289  try
290  {
291 
292  unsigned int order = 3 ;
293  vpMatrix mp(order,order) ; mp =0 ;
294  vpMatrix m(order,order) ; m = 0 ;
295 
296  //The opposite of vpDot and vpDot2 because moments in vpMeEllipse
297  //are computed in the ij coordinate system whereas the moments in vpDot and vpDot2
298  //are computed in the uv coordinate system
299  mp[0][0] = t.get_m00() ;
300  mp[1][0] = t.get_m01();
301  mp[0][1] = t.get_m10() ;
302  mp[2][0] = t.get_m02() ;
303  mp[1][1] = t.get_m11() ;
304  mp[0][2] = t.get_m20() ;
305 
306  vpPixelMeterConversion::convertMoment(cam,order,mp,m) ;
307 
308  double m00 = m[0][0] ;
309  double m01 = m[0][1] ;
310  double m10 = m[1][0] ;
311  double m02 = m[0][2] ;
312  double m11 = m[1][1] ;
313  double m20 = m[2][0] ;
314 
315  double xc = m10/m00 ; // sum j /S
316  double yc = m01/m00 ; // sum i /S
317 
318  double mu20 = 4*(m20 - m00*vpMath::sqr(xc))/(m00) ;
319  double mu02 = 4*(m02 - m00*vpMath::sqr(yc))/(m00) ;
320  double mu11 = 4*(m11 - m00*xc*yc)/(m00) ;
321 
322  s.buildFrom(xc, yc, mu20, mu11, mu02 ) ;
323  }
324  catch(...)
325  {
326  vpERROR_TRACE("Error caught") ;
327  throw ;
328  }
329 }
330 #endif //#ifdef VISP_HAVE_MODULE_ME
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
double m02
Definition: vpDot2.h:410
double m10
Definition: vpDot.h:145
#define vpERROR_TRACE
Definition: vpDebug.h:391
double m00
Definition: vpDot.h:131
Class that tracks an ellipse moving edges.
Definition: vpMeEllipse.h:95
double m11
Definition: vpDot2.h:394
Class that defines what is a sphere.
Definition: vpSphere.h:60
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:125
double m01
Definition: vpDot2.h:386
double m20
Definition: vpDot.h:161
double m11
Definition: vpDot.h:152
double get_m02() const
Definition: vpMeEllipse.h:166
vpColVector cP
Definition: vpTracker.h:77
double m01
Definition: vpDot.h:138
double m20
Definition: vpDot2.h:401
static double sqr(double x)
Definition: vpMath.h:110
Generic class defining intrinsic camera parameters.
double get_m01() const
Definition: vpMeEllipse.h:145
void setABC(const double A, const double B, const double C)
double m02
Definition: vpDot.h:170
double get_m00() const
Definition: vpMeEllipse.h:131
static void convertMoment(const vpCameraParameters &cam, unsigned int order, const vpMatrix &moment_pixel, vpMatrix &moment_meter)
double get_m20() const
Definition: vpMeEllipse.h:159
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:116
double m10
Definition: vpDot2.h:378
void buildFrom(const double x, const double y, const double mu20, const double mu11, const double mu02)
double m00
Definition: vpDot2.h:370
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:57
double get_m10() const
Definition: vpMeEllipse.h:138
vpColVector p
Definition: vpTracker.h:73
double get_m11() const
Definition: vpMeEllipse.h:152