ViSP  2.6.2
vpDot.h
1 /****************************************************************************
2  *
3  * $Id: vpDot.h 3853 2012-07-17 16:59:39Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
58 # include <visp/vpList.h>
59 #endif
60 
61 #include <math.h>
62 #include <fstream>
63 #include <list>
64 #include <vector>
65 
80 class VISP_EXPORT vpDot : public vpTracker
81 {
82 public :
86  typedef enum {
87  CONNEXITY_4,
89  CONNEXITY_8
91  } vpConnexityType;
92 
93  static const unsigned int SPIRAL_SEARCH_SIZE;
95  double m00;
102  double m01;
109  double m10;
116  double m11;
125  double m20;
134  double m02;
143  double mu11;
148  double mu20;
153  double mu02;
159  vpDot() ;
160  vpDot(const vpImagePoint &ip) ;
161  vpDot(const vpDot& d) ;
162  virtual ~vpDot() ;
163 
164  vpDot& operator =(const vpDot& d) ;
165  bool operator ==(const vpDot& d);
166  bool operator !=(const vpDot& d);
167 
168  void initTracking(const vpImage<unsigned char> &I) ;
169  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
170  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip,
171  unsigned int gray_level_min, unsigned int gray_level_max);
172 
173  void track(const vpImage<unsigned char> & I) ;
174  void track(const vpImage<unsigned char> & I, vpImagePoint &ip) ;
175 
176  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
177  unsigned int thickness=1);
178 
182  inline void setCog(const vpImagePoint &cog) {
183  this->cog = cog;
184  }
185 
200  void setComputeMoments(const bool activate) { compute_moment = activate; }
201 
205  void setConnexity(vpConnexityType connexityType) {this->connexityType = connexityType; };
206  void setMaxDotSize(double percentage) ;
207  void setGrayLevelMin( const unsigned int &gray_level_min ) {
208  this->gray_level_min = gray_level_min;
209  };
210  void setGrayLevelMax( const unsigned int &gray_level_max ) {
211  this->gray_level_max = gray_level_max;
212  };
213  void setGrayLevelPrecision( const double & grayLevelPrecision );
214 
215 
225  void setGraphics(const bool activate) { graphics = activate ; }
226 
234  inline vpRect getBBox() {
235  vpRect bbox;
236 
237  bbox.setRect(this->u_min,
238  this->v_min,
239  this->u_max - this->u_min + 1,
240  this->v_max - this->v_min + 1);
241 
242  return (bbox);
243  };
249  inline vpImagePoint getCog() const {
250  return cog;
251  }
252 
258  inline std::list<vpImagePoint> getEdges() {
259  return this->ip_edges_list;
260  };
261 
270  inline std::list<vpImagePoint> getConnexities() {
271  return this->ip_connexities_list;
272  };
273 
274 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
275 
289  vp_deprecated void getEdges(std::list<vpImagePoint> &edges_list) {
290  edges_list = this->ip_edges_list;
291  };
292 #endif
293 
294  inline double getGamma() {return this->gamma;};
302  double getGrayLevelPrecision() const {return grayLevelPrecision;}
303  double getMaxDotSize(){
304  return this->maxDotSizePercentage;
305  }
309  double getMeanGrayLevel() {
310  return (this->mean_gray_level);
311  };
312 
320  inline unsigned int getWidth() const {
321  return (this->u_max - this->u_min + 1);
322  };
323 
331  inline unsigned int getHeight() const {
332  return (this->v_max - this->v_min + 1);
333  };
334 
340  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot& d) {
341  return (os << "(" << d.getCog() << ")" ) ;
342  } ;
343 
344  void print(std::ostream& os) { os << *this << std::endl ; }
345 
346 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
347 
362  vp_deprecated void getConnexities(vpList<vpImagePoint> &connexities_list) {
363  // convert a vpList in a std::list
364  connexities_list.kill();
365  std::list<vpImagePoint>::const_iterator it;
366  for (it = ip_connexities_list.begin(); it != ip_connexities_list.end(); ++it) {
367  connexities_list += *it;
368  }
369  };
370 #endif
371 
372 private:
374  std::list<vpImagePoint> ip_connexities_list;
375 
377  std::list<vpImagePoint> ip_edges_list;
378 
383  vpConnexityType connexityType;
384 
386  vpImagePoint cog;
387 
388  // Bounding box
389  unsigned int u_min, u_max, v_min, v_max;
390 
391  // Flag used to allow display
392  bool graphics ;
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 } ;
422 
423 #endif
424 
425 /*
426  * Local variables:
427  * c-basic-offset: 2
428  * End:
429  */
430 
431 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:72
double mu20
Definition: vpDot.h:148
double getMeanGrayLevel()
Definition: vpDot.h:309
unsigned int getHeight() const
Definition: vpDot.h:331
double m10
Definition: vpDot.h:109
Provide simple list management.
Definition: vpList.h:112
Class to define colors available for display functionnalities.
Definition: vpColor.h:123
vp_deprecated void getEdges(std::list< vpImagePoint > &edges_list)
Definition: vpDot.h:289
vp_deprecated void getConnexities(vpList< vpImagePoint > &connexities_list)
Definition: vpDot.h:362
void print(std::ostream &os)
Definition: vpDot.h:344
double m00
Definition: vpDot.h:95
vpConnexityType
Definition: vpDot.h:86
double mu11
Definition: vpDot.h:143
void kill()
Destroy the list.
Definition: vpList.h:694
double mu02
Definition: vpDot.h:153
void setGrayLevelMax(const unsigned int &gray_level_max)
Definition: vpDot.h:210
static const unsigned int SPIRAL_SEARCH_SIZE
Definition: vpDot.h:93
double m20
Definition: vpDot.h:125
double m11
Definition: vpDot.h:116
double getMaxDotSize()
Definition: vpDot.h:303
static const vpColor red
Definition: vpColor.h:165
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:69
void setGrayLevelMin(const unsigned int &gray_level_min)
Definition: vpDot.h:207
vpImagePoint getCog() const
Definition: vpDot.h:249
double m01
Definition: vpDot.h:102
void setRect(double left, double top, double width, double height)
Definition: vpRect.h:234
double getGrayLevelPrecision() const
Definition: vpDot.h:302
void setCog(const vpImagePoint &cog)
Definition: vpDot.h:182
unsigned int getWidth() const
Definition: vpDot.h:320
double m02
Definition: vpDot.h:134
std::list< vpImagePoint > getConnexities()
Definition: vpDot.h:270
void setGraphics(const bool activate)
Definition: vpDot.h:225
std::list< vpImagePoint > getEdges()
Definition: vpDot.h:258
void init()
Default initialization.
Definition: vpTracker.cpp:54
double getGamma()
Definition: vpDot.h:294
This tracker is meant to track a dot (connex pixels with same gray level) on a vpImage.
Definition: vpDot.h:80
vpRect getBBox()
Definition: vpDot.h:234
void setComputeMoments(const bool activate)
Definition: vpDot.h:200
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:92
void setConnexity(vpConnexityType connexityType)
Definition: vpDot.h:205