ViSP  2.10.0
vpDot.h
1 /****************************************************************************
2  *
3  * $Id: vpDot.h 4943 2014-11-03 13:51:09Z 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/vpConfig.h>
52 #include <visp/vpImage.h>
53 #include <visp/vpDisplay.h>
54 #include <visp/vpTracker.h>
55 #include <visp/vpRect.h>
56 #include <visp/vpImagePoint.h>
57 
58 #include <math.h>
59 #include <fstream>
60 #include <list>
61 #include <vector>
62 
63 #ifdef VISP_USE_MSVC
64 # pragma comment(linker, "/STACK:256000000") // Increase max recursion depth
65 #endif
66 
119 class VISP_EXPORT vpDot : public vpTracker
120 {
121 public :
125  typedef enum {
126  CONNEXITY_4,
128  CONNEXITY_8
130  } vpConnexityType;
131 
132  static const unsigned int SPIRAL_SEARCH_SIZE;
134  double m00;
141  double m01;
148  double m10;
155  double m11;
164  double m20;
173  double m02;
182  double mu11;
187  double mu20;
192  double mu02;
198  vpDot() ;
199  vpDot(const vpImagePoint &ip) ;
200  vpDot(const vpDot& d) ;
201  virtual ~vpDot() ;
202 
203  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
204  unsigned int thickness=1) const;
205 
213  inline vpRect getBBox() const {
214  vpRect bbox;
215 
216  bbox.setRect(this->u_min,
217  this->v_min,
218  this->u_max - this->u_min + 1,
219  this->v_max - this->v_min + 1);
220 
221  return (bbox);
222  };
228  inline vpImagePoint getCog() const {
229  return cog;
230  }
231 
237  inline std::list<vpImagePoint> getEdges() const {
238  return this->ip_edges_list;
239  };
240 
249  inline std::list<vpImagePoint> getConnexities() const {
250  return this->ip_connexities_list;
251  };
252 
253  inline double getGamma() const {return this->gamma;};
261  double getGrayLevelPrecision() const {return grayLevelPrecision;}
262  double getMaxDotSize() const {
263  return this->maxDotSizePercentage;
264  }
268  double getMeanGrayLevel() const {
269  return (this->mean_gray_level);
270  };
271 
279  inline unsigned int getWidth() const {
280  return (this->u_max - this->u_min + 1);
281  };
282 
290  inline unsigned int getHeight() const {
291  return (this->v_max - this->v_min + 1);
292  };
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,
297  unsigned int gray_level_min, unsigned int gray_level_max);
298 
299  vpDot& operator =(const vpDot& d) ;
300  bool operator ==(const vpDot& d);
301  bool operator !=(const vpDot& d);
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) {
310  this->cog = ip;
311  }
312 
327  void setComputeMoments(const bool activate) { compute_moment = activate; }
328 
332  void setConnexity(vpConnexityType type) {this->connexityType = type; };
333  void setMaxDotSize(double percentage) ;
334  void setGrayLevelMin( const unsigned int &level_min ) {
335  this->gray_level_min = level_min;
336  };
337  void setGrayLevelMax( const unsigned int &level_max ) {
338  this->gray_level_max = level_max;
339  };
340  void setGrayLevelPrecision( const double & grayLevelPrecision );
341 
355  void setGraphics(const bool activate) { graphics = activate ; }
361  void setGraphicsThickness(unsigned int t) {this->thickness = t;};
362 
363  void track(const vpImage<unsigned char> & I) ;
364  void track(const vpImage<unsigned char> & I, vpImagePoint &ip) ;
365 
366 private:
368  std::list<vpImagePoint> ip_connexities_list;
369 
371  std::list<vpImagePoint> ip_edges_list;
372 
377  vpConnexityType connexityType;
378 
380  vpImagePoint cog;
381 
382  // Bounding box
383  unsigned int u_min, u_max, v_min, v_max;
384 
385  // Flag used to allow display
386  bool graphics ;
387 
388  unsigned int thickness; // Graphics thickness
389 
390  double maxDotSizePercentage;
391  unsigned char gray_level_out;
392 
393  double mean_gray_level; // Mean gray level of the dot
394  unsigned int gray_level_min; // left threshold for binarisation
395  unsigned int gray_level_max; // right threshold for binarisation
396  double grayLevelPrecision; //precision of the gray level of the dot.
397  //It is a double precision float witch value is in ]0,1].
398  //1 means full precision, whereas values close to 0 show a very bad precision
399  double gamma ;
401  bool compute_moment ;
402  double nbMaxPoint;
403 
404  void init() ;
405  void setGrayLevelOut();
406  bool connexe(const vpImage<unsigned char>& I,unsigned int u,unsigned int v,
407  double &mean_value, double &u_cog, double &v_cog, double &n);
408  bool connexe(const vpImage<unsigned char>& I,unsigned int u,unsigned int v,
409  double &mean_value, double &u_cog, double &v_cog, double &n,std::vector<bool> &checkTab);
410  void COG(const vpImage<unsigned char> &I,double& u, double& v) ;
411 
412 //Static Functions
413 public:
414  static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
415  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
416  unsigned int thickness=1);
417  static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
418  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
419  unsigned int thickness=1);
420 } ;
421 
422 #endif
423 
424 
425 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:69
double mu20
Definition: vpDot.h:187
void setConnexity(vpConnexityType type)
Definition: vpDot.h:332
unsigned int getHeight() const
Definition: vpDot.h:290
double m10
Definition: vpDot.h:148
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
std::list< vpImagePoint > getConnexities() const
Definition: vpDot.h:249
void print(std::ostream &os)
Definition: vpDot.h:304
void setGrayLevelMin(const unsigned int &level_min)
Definition: vpDot.h:334
double m00
Definition: vpDot.h:134
vpConnexityType
Definition: vpDot.h:125
double mu11
Definition: vpDot.h:182
double mu02
Definition: vpDot.h:192
static const unsigned int SPIRAL_SEARCH_SIZE
Definition: vpDot.h:132
double m20
Definition: vpDot.h:164
double m11
Definition: vpDot.h:155
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:237
vpImagePoint getCog() const
Definition: vpDot.h:228
double m01
Definition: vpDot.h:141
double getGrayLevelPrecision() const
Definition: vpDot.h:261
vpRect getBBox() const
Definition: vpDot.h:213
unsigned int getWidth() const
Definition: vpDot.h:279
void setGraphicsThickness(unsigned int t)
Definition: vpDot.h:361
double m02
Definition: vpDot.h:173
double getMaxDotSize() const
Definition: vpDot.h:262
double getMeanGrayLevel() const
Definition: vpDot.h:268
void setGraphics(const bool activate)
Definition: vpDot.h:355
void setGrayLevelMax(const unsigned int &level_max)
Definition: vpDot.h:337
void init()
Default initialization.
Definition: vpTracker.cpp:54
double getGamma() const
Definition: vpDot.h:253
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:119
void setComputeMoments(const bool activate)
Definition: vpDot.h:327
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:93
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:256
void setCog(const vpImagePoint &ip)
Definition: vpDot.h:309