Visual Servoing Platform  version 3.6.1 under development (2024-04-24)
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 
52 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
53 #include <optional>
54 #endif
55 
93 class VISP_EXPORT vpMeEllipse : public vpMeTracker
94 {
95 public:
99  vpMeEllipse();
100 
104  vpMeEllipse(const vpMeEllipse &me_ellipse);
105 
109  virtual ~vpMeEllipse() vp_override;
110 
121  void display(const vpImage<unsigned char> &I, const vpColor &col, unsigned int thickness = 1);
122 
132  inline vpColVector get_nij() const
133  {
134  vpColVector nij(3);
135  nij[0] = m_n20;
136  nij[1] = m_n11;
137  nij[2] = m_n02;
138 
139  return nij;
140  }
141 
151  inline vpColVector get_ABE() const
152  {
153  vpColVector ABE(3);
154  ABE[0] = m_a;
155  ABE[1] = m_b;
156  ABE[2] = m_e;
157 
158  return ABE;
159  }
160 
169  inline double getArea() const { return m_m00; }
170 
176  inline vpImagePoint getCenter() const { return m_iPc; }
177 
181  unsigned int getExpectedDensity() const { return m_expectedDensity; }
182 
186  unsigned int getNumberOfGoodPoints() const { return m_numberOfGoodPoints; }
187 
194  inline vpImagePoint getFirstEndpoint() const { return m_iP1; }
195 
202  inline double getHighestAngle() const { return m_alphamax; }
203 
210  inline vpImagePoint getSecondEndpoint() const { return m_iP2; }
211 
218  inline double getSmallestAngle() const { return m_alphamin; }
219 
233  void initTracking(const vpImage<unsigned char> &I, bool trackCircle = false, bool trackArc = false);
234 
254 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
255  void initTracking(const vpImage<unsigned char> &I, std::optional<std::vector<vpImagePoint>> &opt_ips, bool trackCircle = false, bool trackArc = false);
256 #else
257  void initTracking(const vpImage<unsigned char> &I, std::vector<vpImagePoint> *opt_ips, bool trackCircle = false, bool trackArc = false);
258 #endif
259 
277  void initTracking(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP, bool trackCircle = false,
278  bool trackArc = false);
279 
294  void initTracking(const vpImage<unsigned char> &I, const vpColVector &param, vpImagePoint *pt1 = nullptr,
295  const vpImagePoint *pt2 = nullptr, bool trackCircle = false);
296 
301  void printParameters() const;
302 
306  void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
307  {
308  m_iP1 = pt1;
309  m_iP2 = pt2;
310  }
311 
321  void setThresholdRobust(double threshold)
322  {
323  if (threshold < 0) {
324  m_thresholdWeight = 0;
325  }
326  else if (threshold > 1) {
327  m_thresholdWeight = 1;
328  }
329  else {
330  m_thresholdWeight = threshold;
331  }
332  }
333 
338  void track(const vpImage<unsigned char> &I);
339 
356  static void displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &A, const double &B,
357  const double &E, const double &smallalpha, const double &highalpha,
358  const vpColor &color = vpColor::green, unsigned int thickness = 1);
359 
376  static void displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &A, const double &B,
377  const double &E, const double &smallalpha, const double &highalpha,
378  const vpColor &color = vpColor::green, unsigned int thickness = 1);
379 
380 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
381  // Marked deprecated since they override vpMeTracker::display(). Warning detected by mingw64
385  vp_deprecated static void display(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &A, const double &B,
386  const double &E, const double &smallalpha, const double &highalpha,
387  const vpColor &color = vpColor::green, unsigned int thickness = 1);
388 
392  vp_deprecated static void display(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &A, const double &B,
393  const double &E, const double &smallalpha, const double &highalpha,
394  const vpColor &color = vpColor::green, unsigned int thickness = 1);
395 #endif
396 
397 protected:
405  double m_a;
407  double m_b;
411  double m_e;
412 
424  double m_alpha1;
429  double m_alpha2;
431  double m_ce;
433  double m_se;
435  std::list<double> m_angleList;
437  double m_m00;
438 
441 
445  double m_alphamin;
449  double m_alphamax;
451  double m_uc;
453  double m_vc;
455  double m_n20;
457  double m_n11;
459  double m_n02;
461  unsigned int m_expectedDensity;
463  unsigned int m_numberOfGoodPoints;
469  double m_arcEpsilon;
470 
477  void computeAbeFromNij();
478 
484  double computeAngleOnEllipse(const vpImagePoint &pt) const;
485 
492  void computeKiFromNij();
493 
499  void computeNijFromAbe();
500 
508  void computePointOnEllipse(const double angle, vpImagePoint &iP);
509 
517  double computeTheta(const vpImagePoint &iP) const;
518 
526  double computeTheta(double u, double v) const;
527 
537  void getParameters();
538 
546  void leastSquare(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP);
547 
556  unsigned int leastSquareRobust(const vpImage<unsigned char> &I);
557 
569  unsigned int plugHoles(const vpImage<unsigned char> &I);
570 
582  virtual void sample(const vpImage<unsigned char> &I, bool doNotTrack = false) vp_override;
583 
589  void updateTheta();
590 };
591 
592 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
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:94
double m_n20
Second order centered and normalized moments .
Definition: vpMeEllipse.h:455
double m_arcEpsilon
Epsilon value used to check if arc angles are the same.
Definition: vpMeEllipse.h:469
double m_e
Definition: vpMeEllipse.h:411
double getHighestAngle() const
Definition: vpMeEllipse.h:202
double m_alpha2
Definition: vpMeEllipse.h:429
vpImagePoint m_iPc
The coordinates of the ellipse center.
Definition: vpMeEllipse.h:403
double getSmallestAngle() const
Definition: vpMeEllipse.h:218
double m_vc
Value of v coordinate of iPc.
Definition: vpMeEllipse.h:453
unsigned int m_numberOfGoodPoints
Number of correct points tracked along the ellipse.
Definition: vpMeEllipse.h:463
double m_uc
Value of u coordinate of iPc.
Definition: vpMeEllipse.h:451
bool m_trackCircle
Track a circle (true) or an ellipse (false).
Definition: vpMeEllipse.h:465
void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
Definition: vpMeEllipse.h:306
vpColVector m_K
Definition: vpMeEllipse.h:401
double m_m00
Ellipse area.
Definition: vpMeEllipse.h:437
vpImagePoint getSecondEndpoint() const
Definition: vpMeEllipse.h:210
vpImagePoint getFirstEndpoint() const
Definition: vpMeEllipse.h:194
double m_alphamin
Definition: vpMeEllipse.h:445
void setThresholdRobust(double threshold)
Definition: vpMeEllipse.h:321
vpColVector get_ABE() const
Definition: vpMeEllipse.h:151
unsigned int getNumberOfGoodPoints() const
Definition: vpMeEllipse.h:186
std::list< double > m_angleList
Stores the value in increasing order of the angle on the ellipse for each vpMeSite.
Definition: vpMeEllipse.h:435
bool m_trackArc
Track an arc of ellipse/circle (true) or a complete one (false).
Definition: vpMeEllipse.h:467
double m_a
is the semi major axis of the ellipse.
Definition: vpMeEllipse.h:405
vpImagePoint getCenter() const
Definition: vpMeEllipse.h:176
double m_alpha1
Definition: vpMeEllipse.h:424
double m_b
is the semi minor axis of the ellipse.
Definition: vpMeEllipse.h:407
double m_alphamax
Definition: vpMeEllipse.h:449
vpColVector get_nij() const
Definition: vpMeEllipse.h:132
double m_se
Value of sin(e).
Definition: vpMeEllipse.h:433
double m_n02
Second order centered and normalized moments .
Definition: vpMeEllipse.h:459
unsigned int getExpectedDensity() const
Definition: vpMeEllipse.h:181
unsigned int m_expectedDensity
Expected number of points to track along the ellipse.
Definition: vpMeEllipse.h:461
double getArea() const
Definition: vpMeEllipse.h:169
vpImagePoint m_iP2
Definition: vpMeEllipse.h:420
double m_n11
Second order centered and normalized moments .
Definition: vpMeEllipse.h:457
vpImagePoint m_iP1
Definition: vpMeEllipse.h:416
double m_ce
Value of cos(e).
Definition: vpMeEllipse.h:431
double m_thresholdWeight
Threshold on the weights for the robust least square.
Definition: vpMeEllipse.h:440
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)