Visual Servoing Platform  version 3.3.1 under development (2020-10-22)
vpDot.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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  * Authors:
35  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
45 #ifndef vpDot_hh
46 #define vpDot_hh
47 
48 #include <visp3/core/vpConfig.h>
49 #include <visp3/core/vpDisplay.h>
50 #include <visp3/core/vpImage.h>
51 #include <visp3/core/vpImagePoint.h>
52 #include <visp3/core/vpPolygon.h>
53 #include <visp3/core/vpRect.h>
54 #include <visp3/core/vpTracker.h>
55 
56 #include <fstream>
57 #include <list>
58 #include <math.h>
59 #include <vector>
60 
61 #ifdef VISP_USE_MSVC
62 #pragma comment(linker, "/STACK:256000000") // Increase max recursion depth
63 #endif
64 
115 class VISP_EXPORT vpDot : public vpTracker
116 {
117 public:
121  typedef enum {
122  CONNEXITY_4,
124  CONNEXITY_8
126  } vpConnexityType;
127 
128  static const unsigned int SPIRAL_SEARCH_SIZE;
130  double m00;
137  double m01;
144  double m10;
151  double m11;
158  double m20;
165  double m02;
172  double mu11;
177  double mu20;
182  double mu02;
188  vpDot();
189  explicit vpDot(const vpImagePoint &ip);
190  vpDot(const vpDot &d);
191  virtual ~vpDot();
192 
193  void display(const vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1) const;
194 
202  inline vpRect getBBox() const
203  {
204  vpRect bbox;
205 
206  bbox.setRect(this->u_min, this->v_min, this->u_max - this->u_min + 1, this->v_max - this->v_min + 1);
207 
208  return (bbox);
209  };
215  inline vpImagePoint getCog() const { return cog; }
216 
223  inline std::list<vpImagePoint> getEdges() const { return this->ip_edges_list; };
224 
233  inline std::list<vpImagePoint> getConnexities() const { return this->ip_connexities_list; };
234 
235  inline double getGamma() const { return this->gamma; };
243  double getGrayLevelPrecision() const { return grayLevelPrecision; }
244  double getMaxDotSize() const { return this->maxDotSizePercentage; }
248  double getMeanGrayLevel() const { return (this->mean_gray_level); };
249 
253  vpPolygon getPolygon() const { return (vpPolygon(ip_edges_list)); };
254 
262  inline unsigned int getWidth() const { return (this->u_max - this->u_min + 1); };
263 
271  inline unsigned int getHeight() const { return (this->v_max - this->v_min + 1); };
272 
273  void initTracking(const vpImage<unsigned char> &I);
274  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
275  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int gray_level_min,
276  unsigned int gray_level_max);
277 
278  vpDot &operator=(const vpDot &d);
279  bool operator==(const vpDot &d) const;
280  bool operator!=(const vpDot &d) const;
281  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpDot &d);
282 
283  void print(std::ostream &os) { os << *this << std::endl; }
284 
288  inline void setCog(const vpImagePoint &ip) { this->cog = ip; }
289 
305  void setComputeMoments(bool activate) { compute_moment = activate; }
306 
310  void setConnexity(vpConnexityType type) { this->connexityType = type; };
311  void setMaxDotSize(double percentage);
312  void setGrayLevelMin(const unsigned int &level_min) { this->gray_level_min = level_min; };
313  void setGrayLevelMax(const unsigned int &level_max) { this->gray_level_max = level_max; };
314  void setGrayLevelPrecision(const double &grayLevelPrecision);
315 
329  void setGraphics(bool activate) { graphics = activate; }
336  void setGraphicsThickness(unsigned int t) { this->thickness = t; };
337 
338  void track(const vpImage<unsigned char> &I);
339  void track(const vpImage<unsigned char> &I, vpImagePoint &ip);
340 
341 private:
343  std::list<vpImagePoint> ip_connexities_list;
344 
346  std::list<vpImagePoint> ip_edges_list;
347 
352  vpConnexityType connexityType;
353 
355  vpImagePoint cog;
356 
357  // Bounding box
358  unsigned int u_min, u_max, v_min, v_max;
359 
360  // Flag used to allow display
361  bool graphics;
362 
363  unsigned int thickness; // Graphics thickness
364 
365  double maxDotSizePercentage;
366  unsigned char gray_level_out;
367 
368  double mean_gray_level; // Mean gray level of the dot
369  unsigned int gray_level_min; // left threshold for binarisation
370  unsigned int gray_level_max; // right threshold for binarisation
371  double grayLevelPrecision; // precision of the gray level of the dot.
372  // It is a double precision float witch value is in ]0,1].
373  // 1 means full precision, whereas values close to 0 show a very bad
374  // precision
375  double gamma;
377  bool compute_moment;
378  double nbMaxPoint;
379 
380  void init();
381  void setGrayLevelOut();
382  bool connexe(const vpImage<unsigned char> &I, unsigned int u, unsigned int v, double &mean_value, double &u_cog,
383  double &v_cog, double &n);
384  bool connexe(const vpImage<unsigned char> &I, unsigned int u, unsigned int v, double &mean_value, double &u_cog,
385  double &v_cog, double &n, std::vector<bool> &checkTab);
386  void COG(const vpImage<unsigned char> &I, double &u, double &v);
387 
388  // Static Functions
389 public:
390  static void display(const vpImage<unsigned char> &I, const vpImagePoint &cog,
391  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
392  unsigned int thickness = 1);
393  static void display(const vpImage<vpRGBa> &I, const vpImagePoint &cog, const std::list<vpImagePoint> &edges_list,
394  vpColor color = vpColor::red, unsigned int thickness = 1);
395 };
396 
397 #endif
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:53
double mu20
Definition: vpDot.h:177
void setConnexity(vpConnexityType type)
Definition: vpDot.h:310
double m10
Definition: vpDot.h:144
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:157
void setComputeMoments(bool activate)
Definition: vpDot.h:305
double getGrayLevelPrecision() const
Definition: vpDot.h:243
void print(std::ostream &os)
Definition: vpDot.h:283
void setGrayLevelMin(const unsigned int &level_min)
Definition: vpDot.h:312
double m00
Definition: vpDot.h:130
vpConnexityType
Definition: vpDot.h:121
double mu11
Definition: vpDot.h:172
double getMeanGrayLevel() const
Definition: vpDot.h:248
double mu02
Definition: vpDot.h:182
vpPolygon getPolygon() const
Definition: vpDot.h:253
static const unsigned int SPIRAL_SEARCH_SIZE
Definition: vpDot.h:128
double m20
Definition: vpDot.h:158
double m11
Definition: vpDot.h:151
static const vpColor red
Definition: vpColor.h:217
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:64
Defines a generic 2D polygon.
Definition: vpPolygon.h:103
double m01
Definition: vpDot.h:137
vpImagePoint getCog() const
Definition: vpDot.h:215
vpRect getBBox() const
Definition: vpDot.h:202
void setGraphicsThickness(unsigned int t)
Definition: vpDot.h:336
unsigned int getHeight() const
Definition: vpDot.h:271
double m02
Definition: vpDot.h:165
double getGamma() const
Definition: vpDot.h:235
void setGrayLevelMax(const unsigned int &level_max)
Definition: vpDot.h:313
void init()
Default initialization.
Definition: vpTracker.cpp:47
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:115
Defines a rectangle in the plane.
Definition: vpRect.h:79
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
unsigned int getWidth() const
Definition: vpDot.h:262
void setGraphics(bool activate)
Definition: vpDot.h:329
std::list< vpImagePoint > getEdges() const
Definition: vpDot.h:223
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:334
std::list< vpImagePoint > getConnexities() const
Definition: vpDot.h:233
void setCog(const vpImagePoint &ip)
Definition: vpDot.h:288
double getMaxDotSize() const
Definition: vpDot.h:244