ViSP  2.9.0
vpDot.h
1 /****************************************************************************
2  *
3  * $Id: vpDot.h 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Track a white dot.
36  *
37  * Authors:
38  * Eric Marchand
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
48 #ifndef vpDot_hh
49 #define vpDot_hh
50 
51 #include <visp/vpImage.h>
52 #include <visp/vpDisplay.h>
53 #include <visp/vpTracker.h>
54 #include <visp/vpRect.h>
55 #include <visp/vpImagePoint.h>
56 
57 #include <math.h>
58 #include <fstream>
59 #include <list>
60 #include <vector>
61 
114 class VISP_EXPORT vpDot : public vpTracker
115 {
116 public :
120  typedef enum {
121  CONNEXITY_4,
123  CONNEXITY_8
125  } vpConnexityType;
126 
127  static const unsigned int SPIRAL_SEARCH_SIZE;
129  double m00;
136  double m01;
143  double m10;
150  double m11;
159  double m20;
168  double m02;
177  double mu11;
182  double mu20;
187  double mu02;
193  vpDot() ;
194  vpDot(const vpImagePoint &ip) ;
195  vpDot(const vpDot& d) ;
196  virtual ~vpDot() ;
197 
198  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
199  unsigned int thickness=1) const;
200 
208  inline vpRect getBBox() const {
209  vpRect bbox;
210 
211  bbox.setRect(this->u_min,
212  this->v_min,
213  this->u_max - this->u_min + 1,
214  this->v_max - this->v_min + 1);
215 
216  return (bbox);
217  };
223  inline vpImagePoint getCog() const {
224  return cog;
225  }
226 
232  inline std::list<vpImagePoint> getEdges() const {
233  return this->ip_edges_list;
234  };
235 
244  inline std::list<vpImagePoint> getConnexities() const {
245  return this->ip_connexities_list;
246  };
247 
248  inline double getGamma() const {return this->gamma;};
256  double getGrayLevelPrecision() const {return grayLevelPrecision;}
257  double getMaxDotSize() const {
258  return this->maxDotSizePercentage;
259  }
263  double getMeanGrayLevel() const {
264  return (this->mean_gray_level);
265  };
266 
274  inline unsigned int getWidth() const {
275  return (this->u_max - this->u_min + 1);
276  };
277 
285  inline unsigned int getHeight() const {
286  return (this->v_max - this->v_min + 1);
287  };
288 
289  void initTracking(const vpImage<unsigned char> &I) ;
290  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
291  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip,
292  unsigned int gray_level_min, unsigned int gray_level_max);
293 
294  vpDot& operator =(const vpDot& d) ;
295  bool operator ==(const vpDot& d);
296  bool operator !=(const vpDot& d);
297  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot& d);
298 
299  void print(std::ostream& os) { os << *this << std::endl ; }
300 
304  inline void setCog(const vpImagePoint &ip) {
305  this->cog = ip;
306  }
307 
322  void setComputeMoments(const bool activate) { compute_moment = activate; }
323 
327  void setConnexity(vpConnexityType type) {this->connexityType = type; };
328  void setMaxDotSize(double percentage) ;
329  void setGrayLevelMin( const unsigned int &level_min ) {
330  this->gray_level_min = level_min;
331  };
332  void setGrayLevelMax( const unsigned int &level_max ) {
333  this->gray_level_max = level_max;
334  };
335  void setGrayLevelPrecision( const double & grayLevelPrecision );
336 
350  void setGraphics(const 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 binarisation
390  unsigned int gray_level_max; // right threshold for binarisation
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 precision
394  double gamma ;
396  bool compute_moment ;
397  double nbMaxPoint;
398 
399  void init() ;
400  void setGrayLevelOut();
401  bool connexe(const vpImage<unsigned char>& I,unsigned int u,unsigned int v,
402  double &mean_value, double &u_cog, double &v_cog, double &n);
403  bool connexe(const vpImage<unsigned char>& I,unsigned int u,unsigned int v,
404  double &mean_value, double &u_cog, double &v_cog, double &n,std::vector<bool> &checkTab);
405  void COG(const vpImage<unsigned char> &I,double& u, double& v) ;
406 
407 //Static Functions
408 public:
409  static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
410  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
411  unsigned int thickness=1);
412  static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
413  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
414  unsigned int thickness=1);
415 } ;
416 
417 #endif
418 
419 
420 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:69
double mu20
Definition: vpDot.h:182
void setConnexity(vpConnexityType type)
Definition: vpDot.h:327
unsigned int getHeight() const
Definition: vpDot.h:285
double m10
Definition: vpDot.h:143
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
std::list< vpImagePoint > getConnexities() const
Definition: vpDot.h:244
void print(std::ostream &os)
Definition: vpDot.h:299
void setGrayLevelMin(const unsigned int &level_min)
Definition: vpDot.h:329
double m00
Definition: vpDot.h:129
vpConnexityType
Definition: vpDot.h:120
double mu11
Definition: vpDot.h:177
double mu02
Definition: vpDot.h:187
static const unsigned int SPIRAL_SEARCH_SIZE
Definition: vpDot.h:127
double m20
Definition: vpDot.h:159
double m11
Definition: vpDot.h:150
static const vpColor red
Definition: vpColor.h:167
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:69
std::list< vpImagePoint > getEdges() const
Definition: vpDot.h:232
vpImagePoint getCog() const
Definition: vpDot.h:223
double m01
Definition: vpDot.h:136
double getGrayLevelPrecision() const
Definition: vpDot.h:256
vpRect getBBox() const
Definition: vpDot.h:208
unsigned int getWidth() const
Definition: vpDot.h:274
void setGraphicsThickness(unsigned int t)
Definition: vpDot.h:356
double m02
Definition: vpDot.h:168
double getMaxDotSize() const
Definition: vpDot.h:257
double getMeanGrayLevel() const
Definition: vpDot.h:263
void setGraphics(const bool activate)
Definition: vpDot.h:350
void setGrayLevelMax(const unsigned int &level_max)
Definition: vpDot.h:332
void init()
Default initialization.
Definition: vpTracker.cpp:54
double getGamma() const
Definition: vpDot.h:248
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:114
void setComputeMoments(const bool activate)
Definition: vpDot.h:322
Defines a rectangle in the plane.
Definition: vpRect.h:85
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:246
void setCog(const vpImagePoint &ip)
Definition: vpDot.h:304