ViSP  2.8.0
vpDot.h
1 /****************************************************************************
2  *
3  * $Id: vpDot.h 4317 2013-07-17 09:40:17Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 
118 class VISP_EXPORT vpDot : public vpTracker
119 {
120 public :
124  typedef enum {
125  CONNEXITY_4,
127  CONNEXITY_8
129  } vpConnexityType;
130 
131  static const unsigned int SPIRAL_SEARCH_SIZE;
133  double m00;
140  double m01;
147  double m10;
154  double m11;
163  double m20;
172  double m02;
181  double mu11;
186  double mu20;
191  double mu02;
197  vpDot() ;
198  vpDot(const vpImagePoint &ip) ;
199  vpDot(const vpDot& d) ;
200  virtual ~vpDot() ;
201 
202  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
203  unsigned int thickness=1);
204 
212  inline vpRect getBBox() {
213  vpRect bbox;
214 
215  bbox.setRect(this->u_min,
216  this->v_min,
217  this->u_max - this->u_min + 1,
218  this->v_max - this->v_min + 1);
219 
220  return (bbox);
221  };
227  inline vpImagePoint getCog() const {
228  return cog;
229  }
230 
236  inline std::list<vpImagePoint> getEdges() {
237  return this->ip_edges_list;
238  };
239 
248  inline std::list<vpImagePoint> getConnexities() {
249  return this->ip_connexities_list;
250  };
251 
252  inline double getGamma() {return this->gamma;};
260  double getGrayLevelPrecision() const {return grayLevelPrecision;}
261  double getMaxDotSize(){
262  return this->maxDotSizePercentage;
263  }
267  double getMeanGrayLevel() {
268  return (this->mean_gray_level);
269  };
270 
278  inline unsigned int getWidth() const {
279  return (this->u_max - this->u_min + 1);
280  };
281 
289  inline unsigned int getHeight() const {
290  return (this->v_max - this->v_min + 1);
291  };
292 
293  void initTracking(const vpImage<unsigned char> &I) ;
294  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
295  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip,
296  unsigned int gray_level_min, unsigned int gray_level_max);
297 
298  vpDot& operator =(const vpDot& d) ;
299  bool operator ==(const vpDot& d);
300  bool operator !=(const vpDot& d);
306  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot& d) {
307  return (os << "(" << d.getCog() << ")" ) ;
308  } ;
309 
310  void print(std::ostream& os) { os << *this << std::endl ; }
311 
315  inline void setCog(const vpImagePoint &cog) {
316  this->cog = cog;
317  }
318 
333  void setComputeMoments(const bool activate) { compute_moment = activate; }
334 
338  void setConnexity(vpConnexityType connexityType) {this->connexityType = connexityType; };
339  void setMaxDotSize(double percentage) ;
340  void setGrayLevelMin( const unsigned int &gray_level_min ) {
341  this->gray_level_min = gray_level_min;
342  };
343  void setGrayLevelMax( const unsigned int &gray_level_max ) {
344  this->gray_level_max = gray_level_max;
345  };
346  void setGrayLevelPrecision( const double & grayLevelPrecision );
347 
361  void setGraphics(const bool activate) { graphics = activate ; }
367  void setGraphicsThickness(unsigned int thickness) {this->thickness = thickness;};
368 
369  void track(const vpImage<unsigned char> & I) ;
370  void track(const vpImage<unsigned char> & I, vpImagePoint &ip) ;
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  unsigned int thickness; // Graphics thickness
395 
396  double maxDotSizePercentage;
397  unsigned char gray_level_out;
398 
399  double mean_gray_level; // Mean gray level of the dot
400  unsigned int gray_level_min; // left threshold for binarisation
401  unsigned int gray_level_max; // right threshold for binarisation
402  double grayLevelPrecision; //precision of the gray level of the dot.
403  //It is a double precision float witch value is in ]0,1].
404  //1 means full precision, whereas values close to 0 show a very bad precision
405  double gamma ;
407  bool compute_moment ;
408  double nbMaxPoint;
409 
410  void init() ;
411  void setGrayLevelOut();
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);
414  bool connexe(const vpImage<unsigned char>& I,unsigned int u,unsigned int v,
415  double &mean_value, double &u_cog, double &v_cog, double &n,std::vector<bool> &checkTab);
416  void COG(const vpImage<unsigned char> &I,double& u, double& v) ;
417 
418 //Static Functions
419 public:
420  static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
421  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
422  unsigned int thickness=1);
423  static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
424  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
425  unsigned int thickness=1);
426 
427 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
428 
441  vp_deprecated void getEdges(std::list<vpImagePoint> &edges_list) {
442  edges_list = this->ip_edges_list;
443  };
444 
456  vp_deprecated void getConnexities(vpList<vpImagePoint> &connexities_list) {
457  // convert a vpList in a std::list
458  connexities_list.kill();
459  std::list<vpImagePoint>::const_iterator it;
460  for (it = ip_connexities_list.begin(); it != ip_connexities_list.end(); ++it) {
461  connexities_list += *it;
462  }
463  };
464 #endif
465 } ;
466 
467 #endif
468 
469 
470 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:72
double mu20
Definition: vpDot.h:186
double getMeanGrayLevel()
Definition: vpDot.h:267
unsigned int getHeight() const
Definition: vpDot.h:289
double m10
Definition: vpDot.h:147
Provide simple list management.
Definition: vpList.h:112
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
vp_deprecated void getEdges(std::list< vpImagePoint > &edges_list)
Definition: vpDot.h:441
vp_deprecated void getConnexities(vpList< vpImagePoint > &connexities_list)
Definition: vpDot.h:456
void print(std::ostream &os)
Definition: vpDot.h:310
double m00
Definition: vpDot.h:133
vpConnexityType
Definition: vpDot.h:124
double mu11
Definition: vpDot.h:181
void kill()
Destroy the list.
Definition: vpList.h:694
double mu02
Definition: vpDot.h:191
void setGrayLevelMax(const unsigned int &gray_level_max)
Definition: vpDot.h:343
static const unsigned int SPIRAL_SEARCH_SIZE
Definition: vpDot.h:131
double m20
Definition: vpDot.h:163
double m11
Definition: vpDot.h:154
double getMaxDotSize()
Definition: vpDot.h:261
static const vpColor red
Definition: vpColor.h:167
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:69
void setGrayLevelMin(const unsigned int &gray_level_min)
Definition: vpDot.h:340
vpImagePoint getCog() const
Definition: vpDot.h:227
double m01
Definition: vpDot.h:140
void setRect(double left, double top, double width, double height)
Definition: vpRect.h:234
double getGrayLevelPrecision() const
Definition: vpDot.h:260
void setCog(const vpImagePoint &cog)
Definition: vpDot.h:315
unsigned int getWidth() const
Definition: vpDot.h:278
double m02
Definition: vpDot.h:172
std::list< vpImagePoint > getConnexities()
Definition: vpDot.h:248
void setGraphics(const bool activate)
Definition: vpDot.h:361
std::list< vpImagePoint > getEdges()
Definition: vpDot.h:236
void init()
Default initialization.
Definition: vpTracker.cpp:54
double getGamma()
Definition: vpDot.h:252
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:118
vpRect getBBox()
Definition: vpDot.h:212
void setComputeMoments(const bool activate)
Definition: vpDot.h:333
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:338
void setGraphicsThickness(unsigned int thickness)
Definition: vpDot.h:367