Visual Servoing Platform  version 3.6.1 under development (2024-04-18)
vpDot.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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  * Track a white dot.
33  *
34 *****************************************************************************/
35 
41 #ifndef vpDot_hh
42 #define vpDot_hh
43 
44 #include <visp3/core/vpConfig.h>
45 #include <visp3/core/vpDisplay.h>
46 #include <visp3/core/vpImage.h>
47 #include <visp3/core/vpImagePoint.h>
48 #include <visp3/core/vpPolygon.h>
49 #include <visp3/core/vpRect.h>
50 #include <visp3/core/vpTracker.h>
51 
52 #include <fstream>
53 #include <list>
54 #include <math.h>
55 #include <vector>
56 
57 #ifdef VISP_USE_MSVC
58 #pragma comment(linker, "/STACK:256000000") // Increase max recursion depth
59 #endif
60 
111 class VISP_EXPORT vpDot : public vpTracker
112 {
113 public:
117  typedef enum
118  {
119  CONNEXITY_4,
121  CONNEXITY_8
123  } vpConnexityType;
124 
125 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
126 public:
127 #else
128 private:
129 #endif
130  static const unsigned int SPIRAL_SEARCH_SIZE;
132  double m00;
139  double m01;
146  double m10;
153  double m11;
160  double m20;
167  double m02;
174  double mu11;
179  double mu20;
184  double mu02;
190 public:
191  vpDot();
192  explicit vpDot(const vpImagePoint &ip);
193  vpDot(const vpDot &d);
194  virtual ~vpDot() vp_override;
195 
196  void display(const vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1) const;
197 
207  inline vpColVector get_nij() const
208  {
209  vpColVector nij(3);
210  nij[0] = mu20 / m00;
211  nij[1] = mu11 / m00;
212  nij[2] = mu02 / m00;
213 
214  return nij;
215  }
216 
222  inline double getArea() const { return m00; }
223 
229  inline vpRect getBBox() const
230  {
231  vpRect bbox;
232 
233  bbox.setRect(this->u_min, this->v_min, this->u_max - this->u_min + 1, this->v_max - this->v_min + 1);
234 
235  return (bbox);
236  };
242  inline vpImagePoint getCog() const { return cog; }
243 
250  inline std::list<vpImagePoint> getEdges() const { return this->ip_edges_list; };
251 
258  inline std::list<vpImagePoint> getConnexities() const { return this->ip_connexities_list; };
259 
260  inline double getGamma() const { return this->gamma; };
261 
267  double getGrayLevelPrecision() const { return grayLevelPrecision; }
268  double getMaxDotSize() const { return this->maxDotSizePercentage; }
269 
273  double getMeanGrayLevel() const { return (this->mean_gray_level); };
274 
278  vpPolygon getPolygon() const { return (vpPolygon(ip_edges_list)); };
279 
285  inline unsigned int getWidth() const { return (this->u_max - this->u_min + 1); };
286 
292  inline unsigned int getHeight() const { return (this->v_max - this->v_min + 1); };
293 
294  void initTracking(const vpImage<unsigned char> &I);
295  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
296  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int gray_level_min,
297  unsigned int gray_level_max);
298 
299  vpDot &operator=(const vpDot &d);
300  bool operator==(const vpDot &d) const;
301  bool operator!=(const vpDot &d) const;
302  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpDot &d);
303 
304  void print(std::ostream &os) { os << *this << std::endl; }
305 
309  inline void setCog(const vpImagePoint &ip) { this->cog = ip; }
310 
324  void setComputeMoments(bool activate) { compute_moment = activate; }
325 
329  void setConnexity(vpConnexityType type) { this->connexityType = type; };
330  void setMaxDotSize(double percentage);
331  void setGrayLevelMin(const unsigned int &level_min) { this->gray_level_min = level_min; };
332  void setGrayLevelMax(const unsigned int &level_max) { this->gray_level_max = level_max; };
333  void setGrayLevelPrecision(const double &grayLevelPrecision);
334 
349  void setGraphics(bool activate) { graphics = activate; }
356  void setGraphicsThickness(unsigned int t) { this->thickness = t; };
357 
358  void track(const vpImage<unsigned char> &I);
359  void track(const vpImage<unsigned char> &I, vpImagePoint &ip);
360 
361 private:
363  std::list<vpImagePoint> ip_connexities_list;
364 
366  std::list<vpImagePoint> ip_edges_list;
367 
372  vpConnexityType connexityType;
373 
375  vpImagePoint cog;
376 
377  // Bounding box
378  unsigned int u_min, u_max, v_min, v_max;
379 
380  // Flag used to allow display
381  bool graphics;
382 
383  unsigned int thickness; // Graphics thickness
384 
385  double maxDotSizePercentage;
386  unsigned char gray_level_out;
387 
388  double mean_gray_level; // Mean gray level of the dot
389  unsigned int gray_level_min; // left threshold for binarization
390  unsigned int gray_level_max; // right threshold for binarization
391  double grayLevelPrecision; // precision of the gray level of the dot.
392  // It is a double precision float witch value is in ]0,1].
393  // 1 means full precision, whereas values close to 0 show a very bad
394  // precision
395  double gamma;
397  bool compute_moment;
398  double nbMaxPoint;
399 
400  void init();
401  void setGrayLevelOut();
402  bool connexe(const vpImage<unsigned char> &I, unsigned int u, unsigned int v, double &mean_value, double &u_cog,
403  double &v_cog, double &n);
404  bool connexe(const vpImage<unsigned char> &I, unsigned int u, unsigned int v, double &mean_value, double &u_cog,
405  double &v_cog, double &n, std::vector<bool> &checkTab);
406  void COG(const vpImage<unsigned char> &I, double &u, double &v);
407 
408  // Static Functions
409 public:
410  static void display(const vpImage<unsigned char> &I, const vpImagePoint &cog,
411  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
412  unsigned int thickness = 1);
413  static void display(const vpImage<vpRGBa> &I, const vpImagePoint &cog, const std::list<vpImagePoint> &edges_list,
414  vpColor color = vpColor::red, unsigned int thickness = 1);
415 };
416 
417 #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 red
Definition: vpColor.h:211
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.
Definition: vpDot.h:112
double mu02
Definition: vpDot.h:184
vpRect getBBox() const
Definition: vpDot.h:229
double m10
Definition: vpDot.h:146
std::list< vpImagePoint > getConnexities() const
Definition: vpDot.h:258
unsigned int getWidth() const
Definition: vpDot.h:285
double mu11
Definition: vpDot.h:174
double m01
Definition: vpDot.h:139
void setGraphics(bool activate)
Definition: vpDot.h:349
void setCog(const vpImagePoint &ip)
Definition: vpDot.h:309
void setGraphicsThickness(unsigned int t)
Definition: vpDot.h:356
double getArea() const
Definition: vpDot.h:222
double getMeanGrayLevel() const
Definition: vpDot.h:273
double mu20
Definition: vpDot.h:179
double m11
Definition: vpDot.h:153
std::list< vpImagePoint > getEdges() const
Definition: vpDot.h:250
double m02
Definition: vpDot.h:167
double getMaxDotSize() const
Definition: vpDot.h:268
void print(std::ostream &os)
Definition: vpDot.h:304
vpPolygon getPolygon() const
Definition: vpDot.h:278
void setGrayLevelMax(const unsigned int &level_max)
Definition: vpDot.h:332
void setConnexity(vpConnexityType type)
Definition: vpDot.h:329
void setGrayLevelMin(const unsigned int &level_min)
Definition: vpDot.h:331
void setComputeMoments(bool activate)
Definition: vpDot.h:324
static const unsigned int SPIRAL_SEARCH_SIZE
Definition: vpDot.h:130
double getGrayLevelPrecision() const
Definition: vpDot.h:267
double m00
Definition: vpDot.h:132
double m20
Definition: vpDot.h:160
vpConnexityType
Definition: vpDot.h:118
double getGamma() const
Definition: vpDot.h:260
vpImagePoint getCog() const
Definition: vpDot.h:242
unsigned int getHeight() const
Definition: vpDot.h:292
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
Definition of the vpImage class member functions.
Definition: vpImage.h:69
Defines a generic 2D polygon.
Definition: vpPolygon.h:97
Defines a rectangle in the plane.
Definition: vpRect.h:76
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:330
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:59
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:50
void init()
Default initialization.
Definition: vpTracker.cpp:44