Visual Servoing Platform  version 3.6.1 under development (2024-12-17)
vpMeEllipse.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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 VP_ME_ELLIPSE_H
37 #define VP_ME_ELLIPSE_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 
52 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
53 #include <optional>
54 #endif
55 
56 BEGIN_VISP_NAMESPACE
57 
95 class VISP_EXPORT vpMeEllipse : public vpMeTracker
96 {
97 public:
101  vpMeEllipse();
102 
106  vpMeEllipse(const vpMeEllipse &me_ellipse);
107 
111  virtual ~vpMeEllipse() VP_OVERRIDE;
112 
123  void display(const vpImage<unsigned char> &I, const vpColor &col, unsigned int thickness = 1);
124 
134  inline vpColVector get_nij() const
135  {
136  vpColVector nij(3);
137  const unsigned int index_0 = 0;
138  const unsigned int index_1 = 1;
139  const unsigned int index_2 = 2;
140  nij[index_0] = m_n20;
141  nij[index_1] = m_n11;
142  nij[index_2] = m_n02;
143 
144  return nij;
145  }
146 
156  inline vpColVector get_ABE() const
157  {
158  vpColVector ABE(3);
159  const unsigned int index_0 = 0;
160  const unsigned int index_1 = 1;
161  const unsigned int index_2 = 2;
162  ABE[index_0] = m_a;
163  ABE[index_1] = m_b;
164  ABE[index_2] = m_e;
165 
166  return ABE;
167  }
168 
177  inline double getArea() const { return m_m00; }
178 
184  inline vpImagePoint getCenter() const { return m_iPc; }
185 
189  unsigned int getExpectedDensity() const { return m_expectedDensity; }
190 
194  unsigned int getNumberOfGoodPoints() const { return m_numberOfGoodPoints; }
195 
202  inline vpImagePoint getFirstEndpoint() const { return m_iP1; }
203 
210  inline double getHighestAngle() const { return m_alphamax; }
211 
218  inline vpImagePoint getSecondEndpoint() const { return m_iP2; }
219 
226  inline double getSmallestAngle() const { return m_alphamin; }
227 
241  void initTracking(const vpImage<unsigned char> &I, bool trackCircle = false, bool trackArc = false);
242 
262 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
263  void initTracking(const vpImage<unsigned char> &I, std::optional<std::vector<vpImagePoint>> &opt_ips, bool trackCircle = false, bool trackArc = false);
264 #else
265  void initTracking(const vpImage<unsigned char> &I, std::vector<vpImagePoint> *opt_ips, bool trackCircle = false, bool trackArc = false);
266 #endif
267 
285  void initTracking(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP, bool trackCircle = false,
286  bool trackArc = false);
287 
302  void initTracking(const vpImage<unsigned char> &I, const vpColVector &param, vpImagePoint *pt1 = nullptr,
303  const vpImagePoint *pt2 = nullptr, bool trackCircle = false);
304 
309  void printParameters() const;
310 
314  void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
315  {
316  m_iP1 = pt1;
317  m_iP2 = pt2;
318  }
319 
329  void setThresholdRobust(double threshold)
330  {
331  if (threshold < 0) {
332  m_thresholdWeight = 0;
333  }
334  else if (threshold > 1) {
335  m_thresholdWeight = 1;
336  }
337  else {
338  m_thresholdWeight = threshold;
339  }
340  }
341 
346  void track(const vpImage<unsigned char> &I);
347 
364  static void displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &A, const double &B,
365  const double &E, const double &smallalpha, const double &highalpha,
366  const vpColor &color = vpColor::green, unsigned int thickness = 1);
367 
384  static void displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &A, const double &B,
385  const double &E, const double &smallalpha, const double &highalpha,
386  const vpColor &color = vpColor::green, unsigned int thickness = 1);
387 
388 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
389  // Marked deprecated since they override vpMeTracker::display(). Warning detected by mingw64
393  VP_DEPRECATED static void display(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &A, const double &B,
394  const double &E, const double &smallalpha, const double &highalpha,
395  const vpColor &color = vpColor::green, unsigned int thickness = 1);
396 
400  VP_DEPRECATED static void display(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &A, const double &B,
401  const double &E, const double &smallalpha, const double &highalpha,
402  const vpColor &color = vpColor::green, unsigned int thickness = 1);
403 #endif
404 
405 protected:
413  double m_a;
415  double m_b;
419  double m_e;
420 
432  double m_alpha1;
437  double m_alpha2;
439  double m_ce;
441  double m_se;
443  std::list<double> m_angleList;
445  double m_m00;
446 
449 
453  double m_alphamin;
457  double m_alphamax;
459  double m_uc;
461  double m_vc;
463  double m_n20;
465  double m_n11;
467  double m_n02;
469  unsigned int m_expectedDensity;
471  unsigned int m_numberOfGoodPoints;
477  double m_arcEpsilon;
478 
485  void computeAbeFromNij();
486 
492  double computeAngleOnEllipse(const vpImagePoint &pt) const;
493 
500  void computeKiFromNij();
501 
507  void computeNijFromAbe();
508 
516  void computePointOnEllipse(const double angle, vpImagePoint &iP);
517 
525  double computeTheta(const vpImagePoint &iP) const;
526 
534  double computeTheta(double u, double v) const;
535 
545  void getParameters();
546 
554  void leastSquare(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP);
555 
564  unsigned int leastSquareRobust(const vpImage<unsigned char> &I);
565 
576  void leastSquareRobustCircle(const double &um, const double &vm, unsigned int &k, vpColVector &w);
577 
588  void leastSquareRobustEllipse(const double &um, const double &vm, unsigned int &k, vpColVector &w);
589 
601  unsigned int plugHoles(const vpImage<unsigned char> &I);
602 
614  virtual void sample(const vpImage<unsigned char> &I, bool doNotTrack = false) VP_OVERRIDE;
615 
621  void updateTheta();
622 };
623 
624 END_VISP_NAMESPACE
625 
626 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
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:82
Class that tracks an ellipse using moving edges.
Definition: vpMeEllipse.h:96
double m_n20
Second order centered and normalized moments .
Definition: vpMeEllipse.h:463
double m_arcEpsilon
Epsilon value used to check if arc angles are the same.
Definition: vpMeEllipse.h:477
double m_e
Definition: vpMeEllipse.h:419
double getHighestAngle() const
Definition: vpMeEllipse.h:210
double m_alpha2
Definition: vpMeEllipse.h:437
vpImagePoint m_iPc
The coordinates of the ellipse center.
Definition: vpMeEllipse.h:411
double getSmallestAngle() const
Definition: vpMeEllipse.h:226
double m_vc
Value of v coordinate of iPc.
Definition: vpMeEllipse.h:461
unsigned int m_numberOfGoodPoints
Number of correct points tracked along the ellipse.
Definition: vpMeEllipse.h:471
double m_uc
Value of u coordinate of iPc.
Definition: vpMeEllipse.h:459
bool m_trackCircle
Track a circle (true) or an ellipse (false).
Definition: vpMeEllipse.h:473
void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
Definition: vpMeEllipse.h:314
vpColVector m_K
Definition: vpMeEllipse.h:409
double m_m00
Ellipse area.
Definition: vpMeEllipse.h:445
vpImagePoint getSecondEndpoint() const
Definition: vpMeEllipse.h:218
vpImagePoint getFirstEndpoint() const
Definition: vpMeEllipse.h:202
double m_alphamin
Definition: vpMeEllipse.h:453
void setThresholdRobust(double threshold)
Definition: vpMeEllipse.h:329
vpColVector get_ABE() const
Definition: vpMeEllipse.h:156
unsigned int getNumberOfGoodPoints() const
Definition: vpMeEllipse.h:194
std::list< double > m_angleList
Stores the value in increasing order of the angle on the ellipse for each vpMeSite.
Definition: vpMeEllipse.h:443
bool m_trackArc
Track an arc of ellipse/circle (true) or a complete one (false).
Definition: vpMeEllipse.h:475
double m_a
is the semi major axis of the ellipse.
Definition: vpMeEllipse.h:413
vpImagePoint getCenter() const
Definition: vpMeEllipse.h:184
double m_alpha1
Definition: vpMeEllipse.h:432
double m_b
is the semi minor axis of the ellipse.
Definition: vpMeEllipse.h:415
double m_alphamax
Definition: vpMeEllipse.h:457
vpColVector get_nij() const
Definition: vpMeEllipse.h:134
double m_se
Value of sin(e).
Definition: vpMeEllipse.h:441
double m_n02
Second order centered and normalized moments .
Definition: vpMeEllipse.h:467
unsigned int getExpectedDensity() const
Definition: vpMeEllipse.h:189
unsigned int m_expectedDensity
Expected number of points to track along the ellipse.
Definition: vpMeEllipse.h:469
double getArea() const
Definition: vpMeEllipse.h:177
vpImagePoint m_iP2
Definition: vpMeEllipse.h:428
double m_n11
Second order centered and normalized moments .
Definition: vpMeEllipse.h:465
vpImagePoint m_iP1
Definition: vpMeEllipse.h:424
double m_ce
Value of cos(e).
Definition: vpMeEllipse.h:439
double m_thresholdWeight
Threshold on the weights for the robust least square.
Definition: vpMeEllipse.h:448
Contains abstract elements for a Distance to Feature type feature.
Definition: vpMeTracker.h:62
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)