Visual Servoing Platform  version 3.4.0
vpMeEllipse.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Moving edges.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
44 #ifndef vpMeEllipse_HH
45 #define vpMeEllipse_HH
46 
47 #include <visp3/core/vpColVector.h>
48 #include <visp3/core/vpMatrix.h>
49 
50 #include <visp3/core/vpImagePoint.h>
51 #include <visp3/me/vpMeSite.h>
52 #include <visp3/me/vpMeTracker.h>
53 
54 #include <visp3/core/vpColor.h>
55 #include <visp3/core/vpImage.h>
56 
57 #include <list>
58 #include <math.h>
59 
97 class VISP_EXPORT vpMeEllipse : public vpMeTracker
98 {
99 public:
100  vpMeEllipse();
101  vpMeEllipse(const vpMeEllipse &me_ellipse);
102  virtual ~vpMeEllipse();
103 
104  void display(const vpImage<unsigned char> &I, vpColor col);
105 
115  inline vpColVector get_nij() const
116  {
117  vpColVector nij(3);
118  nij[0] = m_n20;
119  nij[1] = m_n11;
120  nij[2] = m_n02;
121 
122  return nij;
123  }
124 
134  inline vpColVector get_ABE() const
135  {
136  vpColVector ABE(3);
137  ABE[0] = a;
138  ABE[1] = b;
139  ABE[2] = e;
140 
141  return ABE;
142  }
143 
152  inline double getArea() const { return m00; }
153 
159  inline vpImagePoint getCenter() const { return iPc; }
160 
164  unsigned int getExpectedDensity() const { return m_expectedDensity; }
165 
172  inline vpImagePoint getFirstEndpoint() const { return iP1; }
173 
180  inline double getHighestAngle() const { return m_alphamax; }
181 
188  inline vpImagePoint getSecondEndpoint() const { return iP2; }
189 
196  inline double getSmallestAngle() const { return m_alphamin; }
197 
198  void initTracking(const vpImage<unsigned char> &I, bool trackArc = false);
199  void initTracking(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP, bool trackArc = false);
200  void initTracking(const vpImage<unsigned char> &I, const vpColVector &param, vpImagePoint *pt1 = NULL, const vpImagePoint *pt2 = NULL);
201  void printParameters() const;
202 
206  void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
207  {
208  iP1 = pt1;
209  iP2 = pt2;
210  }
211 
221  void setThresholdRobust(double threshold)
222  {
223  if (threshold < 0) {
224  thresholdWeight = 0;
225  } else if (threshold > 1) {
226  thresholdWeight = 1;
227  } else {
228  thresholdWeight = threshold;
229  }
230  }
231 
232  void track(const vpImage<unsigned char> &I);
233 
234 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
235 
245  vp_deprecated inline double getA() const { return a; }
246 
253  vp_deprecated inline double getB() const { return b; }
254 
262  vp_deprecated inline double getE() const { return e; }
263 
274  vp_deprecated inline double get_m00() const { return m00; }
275 
282  vp_deprecated inline double get_m10() const { return m10; }
283 
290  vp_deprecated inline double get_m01() const { return m01; }
291 
298  vp_deprecated inline double get_m11() const { return m11; }
299 
306  vp_deprecated inline double get_m20() const { return m20; }
307 
314  vp_deprecated inline double get_m02() const { return m02; }
315 
321  vp_deprecated inline double get_mu11() const { return mu11; }
322 
328  vp_deprecated inline double get_mu02() const { return mu02; }
329 
335  vp_deprecated inline double get_mu20() const { return mu20; }
340  vp_deprecated void getEquationParam(double &A, double &B, double &E)
341  {
342  A = a;
343  B = b;
344  E = e;
345  }
346  vp_deprecated void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &center_p, double a_p, double b_p, double e_p,
347  double low_alpha, double high_alpha);
348  vp_deprecated void initTracking(const vpImage<unsigned char> &I, unsigned int n, vpImagePoint *iP);
349  vp_deprecated void initTracking(const vpImage<unsigned char> &I, unsigned int n, unsigned *i, unsigned *j);
351 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS
352 
353 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
354 public:
355 #else
356 protected:
357 #endif
358 
365  double a;
367  double b;
371  double e;
372 
373 protected:
385  double alpha1;
390  double alpha2;
392  double ce;
394  double se;
396  std::list<double> angle;
398  double m00;
399 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
400  double mu11, mu20, mu02;
403  double m10, m01;
405  double m11, m02, m20;
406 #endif
407 
410 
411 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
412  double expecteddensity;
414 #endif
415 
419  double m_alphamin;
423  double m_alphamax;
425  double m_uc;
427  double m_vc;
429  double m_n20, m_n11, m_n02;
431  unsigned int m_expectedDensity;
433  unsigned int m_numberOfGoodPoints;
437  double m_arcEpsilon;
438 
439 protected:
440  void computeAbeFromNij();
441  double computeAngleOnEllipse(const vpImagePoint &pt) const;
442  void computeKiFromNij();
443  void computeNijFromAbe();
444  void computePointOnEllipse(const double ang, vpImagePoint &iP);
445  double computeTheta(const vpImagePoint &iP) const;
446  double computeTheta(double u, double v) const;
447  void getParameters();
448  void leastSquare(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP); // FC : new
449  void leastSquareRobust(const vpImage<unsigned char> &I);
450  unsigned int plugHoles(const vpImage<unsigned char> &I);
451  virtual void sample(const vpImage<unsigned char> &I, bool doNotTrack=false);
452  void updateTheta();
453 
454 private:
455 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
456  void computeMoments();
457 #endif
458 
459  // Static Function
460 public:
461  static void display(const vpImage<unsigned char> &I, const vpImagePoint &center,
462  const double &A, const double &B, const double &E,
463  const double &smallalpha, const double &highalpha,
464  const vpColor &color = vpColor::green, unsigned int thickness = 1);
465  static void display(const vpImage<vpRGBa> &I, const vpImagePoint &center,
466  const double &A, const double &B, const double &E,
467  const double &smallalpha, const double &highalpha,
468  const vpColor &color = vpColor::green, unsigned int thickness = 1);
469 };
470 
471 #endif
vp_deprecated void getEquationParam(double &A, double &B, double &E)
Definition: vpMeEllipse.h:340
vpImagePoint getFirstEndpoint() const
Definition: vpMeEllipse.h:172
double a
is the semimajor axis of the ellipse.
Definition: vpMeEllipse.h:365
double getSmallestAngle() const
Definition: vpMeEllipse.h:196
double m_alphamin
Definition: vpMeEllipse.h:419
bool m_trackArc
Track an arc of ellipse (true) or a complete one (false).
Definition: vpMeEllipse.h:435
double m_arcEpsilon
Epsilon value used to check if arc angles are the same.
Definition: vpMeEllipse.h:437
vpColVector get_nij() const
Definition: vpMeEllipse.h:115
double thresholdWeight
Threshold on the weights for the robust least square.
Definition: vpMeEllipse.h:409
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:157
vp_deprecated double getB() const
Definition: vpMeEllipse.h:253
double m_uc
Value of u coordinate of iPc.
Definition: vpMeEllipse.h:425
vpImagePoint iP1
Definition: vpMeEllipse.h:377
vpImagePoint getSecondEndpoint() const
Definition: vpMeEllipse.h:188
Class that tracks an ellipse using moving edges.
Definition: vpMeEllipse.h:97
vp_deprecated double get_m02() const
Definition: vpMeEllipse.h:314
static const vpColor green
Definition: vpColor.h:220
vp_deprecated double getA() const
Definition: vpMeEllipse.h:245
double b
is the semiminor axis of the ellipse.
Definition: vpMeEllipse.h:367
vp_deprecated double get_m00() const
Definition: vpMeEllipse.h:274
double se
Value of sin(e).
Definition: vpMeEllipse.h:394
double getHighestAngle() const
Definition: vpMeEllipse.h:180
double m20
Definition: vpMeEllipse.h:405
vpImagePoint iP2
Definition: vpMeEllipse.h:381
vpImagePoint iPc
The coordinates of the ellipse center.
Definition: vpMeEllipse.h:363
double alpha1
Definition: vpMeEllipse.h:385
double getArea() const
Definition: vpMeEllipse.h:152
unsigned int m_numberOfGoodPoints
Number of correct points tracked along the ellipse.
Definition: vpMeEllipse.h:433
void track(const vpImage< unsigned char > &I)
Track sampled pixels.
double m_alphamax
Definition: vpMeEllipse.h:423
double m10
First order raw moments.
Definition: vpMeEllipse.h:403
Contains abstract elements for a Distance to Feature type feature.
Definition: vpMeTracker.h:65
vpColVector K
Definition: vpMeEllipse.h:361
virtual void sample(const vpImage< unsigned char > &image, bool doNotTrack=false)=0
Sample pixels at a given interval.
vp_deprecated double get_m10() const
Definition: vpMeEllipse.h:282
double m00
Ellipse area.
Definition: vpMeEllipse.h:398
vp_deprecated double get_mu02() const
Definition: vpMeEllipse.h:328
vp_deprecated double get_m11() const
Definition: vpMeEllipse.h:298
std::list< double > angle
Stores the value in increasing order of the angle on the ellipse for each vpMeSite ...
Definition: vpMeEllipse.h:396
vp_deprecated double get_mu11() const
Definition: vpMeEllipse.h:321
vp_deprecated double get_m20() const
Definition: vpMeEllipse.h:306
unsigned int m_expectedDensity
Expected number of points to track along the ellipse.
Definition: vpMeEllipse.h:431
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
Definition: vpMeEllipse.h:206
void initTracking(const vpImage< unsigned char > &I)
vpColVector get_ABE() const
Definition: vpMeEllipse.h:134
unsigned int getExpectedDensity() const
Definition: vpMeEllipse.h:164
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
void setThresholdRobust(double threshold)
Definition: vpMeEllipse.h:221
double alpha2
Definition: vpMeEllipse.h:390
double m_vc
Value of v coordinate of iPc.
Definition: vpMeEllipse.h:427
vp_deprecated double getE() const
Definition: vpMeEllipse.h:262
vp_deprecated double get_m01() const
Definition: vpMeEllipse.h:290
virtual void display(const vpImage< unsigned char > &I, vpColor col)=0
vpImagePoint getCenter() const
Definition: vpMeEllipse.h:159
double ce
Value of cos(e).
Definition: vpMeEllipse.h:392
vp_deprecated double get_mu20() const
Definition: vpMeEllipse.h:335
double m_n20
Second order centered and normalized moments.
Definition: vpMeEllipse.h:429