ViSP  2.10.0
vpMeEllipse.h
1 /****************************************************************************
2  *
3  * $Id: vpMeEllipse.h 4705 2014-03-27 16:24:35Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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 
152  int getExpectedDensity() {return (int)expecteddensity;};
153  void track(const vpImage<unsigned char>& Im);
154 
155  void initTracking(const vpImage<unsigned char> &I) ;
156  void initTracking(const vpImage<unsigned char> &I, const unsigned int n, vpImagePoint* iP) ;
157  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ic, double a_p, double b_p, double e_p, double low_alpha, double high_alpha) ;
158  void display(const vpImage<unsigned char>&I, vpColor col) ;
159  void display(const vpImage<unsigned char>& I) {vpMeTracker::display(I);} //Shouldn't be here since it's already in vpMeTracker
160  void printParameters() ;
161 
162 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
163 
167  void initTracking(const vpImage<unsigned char> &I, const unsigned int n,
168  unsigned *i, unsigned *j) ;
170 #endif //VISP_BUILD_DEPRECATED_FUNCTIONS
171 
185  void setCircle(bool is_circle) { this->circle = is_circle ; }
186 
192  inline double get_m00() const {return m00;}
193 
199  inline double get_m10() const {return m10;}
200 
206  inline double get_m01() const {return m01;}
207 
213  inline double get_m11() const {return m11;}
214 
220  inline double get_m20() const {return m20;}
221 
227  inline double get_m02() const {return m02;}
228 
234  inline double get_mu11() const {return mu11;}
235 
241  inline double get_mu02() const {return mu02;}
242 
248  inline double get_mu20() const {return mu20;}
249 
253  inline vpImagePoint getCenter() const {return iPc; }
254 
258  inline double getA() const {return a; }
259 
263  inline double getB() const {return b; }
264 
268  inline double getE() const {return e; }
269 
273  void getEquationParam(double &A, double &B, double &E) { A = a; B = b; E = e; }
274 
278  inline double getSmallestAngle() { return alpha1; }
279 
283  inline double getHighestAngle() { return alpha2; }
284 
294  void setThresholdRobust(const double threshold){
295  if(threshold<0){
296  thresholdWeight = 0;
297  }else if(threshold>1){
298  thresholdWeight = 1;
299  }else{
300  thresholdWeight = threshold;
301  }
302  }
303 
304 
305 
306 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
307 public:
308 #else
309 protected:
310 #endif
311 
318  double a;
320  double b;
322  double e;
323 
324 protected:
330  double alpha1 ;
332  double alpha2 ;
334  double ce;
336  double se;
338  std::list<double> angle;
340  double m00;
342  double mu11,mu20, mu02;
344  double m10,m01;
346  double m11,m02,m20;
351 
352 private:
354  bool circle ;
355 
356  void computeAngle(vpImagePoint pt1, vpImagePoint pt2);
357  void sample(const vpImage<unsigned char>&image);
358  void reSample(const vpImage<unsigned char> &I) ;
359  void leastSquare() ;
360  void updateTheta();
361  void suppressPoints() ;
362  void seekExtremities(const vpImage<unsigned char> &I) ;
363  void setExtremities();
364  void getParameters() ;
365  void computeMoments();
366 
367 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
368 
372  void computeAngle(int ip1, int jp1,int ip2, int jp2) ;
373  void computeAngle(int ip1, int jp1, double &alpha1,
374  int ip2, int jp2, double &alpha2) ;
376 #endif //VISP_BUILD_DEPRECATED_FUNCTIONS
377 
378 //Static Function
379 public:
380  static void display(const vpImage<unsigned char>& I, const vpImagePoint &center,
381  const double &A, const double &B, const double &E,
382  const double & smallalpha, const double &highalpha,
383  const vpColor &color = vpColor::green,
384  unsigned int thickness=1);
385  static void display(const vpImage<vpRGBa>& I, const vpImagePoint &center,
386  const double &A, const double &B, const double &E,
387  const double & smallalpha, const double &highalpha,
388  const vpColor &color = vpColor::green,
389  unsigned int thickness=1);
390 
391 };
392 
393 #endif
double a
is the semiminor axis of the ellipse.
Definition: vpMeEllipse.h:318
double expecteddensity
Expected number of me to track along the ellipse.
Definition: vpMeEllipse.h:350
double e
is the angle made by the major axis and the i axis of the image frame .
Definition: vpMeEllipse.h:322
double thresholdWeight
Threshold for the robust least square.
Definition: vpMeEllipse.h:348
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
int getExpectedDensity()
Definition: vpMeEllipse.h:152
vpImagePoint iP1
The coordinates of the point corresponding to the smallest angle. More things about the are given a...
Definition: vpMeEllipse.h:326
double getHighestAngle()
Definition: vpMeEllipse.h:283
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:258
double mu20
Definition: vpMeEllipse.h:342
static const vpColor green
Definition: vpColor.h:170
double get_mu02() const
Definition: vpMeEllipse.h:241
double b
is the semimajor axis of the ellipse.
Definition: vpMeEllipse.h:320
double se
Value of sin(e).
Definition: vpMeEllipse.h:336
double get_m02() const
Definition: vpMeEllipse.h:227
double m20
Definition: vpMeEllipse.h:346
void display(const vpImage< unsigned char > &I)
Definition: vpMeEllipse.h:159
double get_mu20() const
Definition: vpMeEllipse.h:248
vpImagePoint iP2
The coordinates of the point corresponding to the highest angle. More things about the are given at...
Definition: vpMeEllipse.h:328
vpImagePoint iPc
The coordinates of the ellipse center.
Definition: vpMeEllipse.h:316
double getE() const
Definition: vpMeEllipse.h:268
double alpha1
The smallest angle.
Definition: vpMeEllipse.h:330
double getB() const
Definition: vpMeEllipse.h:263
void setThresholdRobust(const double threshold)
Definition: vpMeEllipse.h:294
double get_m01() const
Definition: vpMeEllipse.h:206
void track(const vpImage< unsigned char > &I)
Track sampled pixels.
double m10
First order raw moments.
Definition: vpMeEllipse.h:344
Contains abstract elements for a Distance to Feature type feature.
Definition: vpMeTracker.h:71
vpColVector K
Definition: vpMeEllipse.h:314
double m00
Surface.
Definition: vpMeEllipse.h:340
double get_mu11() const
Definition: vpMeEllipse.h:234
double get_m00() const
Definition: vpMeEllipse.h:192
void getEquationParam(double &A, double &B, double &E)
Definition: vpMeEllipse.h:273
std::list< double > angle
Stores the value of the angle for each vpMeSite.
Definition: vpMeEllipse.h:338
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:220
double getSmallestAngle()
Definition: vpMeEllipse.h:278
void initTracking(const vpImage< unsigned char > &I)
void setCircle(bool is_circle)
Definition: vpMeEllipse.h:185
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
double alpha2
The highest angle.
Definition: vpMeEllipse.h:332
double get_m10() const
Definition: vpMeEllipse.h:199
virtual void display(const vpImage< unsigned char > &I, vpColor col)=0
vpImagePoint getCenter() const
Definition: vpMeEllipse.h:253
double ce
Value of cos(e).
Definition: vpMeEllipse.h:334
double get_m11() const
Definition: vpMeEllipse.h:213