ViSP  2.8.0
vpMeEllipse.h
1 /****************************************************************************
2  *
3  * $Id: vpMeEllipse.h 4231 2013-04-29 16:26:28Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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  * Moving edges.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
47 #ifndef vpMeEllipse_HH
48 #define vpMeEllipse_HH
49 
50 #include <visp/vpMatrix.h>
51 #include <visp/vpColVector.h>
52 
53 #include <visp/vpMeTracker.h>
54 #include <visp/vpMeSite.h>
55 #include <visp/vpImagePoint.h>
56 
57 #include <visp/vpImage.h>
58 #include <visp/vpColor.h>
59 
60 #include <math.h>
61 #include <list>
62 
99 /*
100  The code below shows how to use this class.
101 \code
102 #include <visp/vpConfig.h>
103 #include <visp/vpImage.h>
104 #include <visp/vpMeEllipse.h>
105 #include <visp/vpImagePoint.h>
106 
107 int main()
108 {
109  vpImage<unsigned char> I;
110 
111  // I is the image containing the ellipse to track
112 
113  // Set the moving-edges tracker parameters
114  vpMe me;
115  me.setRange(25);
116  me.setPointsToTrack(20);
117  me.setThreshold(15000);
118  me.setSampleStep(10);
119 
120  // Initialize the moving-edges ellipse tracker parameters
121  vpMeEllipse ellipse;
122  ellipse.setMe(&me);
123 
124  // Initialize the tracking. You have to click on five different points belonging to the ellipse.
125  ellipse.initTracking(I);
126 
127  while ( 1 )
128  {
129  // ... Here the code to read or grab the next image.
130 
131  // Track the ellipse.
132  ellipse.track(I);
133  }
134  return 0;
135 }
136 \endcode
137 
138  \note It is possible to display the ellipse as an overlay. For that you
139  must use the display function of the class vpMeEllipse.
140 */
141 
142 class VISP_EXPORT vpMeEllipse : public vpMeTracker
143 {
144 public:
145  vpMeEllipse() ;
146  vpMeEllipse(const vpMeEllipse &meellipse) ;
147  virtual ~vpMeEllipse() ;
148 
149  void track(const vpImage<unsigned char>& Im);
150 
151  void initTracking(const vpImage<unsigned char> &I) ;
152  void initTracking(const vpImage<unsigned char> &I, const unsigned int n,
153  vpImagePoint* iP) ;
154  void display(const vpImage<unsigned char>&I, vpColor col) ;
155  void printParameters() ;
156 
157 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
158 
162  void initTracking(const vpImage<unsigned char> &I, const unsigned int n,
163  unsigned *i, unsigned *j) ;
165 #endif //VISP_BUILD_DEPRECATED_FUNCTIONS
166 
180  void setCircle(bool circle) { this->circle = circle ; }
181 
187  inline double get_m00() const {return m00;}
188 
194  inline double get_m10() const {return m10;}
195 
201  inline double get_m01() const {return m01;}
202 
208  inline double get_m11() const {return m11;}
209 
215  inline double get_m20() const {return m20;}
216 
222  inline double get_m02() const {return m02;}
223 
229  inline double get_mu11() const {return mu11;}
230 
236  inline double get_mu02() const {return mu02;}
237 
243  inline double get_mu20() const {return mu20;}
244 
248  inline vpImagePoint getCenter() const {return iPc; }
249 
253  inline double getA() const {return a; }
254 
258  inline double getB() const {return b; }
259 
263  inline double getE() const {return e; }
264 
268  void getEquationParam(double &A, double &B, double &E) { A = a; B = b; E = e; }
269 
273  inline double getSmallestAngle() { return alpha1; }
274 
278  inline double getHighestAngle() { return alpha2; }
279 
289  void setThresholdRobust(const double threshold){
290  if(threshold<0){
291  thresholdWeight = 0;
292  }else if(threshold>1){
293  thresholdWeight = 1;
294  }else{
295  thresholdWeight = threshold;
296  }
297  }
298 
299 
300 
301 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
302 public:
303 #else
304 protected:
305 #endif
306 
313  double a;
315  double b;
317  double e;
318 
319 protected:
325  double alpha1 ;
327  double alpha2 ;
329  double ce;
331  double se;
333  std::list<double> angle;
335  double m00;
337  double mu11,mu20, mu02;
339  double m10,m01;
341  double m11,m02,m20;
344 
345 private:
347  bool circle ;
348 
349  void computeAngle(vpImagePoint pt1, vpImagePoint pt2);
350  void sample(const vpImage<unsigned char>&image);
351  void reSample(const vpImage<unsigned char> &I) ;
352  void leastSquare() ;
353  void updateTheta();
354  void suppressPoints() ;
355  void seekExtremities(const vpImage<unsigned char> &I) ;
356  void setExtremities();
357  void getParameters() ;
358  void computeMoments();
359 
360 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
361 
365  void computeAngle(int ip1, int jp1,int ip2, int jp2) ;
366  void computeAngle(int ip1, int jp1, double &alpha1,
367  int ip2, int jp2, double &alpha2) ;
369 #endif //VISP_BUILD_DEPRECATED_FUNCTIONS
370 
371 //Static Function
372 public:
373  static void display(const vpImage<unsigned char>& I, const vpImagePoint &center,
374  const double &A, const double &B, const double &E,
375  const double & smallalpha, const double &highalpha,
376  vpColor color = vpColor::green);
377  static void display(const vpImage<vpRGBa>& I, const vpImagePoint &center,
378  const double &A, const double &B, const double &E,
379  const double & smallalpha, const double &highalpha,
380  vpColor color = vpColor::green);
381 
382 };
383 
384 #endif
double a
is the semiminor axis of the ellipse.
Definition: vpMeEllipse.h:313
double e
is the angle made by the major axis and the i axis of the image frame .
Definition: vpMeEllipse.h:317
double thresholdWeight
Threshold for the robust least square.
Definition: vpMeEllipse.h:343
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
vpImagePoint iP1
The coordinates of the point corresponding to the smallest angle. More things about the are given a...
Definition: vpMeEllipse.h:321
double getHighestAngle()
Definition: vpMeEllipse.h:278
Class that tracks an ellipse moving edges.
Definition: vpMeEllipse.h:142
virtual void sample(const vpImage< unsigned char > &image)=0
Sample pixels at a given interval.
double getA() const
Definition: vpMeEllipse.h:253
double mu20
Definition: vpMeEllipse.h:337
static const vpColor green
Definition: vpColor.h:170
double get_mu02() const
Definition: vpMeEllipse.h:236
double b
is the semimajor axis of the ellipse.
Definition: vpMeEllipse.h:315
double se
Value of sin(e).
Definition: vpMeEllipse.h:331
double get_m02() const
Definition: vpMeEllipse.h:222
double m20
Definition: vpMeEllipse.h:341
double get_mu20() const
Definition: vpMeEllipse.h:243
vpImagePoint iP2
The coordinates of the point corresponding to the highest angle. More things about the are given at...
Definition: vpMeEllipse.h:323
vpImagePoint iPc
The coordinates of the ellipse center.
Definition: vpMeEllipse.h:311
double getE() const
Definition: vpMeEllipse.h:263
double alpha1
The smallest angle.
Definition: vpMeEllipse.h:325
double getB() const
Definition: vpMeEllipse.h:258
void setThresholdRobust(const double threshold)
Definition: vpMeEllipse.h:289
double get_m01() const
Definition: vpMeEllipse.h:201
void track(const vpImage< unsigned char > &I)
Track sampled pixels.
double m10
First order raw moments.
Definition: vpMeEllipse.h:339
Contains abstract elements for a Distance to Feature type feature.
Definition: vpMeTracker.h:71
vpColVector K
Definition: vpMeEllipse.h:309
void setCircle(bool circle)
Definition: vpMeEllipse.h:180
double m00
Surface.
Definition: vpMeEllipse.h:335
double get_mu11() const
Definition: vpMeEllipse.h:229
double get_m00() const
Definition: vpMeEllipse.h:187
void getEquationParam(double &A, double &B, double &E)
Definition: vpMeEllipse.h:268
std::list< double > angle
Stores the value of the angle for each vpMeSite.
Definition: vpMeEllipse.h:333
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
double get_m20() const
Definition: vpMeEllipse.h:215
double getSmallestAngle()
Definition: vpMeEllipse.h:273
void initTracking(const vpImage< unsigned char > &I)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
double alpha2
The highest angle.
Definition: vpMeEllipse.h:327
double get_m10() const
Definition: vpMeEllipse.h:194
virtual void display(const vpImage< unsigned char > &I, vpColor col)=0
vpImagePoint getCenter() const
Definition: vpMeEllipse.h:248
double ce
Value of cos(e).
Definition: vpMeEllipse.h:329
double get_m11() const
Definition: vpMeEllipse.h:208