Visual Servoing Platform  version 3.5.1 under development (2023-03-29)
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,
201  const vpImagePoint *pt2 = NULL);
202  void printParameters() const;
203 
207  void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
208  {
209  iP1 = pt1;
210  iP2 = pt2;
211  }
212 
222  void setThresholdRobust(double threshold)
223  {
224  if (threshold < 0) {
225  thresholdWeight = 0;
226  } else if (threshold > 1) {
227  thresholdWeight = 1;
228  } else {
229  thresholdWeight = threshold;
230  }
231  }
232 
233  void track(const vpImage<unsigned char> &I);
234 
235 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
246  vp_deprecated inline double getA() const { return a; }
247 
254  vp_deprecated inline double getB() const { return b; }
255 
263  vp_deprecated inline double getE() const { return e; }
264 
275  vp_deprecated inline double get_m00() const { return m00; }
276 
283  vp_deprecated inline double get_m10() const { return m10; }
284 
291  vp_deprecated inline double get_m01() const { return m01; }
292 
299  vp_deprecated inline double get_m11() const { return m11; }
300 
307  vp_deprecated inline double get_m20() const { return m20; }
308 
315  vp_deprecated inline double get_m02() const { return m02; }
316 
322  vp_deprecated inline double get_mu11() const { return mu11; }
323 
329  vp_deprecated inline double get_mu02() const { return mu02; }
330 
336  vp_deprecated inline double get_mu20() const { return mu20; }
341  vp_deprecated void getEquationParam(double &A, double &B, double &E)
342  {
343  A = a;
344  B = b;
345  E = e;
346  }
347  vp_deprecated void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &center_p, double a_p, double b_p,
348  double e_p, double low_alpha, double high_alpha);
349  vp_deprecated void initTracking(const vpImage<unsigned char> &I, unsigned int n, vpImagePoint *iP);
350  vp_deprecated void initTracking(const vpImage<unsigned char> &I, unsigned int n, unsigned *i, unsigned *j);
352 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS
353 
354 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
355 public:
356 #else
357 protected:
358 #endif
366  double a;
368  double b;
372  double e;
373 
374 protected:
386  double alpha1;
391  double alpha2;
393  double ce;
395  double se;
397  std::list<double> angle;
399  double m00;
400 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
402  double mu11, mu20, mu02;
404  double m10, m01;
406  double m11, m02, m20;
407 #endif
408 
411 
412 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
415 #endif
416 
420  double m_alphamin;
424  double m_alphamax;
426  double m_uc;
428  double m_vc;
430  double m_n20, m_n11, m_n02;
432  unsigned int m_expectedDensity;
434  unsigned int m_numberOfGoodPoints;
438  double m_arcEpsilon;
439 
440 protected:
441  void computeAbeFromNij();
442  double computeAngleOnEllipse(const vpImagePoint &pt) const;
443  void computeKiFromNij();
444  void computeNijFromAbe();
445  void computePointOnEllipse(const double ang, vpImagePoint &iP);
446  double computeTheta(const vpImagePoint &iP) const;
447  double computeTheta(double u, double v) const;
448  void getParameters();
449  void leastSquare(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP); // FC : new
450  void leastSquareRobust(const vpImage<unsigned char> &I);
451  unsigned int plugHoles(const vpImage<unsigned char> &I);
452  virtual void sample(const vpImage<unsigned char> &I, bool doNotTrack = false);
453  void updateTheta();
454 
455 private:
456 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
457  void computeMoments();
458 #endif
459 
460  // Static Function
461 public:
462  static void display(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &A, const double &B,
463  const double &E, 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, const double &A, const double &B,
466  const double &E, const double &smallalpha, const double &highalpha,
467  const vpColor &color = vpColor::green, unsigned int thickness = 1);
468 };
469 
470 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:158
static const vpColor green
Definition: vpColor.h:220
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:89
Class that tracks an ellipse using moving edges.
Definition: vpMeEllipse.h:98
double m_arcEpsilon
Epsilon value used to check if arc angles are the same.
Definition: vpMeEllipse.h:438
double m02
Definition: vpMeEllipse.h:406
double a
is the semimajor axis of the ellipse.
Definition: vpMeEllipse.h:366
double getHighestAngle() const
Definition: vpMeEllipse.h:180
double se
Value of sin(e).
Definition: vpMeEllipse.h:395
vpImagePoint iP2
Definition: vpMeEllipse.h:382
vpColVector K
Definition: vpMeEllipse.h:362
double getSmallestAngle() const
Definition: vpMeEllipse.h:196
vp_deprecated double get_mu20() const
Definition: vpMeEllipse.h:336
double m_vc
Value of v coordinate of iPc.
Definition: vpMeEllipse.h:428
unsigned int m_numberOfGoodPoints
Number of correct points tracked along the ellipse.
Definition: vpMeEllipse.h:434
vpImagePoint iPc
The coordinates of the ellipse center.
Definition: vpMeEllipse.h:364
std::list< double > angle
Stores the value in increasing order of the angle on the ellipse for each vpMeSite .
Definition: vpMeEllipse.h:397
vp_deprecated double getA() const
Definition: vpMeEllipse.h:246
vp_deprecated double get_m20() const
Definition: vpMeEllipse.h:307
double b
is the semiminor axis of the ellipse.
Definition: vpMeEllipse.h:368
double expecteddensity
Expected number of points to track along the ellipse.
Definition: vpMeEllipse.h:414
vp_deprecated double get_m11() const
Definition: vpMeEllipse.h:299
double m_uc
Value of u coordinate of iPc.
Definition: vpMeEllipse.h:426
double m01
Definition: vpMeEllipse.h:404
double ce
Value of cos(e).
Definition: vpMeEllipse.h:393
vp_deprecated double get_m00() const
Definition: vpMeEllipse.h:275
void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
Definition: vpMeEllipse.h:207
double m00
Ellipse area.
Definition: vpMeEllipse.h:399
vpImagePoint getSecondEndpoint() const
Definition: vpMeEllipse.h:188
vpImagePoint getFirstEndpoint() const
Definition: vpMeEllipse.h:172
double m_alphamin
Definition: vpMeEllipse.h:420
vp_deprecated void getEquationParam(double &A, double &B, double &E)
Definition: vpMeEllipse.h:341
void setThresholdRobust(double threshold)
Definition: vpMeEllipse.h:222
vpColVector get_ABE() const
Definition: vpMeEllipse.h:134
double mu02
Definition: vpMeEllipse.h:402
vp_deprecated double get_mu11() const
Definition: vpMeEllipse.h:322
bool m_trackArc
Track an arc of ellipse (true) or a complete one (false).
Definition: vpMeEllipse.h:436
vp_deprecated double get_mu02() const
Definition: vpMeEllipse.h:329
vpImagePoint getCenter() const
Definition: vpMeEllipse.h:159
double m_alphamax
Definition: vpMeEllipse.h:424
vp_deprecated double getB() const
Definition: vpMeEllipse.h:254
vpColVector get_nij() const
Definition: vpMeEllipse.h:115
vp_deprecated double get_m10() const
Definition: vpMeEllipse.h:283
double m_n02
Definition: vpMeEllipse.h:430
unsigned int getExpectedDensity() const
Definition: vpMeEllipse.h:164
unsigned int m_expectedDensity
Expected number of points to track along the ellipse.
Definition: vpMeEllipse.h:432
vp_deprecated double get_m02() const
Definition: vpMeEllipse.h:315
double alpha2
Definition: vpMeEllipse.h:391
double getArea() const
Definition: vpMeEllipse.h:152
vpImagePoint iP1
Definition: vpMeEllipse.h:378
vp_deprecated double get_m01() const
Definition: vpMeEllipse.h:291
double alpha1
Definition: vpMeEllipse.h:386
double thresholdWeight
Threshold on the weights for the robust least square.
Definition: vpMeEllipse.h:410
vp_deprecated double getE() const
Definition: vpMeEllipse.h:263
Contains abstract elements for a Distance to Feature type feature.
Definition: vpMeTracker.h:66
void initTracking(const vpImage< unsigned char > &I)
virtual void sample(const vpImage< unsigned char > &image, bool doNotTrack=false)=0
Sample pixels at a given interval.
void track(const vpImage< unsigned char > &I)
Track sampled pixels.
virtual void display(const vpImage< unsigned char > &I, vpColor col)=0