Visual Servoing Platform  version 3.6.1 under development (2025-02-01)
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 
122  void display(const vpImage<unsigned char> &I, const vpColor &col, unsigned int thickness = 1);
123 
133  void display(const vpImage<vpRGBa> &I, const vpColor &col, unsigned int thickness = 1);
134 
144  inline vpColVector get_nij() const
145  {
146  vpColVector nij(3);
147  const unsigned int index_0 = 0;
148  const unsigned int index_1 = 1;
149  const unsigned int index_2 = 2;
150  nij[index_0] = m_n20;
151  nij[index_1] = m_n11;
152  nij[index_2] = m_n02;
153 
154  return nij;
155  }
156 
166  inline vpColVector get_ABE() const
167  {
168  vpColVector ABE(3);
169  const unsigned int index_0 = 0;
170  const unsigned int index_1 = 1;
171  const unsigned int index_2 = 2;
172  ABE[index_0] = m_a;
173  ABE[index_1] = m_b;
174  ABE[index_2] = m_e;
175 
176  return ABE;
177  }
178 
187  inline double getArea() const { return m_m00; }
188 
194  inline vpImagePoint getCenter() const { return m_iPc; }
195 
199  unsigned int getExpectedDensity() const { return m_expectedDensity; }
200 
204  unsigned int getNumberOfGoodPoints() const { return m_numberOfGoodPoints; }
205 
212  inline vpImagePoint getFirstEndpoint() const { return m_iP1; }
213 
220  inline double getHighestAngle() const { return m_alphamax; }
221 
228  inline vpImagePoint getSecondEndpoint() const { return m_iP2; }
229 
236  inline double getSmallestAngle() const { return m_alphamin; }
237 
251  void initTracking(const vpImage<unsigned char> &I, bool trackCircle = false, bool trackArc = false);
252 
272 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
273  void initTracking(const vpImage<unsigned char> &I, std::optional<std::vector<vpImagePoint>> &opt_ips, bool trackCircle = false, bool trackArc = false);
274 #else
275  void initTracking(const vpImage<unsigned char> &I, std::vector<vpImagePoint> *opt_ips, bool trackCircle = false, bool trackArc = false);
276 #endif
277 
295  void initTracking(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP, bool trackCircle = false,
296  bool trackArc = false);
297 
312  void initTracking(const vpImage<unsigned char> &I, const vpColVector &param, vpImagePoint *pt1 = nullptr,
313  const vpImagePoint *pt2 = nullptr, bool trackCircle = false);
314 
319  void printParameters() const;
320 
324  void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
325  {
326  m_iP1 = pt1;
327  m_iP2 = pt2;
328  }
329 
339  void setThresholdRobust(double threshold)
340  {
341  if (threshold < 0) {
342  m_thresholdWeight = 0;
343  }
344  else if (threshold > 1) {
345  m_thresholdWeight = 1;
346  }
347  else {
348  m_thresholdWeight = threshold;
349  }
350  }
351 
356  void track(const vpImage<unsigned char> &I);
357 
374  static void displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &A, const double &B,
375  const double &E, const double &smallalpha, const double &highalpha,
376  const vpColor &color = vpColor::green, unsigned int thickness = 1);
377 
394  static void displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &A, const double &B,
395  const double &E, const double &smallalpha, const double &highalpha,
396  const vpColor &color = vpColor::green, unsigned int thickness = 1);
397 
398 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
399  // Marked deprecated since they override vpMeTracker::display(). Warning detected by mingw64
403  VP_DEPRECATED static void display(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &A, const double &B,
404  const double &E, const double &smallalpha, const double &highalpha,
405  const vpColor &color = vpColor::green, unsigned int thickness = 1);
406 
410  VP_DEPRECATED static void display(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &A, const double &B,
411  const double &E, const double &smallalpha, const double &highalpha,
412  const vpColor &color = vpColor::green, unsigned int thickness = 1);
413 #endif
414 
415 protected:
423  double m_a;
425  double m_b;
429  double m_e;
430 
442  double m_alpha1;
447  double m_alpha2;
449  double m_ce;
451  double m_se;
453  std::list<double> m_angleList;
455  double m_m00;
456 
459 
463  double m_alphamin;
467  double m_alphamax;
469  double m_uc;
471  double m_vc;
473  double m_n20;
475  double m_n11;
477  double m_n02;
479  unsigned int m_expectedDensity;
481  unsigned int m_numberOfGoodPoints;
487  double m_arcEpsilon;
488 
495  void computeAbeFromNij();
496 
502  double computeAngleOnEllipse(const vpImagePoint &pt) const;
503 
510  void computeKiFromNij();
511 
517  void computeNijFromAbe();
518 
526  void computePointOnEllipse(const double angle, vpImagePoint &iP);
527 
535  double computeTheta(const vpImagePoint &iP) const;
536 
544  double computeTheta(double u, double v) const;
545 
555  void getParameters();
556 
564  void leastSquare(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &iP);
565 
574  unsigned int leastSquareRobust(const vpImage<unsigned char> &I);
575 
586  void leastSquareRobustCircle(const double &um, const double &vm, unsigned int &k, vpColVector &w);
587 
598  void leastSquareRobustEllipse(const double &um, const double &vm, unsigned int &k, vpColVector &w);
599 
611  unsigned int plugHoles(const vpImage<unsigned char> &I);
612 
624  virtual void sample(const vpImage<unsigned char> &I, bool doNotTrack = false) VP_OVERRIDE;
625 
631  void updateTheta();
632 };
633 
634 END_VISP_NAMESPACE
635 
636 #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:201
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:473
double m_arcEpsilon
Epsilon value used to check if arc angles are the same.
Definition: vpMeEllipse.h:487
double m_e
Definition: vpMeEllipse.h:429
double getHighestAngle() const
Definition: vpMeEllipse.h:220
double m_alpha2
Definition: vpMeEllipse.h:447
vpImagePoint m_iPc
The coordinates of the ellipse center.
Definition: vpMeEllipse.h:421
double getSmallestAngle() const
Definition: vpMeEllipse.h:236
double m_vc
Value of v coordinate of iPc.
Definition: vpMeEllipse.h:471
unsigned int m_numberOfGoodPoints
Number of correct points tracked along the ellipse.
Definition: vpMeEllipse.h:481
double m_uc
Value of u coordinate of iPc.
Definition: vpMeEllipse.h:469
bool m_trackCircle
Track a circle (true) or an ellipse (false).
Definition: vpMeEllipse.h:483
void setEndpoints(const vpImagePoint &pt1, const vpImagePoint &pt2)
Definition: vpMeEllipse.h:324
vpColVector m_K
Definition: vpMeEllipse.h:419
double m_m00
Ellipse area.
Definition: vpMeEllipse.h:455
vpImagePoint getSecondEndpoint() const
Definition: vpMeEllipse.h:228
vpImagePoint getFirstEndpoint() const
Definition: vpMeEllipse.h:212
double m_alphamin
Definition: vpMeEllipse.h:463
void setThresholdRobust(double threshold)
Definition: vpMeEllipse.h:339
vpColVector get_ABE() const
Definition: vpMeEllipse.h:166
unsigned int getNumberOfGoodPoints() const
Definition: vpMeEllipse.h:204
std::list< double > m_angleList
Stores the value in increasing order of the angle on the ellipse for each vpMeSite.
Definition: vpMeEllipse.h:453
bool m_trackArc
Track an arc of ellipse/circle (true) or a complete one (false).
Definition: vpMeEllipse.h:485
double m_a
is the semi major axis of the ellipse.
Definition: vpMeEllipse.h:423
vpImagePoint getCenter() const
Definition: vpMeEllipse.h:194
double m_alpha1
Definition: vpMeEllipse.h:442
double m_b
is the semi minor axis of the ellipse.
Definition: vpMeEllipse.h:425
double m_alphamax
Definition: vpMeEllipse.h:467
vpColVector get_nij() const
Definition: vpMeEllipse.h:144
double m_se
Value of sin(e).
Definition: vpMeEllipse.h:451
double m_n02
Second order centered and normalized moments .
Definition: vpMeEllipse.h:477
unsigned int getExpectedDensity() const
Definition: vpMeEllipse.h:199
unsigned int m_expectedDensity
Expected number of points to track along the ellipse.
Definition: vpMeEllipse.h:479
double getArea() const
Definition: vpMeEllipse.h:187
vpImagePoint m_iP2
Definition: vpMeEllipse.h:438
double m_n11
Second order centered and normalized moments .
Definition: vpMeEllipse.h:475
vpImagePoint m_iP1
Definition: vpMeEllipse.h:434
double m_ce
Value of cos(e).
Definition: vpMeEllipse.h:449
double m_thresholdWeight
Threshold on the weights for the robust least square.
Definition: vpMeEllipse.h:458
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)