ViSP  2.7.0
vpDot.h
1 /****************************************************************************
2  *
3  * $Id: vpDot.h 4092 2013-02-04 10:36:30Z 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 
116 class VISP_EXPORT vpDot : public vpTracker
117 {
118 public :
122  typedef enum {
123  CONNEXITY_4,
125  CONNEXITY_8
127  } vpConnexityType;
128 
129  static const unsigned int SPIRAL_SEARCH_SIZE;
131  double m00;
138  double m01;
145  double m10;
152  double m11;
161  double m20;
170  double m02;
179  double mu11;
184  double mu20;
189  double mu02;
195  vpDot() ;
196  vpDot(const vpImagePoint &ip) ;
197  vpDot(const vpDot& d) ;
198  virtual ~vpDot() ;
199 
200  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
201  unsigned int thickness=1);
202 
210  inline vpRect getBBox() {
211  vpRect bbox;
212 
213  bbox.setRect(this->u_min,
214  this->v_min,
215  this->u_max - this->u_min + 1,
216  this->v_max - this->v_min + 1);
217 
218  return (bbox);
219  };
225  inline vpImagePoint getCog() const {
226  return cog;
227  }
228 
234  inline std::list<vpImagePoint> getEdges() {
235  return this->ip_edges_list;
236  };
237 
246  inline std::list<vpImagePoint> getConnexities() {
247  return this->ip_connexities_list;
248  };
249 
250  inline double getGamma() {return this->gamma;};
258  double getGrayLevelPrecision() const {return grayLevelPrecision;}
259  double getMaxDotSize(){
260  return this->maxDotSizePercentage;
261  }
265  double getMeanGrayLevel() {
266  return (this->mean_gray_level);
267  };
268 
276  inline unsigned int getWidth() const {
277  return (this->u_max - this->u_min + 1);
278  };
279 
287  inline unsigned int getHeight() const {
288  return (this->v_max - this->v_min + 1);
289  };
290 
291  void initTracking(const vpImage<unsigned char> &I) ;
292  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
293  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip,
294  unsigned int gray_level_min, unsigned int gray_level_max);
295 
296  vpDot& operator =(const vpDot& d) ;
297  bool operator ==(const vpDot& d);
298  bool operator !=(const vpDot& d);
304  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot& d) {
305  return (os << "(" << d.getCog() << ")" ) ;
306  } ;
307 
308  void print(std::ostream& os) { os << *this << std::endl ; }
309 
313  inline void setCog(const vpImagePoint &cog) {
314  this->cog = cog;
315  }
316 
331  void setComputeMoments(const bool activate) { compute_moment = activate; }
332 
336  void setConnexity(vpConnexityType connexityType) {this->connexityType = connexityType; };
337  void setMaxDotSize(double percentage) ;
338  void setGrayLevelMin( const unsigned int &gray_level_min ) {
339  this->gray_level_min = gray_level_min;
340  };
341  void setGrayLevelMax( const unsigned int &gray_level_max ) {
342  this->gray_level_max = gray_level_max;
343  };
344  void setGrayLevelPrecision( const double & grayLevelPrecision );
345 
359  void setGraphics(const bool activate) { graphics = activate ; }
365  void setGraphicsThickness(unsigned int thickness) {this->thickness = thickness;};
366 
367  void track(const vpImage<unsigned char> & I) ;
368  void track(const vpImage<unsigned char> & I, vpImagePoint &ip) ;
369 
370 private:
372  std::list<vpImagePoint> ip_connexities_list;
373 
375  std::list<vpImagePoint> ip_edges_list;
376 
381  vpConnexityType connexityType;
382 
384  vpImagePoint cog;
385 
386  // Bounding box
387  unsigned int u_min, u_max, v_min, v_max;
388 
389  // Flag used to allow display
390  bool graphics ;
391 
392  unsigned int thickness; // Graphics thickness
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  static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
422  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
423  unsigned int thickness=1);
424 
425 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
426 
439  vp_deprecated void getEdges(std::list<vpImagePoint> &edges_list) {
440  edges_list = this->ip_edges_list;
441  };
442 
454  vp_deprecated void getConnexities(vpList<vpImagePoint> &connexities_list) {
455  // convert a vpList in a std::list
456  connexities_list.kill();
457  std::list<vpImagePoint>::const_iterator it;
458  for (it = ip_connexities_list.begin(); it != ip_connexities_list.end(); ++it) {
459  connexities_list += *it;
460  }
461  };
462 #endif
463 } ;
464 
465 #endif
466 
467 
468 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:72
double mu20
Definition: vpDot.h:184
double getMeanGrayLevel()
Definition: vpDot.h:265
unsigned int getHeight() const
Definition: vpDot.h:287
double m10
Definition: vpDot.h:145
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:439
vp_deprecated void getConnexities(vpList< vpImagePoint > &connexities_list)
Definition: vpDot.h:454
void print(std::ostream &os)
Definition: vpDot.h:308
double m00
Definition: vpDot.h:131
vpConnexityType
Definition: vpDot.h:122
double mu11
Definition: vpDot.h:179
void kill()
Destroy the list.
Definition: vpList.h:694
double mu02
Definition: vpDot.h:189
void setGrayLevelMax(const unsigned int &gray_level_max)
Definition: vpDot.h:341
static const unsigned int SPIRAL_SEARCH_SIZE
Definition: vpDot.h:129
double m20
Definition: vpDot.h:161
double m11
Definition: vpDot.h:152
double getMaxDotSize()
Definition: vpDot.h:259
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:338
vpImagePoint getCog() const
Definition: vpDot.h:225
double m01
Definition: vpDot.h:138
void setRect(double left, double top, double width, double height)
Definition: vpRect.h:234
double getGrayLevelPrecision() const
Definition: vpDot.h:258
void setCog(const vpImagePoint &cog)
Definition: vpDot.h:313
unsigned int getWidth() const
Definition: vpDot.h:276
double m02
Definition: vpDot.h:170
std::list< vpImagePoint > getConnexities()
Definition: vpDot.h:246
void setGraphics(const bool activate)
Definition: vpDot.h:359
std::list< vpImagePoint > getEdges()
Definition: vpDot.h:234
void init()
Default initialization.
Definition: vpTracker.cpp:54
double getGamma()
Definition: vpDot.h:250
This tracker is meant to track a dot (connex pixels with same gray level) on a vpImage.
Definition: vpDot.h:116
vpRect getBBox()
Definition: vpDot.h:210
void setComputeMoments(const bool activate)
Definition: vpDot.h:331
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:336
void setGraphicsThickness(unsigned int thickness)
Definition: vpDot.h:365