Visual Servoing Platform  version 3.0.0
vpDot.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 
54 #include <math.h>
55 #include <fstream>
56 #include <list>
57 #include <vector>
58 
59 #ifdef VISP_USE_MSVC
60 # pragma comment(linker, "/STACK:256000000") // Increase max recursion depth
61 #endif
62 
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;
160  double m20;
169  double m02;
178  double mu11;
183  double mu20;
188  double mu02;
194  vpDot() ;
195  vpDot(const vpImagePoint &ip) ;
196  vpDot(const vpDot& d) ;
197  virtual ~vpDot() ;
198 
199  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
200  unsigned int thickness=1) const;
201 
209  inline vpRect getBBox() const {
210  vpRect bbox;
211 
212  bbox.setRect(this->u_min,
213  this->v_min,
214  this->u_max - this->u_min + 1,
215  this->v_max - this->v_min + 1);
216 
217  return (bbox);
218  };
224  inline vpImagePoint getCog() const {
225  return cog;
226  }
227 
233  inline std::list<vpImagePoint> getEdges() const {
234  return this->ip_edges_list;
235  };
236 
245  inline std::list<vpImagePoint> getConnexities() const {
246  return this->ip_connexities_list;
247  };
248 
249  inline double getGamma() const {return this->gamma;};
257  double getGrayLevelPrecision() const {return grayLevelPrecision;}
258  double getMaxDotSize() const {
259  return this->maxDotSizePercentage;
260  }
264  double getMeanGrayLevel() const {
265  return (this->mean_gray_level);
266  };
267 
275  inline unsigned int getWidth() const {
276  return (this->u_max - this->u_min + 1);
277  };
278 
286  inline unsigned int getHeight() const {
287  return (this->v_max - this->v_min + 1);
288  };
289 
290  void initTracking(const vpImage<unsigned char> &I) ;
291  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
292  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip,
293  unsigned int gray_level_min, unsigned int gray_level_max);
294 
295  vpDot& operator =(const vpDot& d) ;
296  bool operator ==(const vpDot& d);
297  bool operator !=(const vpDot& d);
298  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot& d);
299 
300  void print(std::ostream& os) { os << *this << std::endl ; }
301 
305  inline void setCog(const vpImagePoint &ip) {
306  this->cog = ip;
307  }
308 
323  void setComputeMoments(const bool activate) { compute_moment = activate; }
324 
328  void setConnexity(vpConnexityType type) {this->connexityType = type; };
329  void setMaxDotSize(double percentage) ;
330  void setGrayLevelMin( const unsigned int &level_min ) {
331  this->gray_level_min = level_min;
332  };
333  void setGrayLevelMax( const unsigned int &level_max ) {
334  this->gray_level_max = level_max;
335  };
336  void setGrayLevelPrecision( const double & grayLevelPrecision );
337 
351  void setGraphics(const bool activate) { graphics = activate ; }
357  void setGraphicsThickness(unsigned int t) {this->thickness = t;};
358 
359  void track(const vpImage<unsigned char> & I) ;
360  void track(const vpImage<unsigned char> & I, vpImagePoint &ip) ;
361 
362 private:
364  std::list<vpImagePoint> ip_connexities_list;
365 
367  std::list<vpImagePoint> ip_edges_list;
368 
373  vpConnexityType connexityType;
374 
376  vpImagePoint cog;
377 
378  // Bounding box
379  unsigned int u_min, u_max, v_min, v_max;
380 
381  // Flag used to allow display
382  bool graphics ;
383 
384  unsigned int thickness; // Graphics thickness
385 
386  double maxDotSizePercentage;
387  unsigned char gray_level_out;
388 
389  double mean_gray_level; // Mean gray level of the dot
390  unsigned int gray_level_min; // left threshold for binarisation
391  unsigned int gray_level_max; // right threshold for binarisation
392  double grayLevelPrecision; //precision of the gray level of the dot.
393  //It is a double precision float witch value is in ]0,1].
394  //1 means full precision, whereas values close to 0 show a very bad 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,
403  double &mean_value, double &u_cog, double &v_cog, double &n);
404  bool connexe(const vpImage<unsigned char>& I,unsigned int u,unsigned int v,
405  double &mean_value, double &u_cog, 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,
414  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
415  unsigned int thickness=1);
416 } ;
417 
418 #endif
419 
420 
421 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:65
double mu20
Definition: vpDot.h:183
void setConnexity(vpConnexityType type)
Definition: vpDot.h:328
unsigned int getHeight() const
Definition: vpDot.h:286
double m10
Definition: vpDot.h:144
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
std::list< vpImagePoint > getConnexities() const
Definition: vpDot.h:245
void print(std::ostream &os)
Definition: vpDot.h:300
void setGrayLevelMin(const unsigned int &level_min)
Definition: vpDot.h:330
double m00
Definition: vpDot.h:130
vpConnexityType
Definition: vpDot.h:121
double mu11
Definition: vpDot.h:178
double mu02
Definition: vpDot.h:188
static const unsigned int SPIRAL_SEARCH_SIZE
Definition: vpDot.h:128
double m20
Definition: vpDot.h:160
double m11
Definition: vpDot.h:151
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:233
vpImagePoint getCog() const
Definition: vpDot.h:224
double m01
Definition: vpDot.h:137
double getGrayLevelPrecision() const
Definition: vpDot.h:257
vpRect getBBox() const
Definition: vpDot.h:209
unsigned int getWidth() const
Definition: vpDot.h:275
void setGraphicsThickness(unsigned int t)
Definition: vpDot.h:357
double m02
Definition: vpDot.h:169
double getMaxDotSize() const
Definition: vpDot.h:258
double getMeanGrayLevel() const
Definition: vpDot.h:264
void setGraphics(const bool activate)
Definition: vpDot.h:351
void setGrayLevelMax(const unsigned int &level_max)
Definition: vpDot.h:333
void init()
Default initialization.
Definition: vpTracker.cpp:50
double getGamma() const
Definition: vpDot.h:249
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:115
void setComputeMoments(const bool activate)
Definition: vpDot.h:323
Defines a rectangle in the plane.
Definition: vpRect.h:81
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:252
void setCog(const vpImagePoint &ip)
Definition: vpDot.h:305