Visual Servoing Platform  version 3.5.1 under development (2023-09-22)
vpMeEllipse.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 
36 #ifndef _vpMeEllipse_h_
37 #define _vpMeEllipse_h_
38 
39 #include <visp3/core/vpColVector.h>
40 #include <visp3/core/vpMatrix.h>
41 
42 #include <visp3/core/vpImagePoint.h>
43 #include <visp3/me/vpMeSite.h>
44 #include <visp3/me/vpMeTracker.h>
45 
46 #include <visp3/core/vpColor.h>
47 #include <visp3/core/vpImage.h>
48 
49 #include <list>
50 #include <math.h>
51 
89 class VISP_EXPORT vpMeEllipse : public vpMeTracker
90 {
91 public:
95  vpMeEllipse();
99  vpMeEllipse(const vpMeEllipse &me_ellipse);
103  virtual ~vpMeEllipse();
114  void display(const vpImage<unsigned char> &I, const vpColor &col, unsigned int thickness = 1);
115 
125  inline vpColVector get_nij() const
126  {
127  vpColVector nij(3);
128  nij[0] = m_n20;
129  nij[1] = m_n11;
130  nij[2] = m_n02;
131 
132  return nij;
133  }
134 
144  inline vpColVector get_ABE() const
145  {
146  vpColVector ABE(3);
147  ABE[0] = a;
148  ABE[1] = b;
149  ABE[2] = e;
150 
151  return ABE;
152  }
153 
162  inline double getArea() const { return m00; }
163 
169  inline vpImagePoint getCenter() const { return iPc; }
170 
174  unsigned int getExpectedDensity() const { return m_expectedDensity; }
175 
179  unsigned int getNumberOfGoodPoints() const { return m_numberOfGoodPoints; }
180 
187  inline vpImagePoint getFirstEndpoint() const { return iP1; }
188 
195  inline double getHighestAngle() const { return m_alphamax; }
196 
203  inline vpImagePoint getSecondEndpoint() const { return iP2; }
204 
211  inline double getSmallestAngle() const { return m_alphamin; }
212 
226  void initTracking(const vpImage<unsigned char> &I, bool trackCircle = false, bool trackArc = false);
227 
245  void initTracking(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP, bool trackCircle = false,
246  bool trackArc = false);
247 
262  void initTracking(const vpImage<unsigned char> &I, const vpColVector &param, vpImagePoint *pt1 = NULL,
263  const vpImagePoint *pt2 = NULL, bool trackCircle = false);
264 
269  void printParameters() const;
270 
274  void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
275  {
276  iP1 = pt1;
277  iP2 = pt2;
278  }
279 
289  void setThresholdRobust(double threshold)
290  {
291  if (threshold < 0) {
292  thresholdWeight = 0;
293  }
294  else if (threshold > 1) {
295  thresholdWeight = 1;
296  }
297  else {
298  thresholdWeight = threshold;
299  }
300  }
301 
306  void track(const vpImage<unsigned char> &I);
307 
308 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
319  vp_deprecated inline double getA() const { return a; }
320 
327  vp_deprecated inline double getB() const { return b; }
328 
336  vp_deprecated inline double getE() const { return e; }
337 
348  vp_deprecated inline double get_m00() const { return m00; }
349 
356  vp_deprecated inline double get_m10() const { return m10; }
357 
364  vp_deprecated inline double get_m01() const { return m01; }
365 
372  vp_deprecated inline double get_m11() const { return m11; }
373 
380  vp_deprecated inline double get_m20() const { return m20; }
381 
388  vp_deprecated inline double get_m02() const { return m02; }
389 
395  vp_deprecated inline double get_mu11() const { return mu11; }
396 
402  vp_deprecated inline double get_mu02() const { return mu02; }
403 
409  vp_deprecated inline double get_mu20() const { return mu20; }
414  vp_deprecated void getEquationParam(double &A, double &B, double &E)
415  {
416  A = a;
417  B = b;
418  E = e;
419  }
420  vp_deprecated void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &center_p, double a_p, double b_p,
421  double e_p, double low_alpha, double high_alpha);
422  vp_deprecated void initTracking(const vpImage<unsigned char> &I, unsigned int n, vpImagePoint *iP);
423  vp_deprecated void initTracking(const vpImage<unsigned char> &I, unsigned int n, unsigned *i, unsigned *j);
425 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS
426 
427 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
428 public:
429 #else
430 protected:
431 #endif
439  double a;
441  double b;
445  double e;
446 
447 protected:
459  double alpha1;
464  double alpha2;
466  double ce;
468  double se;
470  std::list<double> angle;
472  double m00;
473 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
475  double mu11, mu20, mu02;
477  double m10, m01;
479  double m11, m02, m20;
480 #endif
481 
484 
488  double m_alphamin;
492  double m_alphamax;
494  double m_uc;
496  double m_vc;
498  double m_n20;
500  double m_n11;
502  double m_n02;
504  unsigned int m_expectedDensity;
506  unsigned int m_numberOfGoodPoints;
512  double m_arcEpsilon;
513 
514 protected:
521  void computeAbeFromNij();
522 
528  double computeAngleOnEllipse(const vpImagePoint &pt) const;
529 
536  void computeKiFromNij();
537 
543  void computeNijFromAbe();
544 
552  void computePointOnEllipse(const double angle, vpImagePoint &iP);
553 
561  double computeTheta(const vpImagePoint &iP) const;
562 
570  double computeTheta(double u, double v) const;
571 
581  void getParameters();
582 
590  void leastSquare(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP);
591 
600  unsigned int leastSquareRobust(const vpImage<unsigned char> &I);
601 
613  unsigned int plugHoles(const vpImage<unsigned char> &I);
614 
626 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
627  virtual void sample(const vpImage<unsigned char> &I, bool doNotTrack = false) override;
628 #else
629  virtual void sample(const vpImage<unsigned char> &I, bool doNotTrack = false);
630 #endif
631 
637  void updateTheta();
638 
639 private:
640 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
641  void computeMoments();
642 #endif
643 
644  // Static Function
645 public:
662  static void displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &A, const double &B,
663  const double &E, const double &smallalpha, const double &highalpha,
664  const vpColor &color = vpColor::green, unsigned int thickness = 1);
665 
682  static void displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &A, const double &B,
683  const double &E, const double &smallalpha, const double &highalpha,
684  const vpColor &color = vpColor::green, unsigned int thickness = 1);
685 
686 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
687  // Marked deprecated since they override vpMeTracker::display(). Warning detected by mingw64
688  vp_deprecated static void display(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &A, const double &B,
689  const double &E, const double &smallalpha, const double &highalpha,
690  const vpColor &color = vpColor::green, unsigned int thickness = 1);
691  vp_deprecated static void display(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &A, const double &B,
692  const double &E, const double &smallalpha, const double &highalpha,
693  const vpColor &color = vpColor::green, unsigned int thickness = 1);
694 #endif
695 };
696 
697 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:167
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
static const vpColor green
Definition: vpColor.h:214
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
Class that tracks an ellipse using moving edges.
Definition: vpMeEllipse.h:90
double m_n20
Second order centered and normalized moments .
Definition: vpMeEllipse.h:498
double m_arcEpsilon
Epsilon value used to check if arc angles are the same.
Definition: vpMeEllipse.h:512
double m02
Definition: vpMeEllipse.h:479
double a
is the semi major axis of the ellipse.
Definition: vpMeEllipse.h:439
double getHighestAngle() const
Definition: vpMeEllipse.h:195
double se
Value of sin(e).
Definition: vpMeEllipse.h:468
vpImagePoint iP2
Definition: vpMeEllipse.h:455
vpColVector K
Definition: vpMeEllipse.h:435
double getSmallestAngle() const
Definition: vpMeEllipse.h:211
vp_deprecated double get_mu20() const
Definition: vpMeEllipse.h:409
double m_vc
Value of v coordinate of iPc.
Definition: vpMeEllipse.h:496
unsigned int m_numberOfGoodPoints
Number of correct points tracked along the ellipse.
Definition: vpMeEllipse.h:506
vpImagePoint iPc
The coordinates of the ellipse center.
Definition: vpMeEllipse.h:437
std::list< double > angle
Stores the value in increasing order of the angle on the ellipse for each vpMeSite.
Definition: vpMeEllipse.h:470
vp_deprecated double getA() const
Definition: vpMeEllipse.h:319
vp_deprecated double get_m20() const
Definition: vpMeEllipse.h:380
double b
is the semi minor axis of the ellipse.
Definition: vpMeEllipse.h:441
vp_deprecated double get_m11() const
Definition: vpMeEllipse.h:372
double m_uc
Value of u coordinate of iPc.
Definition: vpMeEllipse.h:494
bool m_trackCircle
Track a circle (true) or an ellipse (false).
Definition: vpMeEllipse.h:508
double m01
Definition: vpMeEllipse.h:477
double ce
Value of cos(e).
Definition: vpMeEllipse.h:466
vp_deprecated double get_m00() const
Definition: vpMeEllipse.h:348
void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
Definition: vpMeEllipse.h:274
double m00
Ellipse area.
Definition: vpMeEllipse.h:472
vpImagePoint getSecondEndpoint() const
Definition: vpMeEllipse.h:203
vpImagePoint getFirstEndpoint() const
Definition: vpMeEllipse.h:187
double m_alphamin
Definition: vpMeEllipse.h:488
vp_deprecated void getEquationParam(double &A, double &B, double &E)
Definition: vpMeEllipse.h:414
void setThresholdRobust(double threshold)
Definition: vpMeEllipse.h:289
vpColVector get_ABE() const
Definition: vpMeEllipse.h:144
double mu02
Definition: vpMeEllipse.h:475
vp_deprecated double get_mu11() const
Definition: vpMeEllipse.h:395
unsigned int getNumberOfGoodPoints() const
Definition: vpMeEllipse.h:179
bool m_trackArc
Track an arc of ellipse/circle (true) or a complete one (false).
Definition: vpMeEllipse.h:510
vp_deprecated double get_mu02() const
Definition: vpMeEllipse.h:402
vpImagePoint getCenter() const
Definition: vpMeEllipse.h:169
double m_alphamax
Definition: vpMeEllipse.h:492
vp_deprecated double getB() const
Definition: vpMeEllipse.h:327
vpColVector get_nij() const
Definition: vpMeEllipse.h:125
vp_deprecated double get_m10() const
Definition: vpMeEllipse.h:356
double m_n02
Second order centered and normalized moments .
Definition: vpMeEllipse.h:502
unsigned int getExpectedDensity() const
Definition: vpMeEllipse.h:174
unsigned int m_expectedDensity
Expected number of points to track along the ellipse.
Definition: vpMeEllipse.h:504
vp_deprecated double get_m02() const
Definition: vpMeEllipse.h:388
double alpha2
Definition: vpMeEllipse.h:464
double getArea() const
Definition: vpMeEllipse.h:162
vpImagePoint iP1
Definition: vpMeEllipse.h:451
double m_n11
Second order centered and normalized moments .
Definition: vpMeEllipse.h:500
vp_deprecated double get_m01() const
Definition: vpMeEllipse.h:364
double alpha1
Definition: vpMeEllipse.h:459
double thresholdWeight
Threshold on the weights for the robust least square.
Definition: vpMeEllipse.h:483
vp_deprecated double getE() const
Definition: vpMeEllipse.h:336
Contains abstract elements for a Distance to Feature type feature.
Definition: vpMeTracker.h:60
void initTracking(const vpImage< unsigned char > &I)
virtual void sample(const vpImage< unsigned char > &image, bool doNotTrack=false)=0
void track(const vpImage< unsigned char > &I)
void display(const vpImage< unsigned char > &I)