Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpDot.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Description:
31  * Track a white dot.
32  *
33  * Authors:
34  * Eric Marchand
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
44 #ifndef vpDot_hh
45 #define vpDot_hh
46 
47 #include <visp3/core/vpConfig.h>
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpDisplay.h>
50 #include <visp3/core/vpTracker.h>
51 #include <visp3/core/vpRect.h>
52 #include <visp3/core/vpImagePoint.h>
53 #include <visp3/core/vpPolygon.h>
54 
55 #include <math.h>
56 #include <fstream>
57 #include <list>
58 #include <vector>
59 
60 #ifdef VISP_USE_MSVC
61 # pragma comment(linker, "/STACK:256000000") // Increase max recursion depth
62 #endif
63 
116 class VISP_EXPORT vpDot : public vpTracker
117 {
118 public :
122  typedef enum {
123  CONNEXITY_4,
125  CONNEXITY_8
127  } vpConnexityType;
128 
129  static const unsigned int SPIRAL_SEARCH_SIZE;
131  double m00;
138  double m01;
145  double m10;
152  double m11;
161  double m20;
170  double m02;
179  double mu11;
184  double mu20;
189  double mu02;
195  vpDot() ;
196  vpDot(const vpImagePoint &ip) ;
197  vpDot(const vpDot& d) ;
198  virtual ~vpDot() ;
199 
200  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
201  unsigned int thickness=1) const;
202 
210  inline vpRect getBBox() const {
211  vpRect bbox;
212 
213  bbox.setRect(this->u_min,
214  this->v_min,
215  this->u_max - this->u_min + 1,
216  this->v_max - this->v_min + 1);
217 
218  return (bbox);
219  };
225  inline vpImagePoint getCog() const {
226  return cog;
227  }
228 
234  inline std::list<vpImagePoint> getEdges() const {
235  return this->ip_edges_list;
236  };
237 
246  inline std::list<vpImagePoint> getConnexities() const {
247  return this->ip_connexities_list;
248  };
249 
250  inline double getGamma() const {return this->gamma;};
258  double getGrayLevelPrecision() const {return grayLevelPrecision;}
259  double getMaxDotSize() const {
260  return this->maxDotSizePercentage;
261  }
265  double getMeanGrayLevel() const {
266  return (this->mean_gray_level);
267  };
268 
273  return (vpPolygon(ip_edges_list));
274  };
275 
283  inline unsigned int getWidth() const {
284  return (this->u_max - this->u_min + 1);
285  };
286 
294  inline unsigned int getHeight() const {
295  return (this->v_max - this->v_min + 1);
296  };
297 
298  void initTracking(const vpImage<unsigned char> &I) ;
299  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
300  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip,
301  unsigned int gray_level_min, unsigned int gray_level_max);
302 
303  vpDot& operator =(const vpDot& d) ;
304  bool operator ==(const vpDot& d) const;
305  bool operator !=(const vpDot& d) const;
306  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot& d);
307 
308  void print(std::ostream& os) { os << *this << std::endl ; }
309 
313  inline void setCog(const vpImagePoint &ip) {
314  this->cog = ip;
315  }
316 
331  void setComputeMoments(const bool activate) { compute_moment = activate; }
332 
336  void setConnexity(vpConnexityType type) {this->connexityType = type; };
337  void setMaxDotSize(double percentage) ;
338  void setGrayLevelMin( const unsigned int &level_min ) {
339  this->gray_level_min = level_min;
340  };
341  void setGrayLevelMax( const unsigned int &level_max ) {
342  this->gray_level_max = level_max;
343  };
344  void setGrayLevelPrecision( const double & grayLevelPrecision );
345 
359  void setGraphics(const bool activate) { graphics = activate ; }
365  void setGraphicsThickness(unsigned int t) {this->thickness = t;};
366 
367  void track(const vpImage<unsigned char> & I) ;
368  void track(const vpImage<unsigned char> & I, vpImagePoint &ip) ;
369 
370 private:
372  std::list<vpImagePoint> ip_connexities_list;
373 
375  std::list<vpImagePoint> ip_edges_list;
376 
381  vpConnexityType connexityType;
382 
384  vpImagePoint cog;
385 
386  // Bounding box
387  unsigned int u_min, u_max, v_min, v_max;
388 
389  // Flag used to allow display
390  bool graphics ;
391 
392  unsigned int thickness; // Graphics thickness
393 
394  double maxDotSizePercentage;
395  unsigned char gray_level_out;
396 
397  double mean_gray_level; // Mean gray level of the dot
398  unsigned int gray_level_min; // left threshold for binarisation
399  unsigned int gray_level_max; // right threshold for binarisation
400  double grayLevelPrecision; //precision of the gray level of the dot.
401  //It is a double precision float witch value is in ]0,1].
402  //1 means full precision, whereas values close to 0 show a very bad precision
403  double gamma ;
405  bool compute_moment ;
406  double nbMaxPoint;
407 
408  void init() ;
409  void setGrayLevelOut();
410  bool connexe(const vpImage<unsigned char>& I,unsigned int u,unsigned int v,
411  double &mean_value, double &u_cog, double &v_cog, double &n);
412  bool connexe(const vpImage<unsigned char>& I,unsigned int u,unsigned int v,
413  double &mean_value, double &u_cog, double &v_cog, double &n,std::vector<bool> &checkTab);
414  void COG(const vpImage<unsigned char> &I,double& u, double& v) ;
415 
416 //Static Functions
417 public:
418  static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
419  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
420  unsigned int thickness=1);
421  static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
422  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
423  unsigned int thickness=1);
424 } ;
425 
426 #endif
427 
428 
429 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:65
double mu20
Definition: vpDot.h:184
void setConnexity(vpConnexityType type)
Definition: vpDot.h:336
unsigned int getHeight() const
Definition: vpDot.h:294
double m10
Definition: vpDot.h:145
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
std::list< vpImagePoint > getConnexities() const
Definition: vpDot.h:246
void print(std::ostream &os)
Definition: vpDot.h:308
void setGrayLevelMin(const unsigned int &level_min)
Definition: vpDot.h:338
double m00
Definition: vpDot.h:131
vpConnexityType
Definition: vpDot.h:122
double mu11
Definition: vpDot.h:179
double mu02
Definition: vpDot.h:189
static const unsigned int SPIRAL_SEARCH_SIZE
Definition: vpDot.h:129
double m20
Definition: vpDot.h:161
double m11
Definition: vpDot.h:152
static const vpColor red
Definition: vpColor.h:163
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:66
std::list< vpImagePoint > getEdges() const
Definition: vpDot.h:234
vpImagePoint getCog() const
Definition: vpDot.h:225
Defines a generic 2D polygon.
Definition: vpPolygon.h:99
double m01
Definition: vpDot.h:138
double getGrayLevelPrecision() const
Definition: vpDot.h:258
vpRect getBBox() const
Definition: vpDot.h:210
unsigned int getWidth() const
Definition: vpDot.h:283
void setGraphicsThickness(unsigned int t)
Definition: vpDot.h:365
double m02
Definition: vpDot.h:170
vpPolygon getPolygon() const
Definition: vpDot.h:272
double getMaxDotSize() const
Definition: vpDot.h:259
double getMeanGrayLevel() const
Definition: vpDot.h:265
void setGraphics(const bool activate)
Definition: vpDot.h:359
void setGrayLevelMax(const unsigned int &level_max)
Definition: vpDot.h:341
void init()
Default initialization.
Definition: vpTracker.cpp:50
double getGamma() const
Definition: vpDot.h:250
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:116
void setComputeMoments(const bool activate)
Definition: vpDot.h:331
Defines a rectangle in the plane.
Definition: vpRect.h:82
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:269
void setCog(const vpImagePoint &ip)
Definition: vpDot.h:313