ViSP  2.6.2
vpDot2.h
1  /****************************************************************************
2  *
3  * $Id: vpDot2.h 2135 2009-04-29 13:51:31Z 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  * Description:
34  * Track a white dot.
35  *
36  * Authors:
37  * Fabien Spindler
38  *
39  *****************************************************************************/
40 
41 
42 /*
43  \file vpDot2.h
44  \brief This tracker is meant to track some zones on a vpImage.
45 */
46 
47 #ifndef vpDot2_hh
48 #define vpDot2_hh
49 
50 #include <visp/vpImage.h>
51 #include <visp/vpRect.h>
52 #include <visp/vpTracker.h>
53 #include <visp/vpColor.h>
54 #include <visp/vpImagePoint.h>
55 
56 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
57 # include <visp/vpList.h>
58 #endif
59 
60 #include <vector>
61 #include <list>
62 
114 class VISP_EXPORT vpDot2 : public vpTracker
115 {
116 public:
117  vpDot2();
118  vpDot2(const vpImagePoint &ip) ;
119  vpDot2(const vpDot2& twinDot );
120  virtual ~vpDot2();
121  void operator=(const vpDot2& twinDot );
122 
126  inline void setCog(const vpImagePoint &cog) {
127  this->cog = cog;
128  }
143  void setComputeMoments(const bool activate) { compute_moment = activate; }
144 
157  void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
158  {
159  if (percentage < 0.)
160  allowedBadPointsPercentage_ = 0.;
161  else if (percentage > 1.)
162  allowedBadPointsPercentage_ = 1.;
163  else
164  allowedBadPointsPercentage_ = percentage;
165  }
166 
167  void setEllipsoidShapePrecision(const double & ellipsoidShapePrecision);
178  void setGraphics(const bool activate) { graphics = activate ; }
191  inline void setGrayLevelMin( const unsigned int & min ) {
192  if (min > 255)
193  this->gray_level_min = 255;
194  else
195  this->gray_level_min = min;
196  };
197 
207  inline void setGrayLevelMax( const unsigned int & max ) {
208  if (max > 255)
209  this->gray_level_max = 255;
210  else
211  this->gray_level_max = max;
212  };
213  void setGrayLevelPrecision( const double & grayLevelPrecision );
214  void setHeight( const double & height );
215  void setMaxSizeSearchDistancePrecision(const double & maxSizeSearchDistancePrecision);
216  void setSizePrecision( const double & sizePrecision );
217  void setSurface( const double & surface );
218  void setWidth( const double & width );
219 
220  void initTracking(const vpImage<unsigned char>& I, unsigned int size = 0);
221  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
222  unsigned int size = 0);
223  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
224  unsigned int gray_level_min, unsigned int gray_level_max,
225  unsigned int size = 0 );
226 
227  void track(const vpImage<unsigned char> &I);
228  void track(const vpImage<unsigned char> &I, vpImagePoint &cog);
229  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
230  unsigned int thickness=1);
231 
239  inline vpRect getBBox() {
240  vpRect bbox;
241 
242  bbox.setRect(this->bbox_u_min,
243  this->bbox_v_min,
244  this->bbox_u_max - this->bbox_u_min + 1,
245  this->bbox_v_max - this->bbox_v_min + 1);
246 
247  return (bbox);
248  };
254  inline vpImagePoint getCog() const {
255  return cog;
256  }
257 
258  double getDistance( const vpDot2& distantDot ) const;
268  void getEdges(std::list<vpImagePoint> &edges_list) {
269  edges_list = this->ip_edges_list;
270  };
278  {
279  return allowedBadPointsPercentage_;
280  }
281 
282  double getEllipsoidShapePrecision() const;
283  void getFreemanChain(std::list<unsigned int> &freeman_chain) ;
284 
285  inline double getGamma() {return this->gamma;};
291  inline unsigned int getGrayLevelMin() const {
292  return gray_level_min;
293  };
299  inline unsigned int getGrayLevelMax() const {
300  return gray_level_max;
301  };
302  double getGrayLevelPrecision() const;
303 
304  double getHeight() const;
305  double getMaxSizeSearchDistancePrecision() const;
311  double getMeanGrayLevel() {
312  return (this->mean_gray_level);
313  };
314  double getSizePrecision() const;
315  double getSurface() const;
316  double getWidth() const;
317 
318  void print(std::ostream& os) { os << *this << std::endl ; }
319  void searchDotsInArea(const vpImage<unsigned char>& I,
320  int area_u, int area_v,
321  unsigned int area_w, unsigned int area_h, std::list<vpDot2> &niceDots );
322 
323  void searchDotsInArea(const vpImage<unsigned char>& I, std::list<vpDot2> &niceDots );
324 
325  static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage<unsigned char> &I, vpColor col = vpColor::blue, bool trackDot = true);
326 
327  static void trackAndDisplay(vpDot2 dot[], const unsigned int &n, vpImage<unsigned char> &I, std::vector<vpImagePoint> &cogs, vpImagePoint* cogStar = NULL);
328 
334  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot2& d) {
335  return (os << "(" << d.getCog() << ")" ) ;
336  } ;
337 
338 public:
339  double m00;
347  double m10;
355  double m01;
363  double m11;
370  double m20;
379  double m02;
388  double mu11;
393  double mu20;
398  double mu02;
404 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
405 
420  vp_deprecated void getEdges(vpList<vpImagePoint> &edges_list) {
421  // convert a vpList in a std::list
422  edges_list.kill();
423  std::list<vpImagePoint>::const_iterator it;
424  for (it = ip_edges_list.begin(); it != ip_edges_list.end(); ++it) {
425  edges_list += *it;
426  }
427  };
428  vp_deprecated void getFreemanChain(vpList<unsigned int> &freeman_chain) ;
429  vp_deprecated vpList<vpDot2>* searchDotsInArea(const vpImage<unsigned char>& I,
430  int area_u, int area_v,
431  unsigned int area_w, unsigned int area_h );
432 
433  /* vp_deprecated */ vpList<vpDot2>* searchDotsInArea(const vpImage<unsigned char>& I );
434 #endif
435 
436 private:
437  virtual bool isValid(const vpImage<unsigned char>& I, const vpDot2& wantedDot);
438 
439  virtual bool hasGoodLevel(const vpImage<unsigned char>& I,
440  const unsigned int &u,
441  const unsigned int &v) const;
442  virtual bool hasReverseLevel(const vpImage<unsigned char>& I,
443  const unsigned int &u,
444  const unsigned int &v) const;
445 
446  virtual vpDot2* getInstance();
447 
448  void init();
449 
450  bool computeParameters(const vpImage<unsigned char> &I,
451  const double &u = -1.0,
452  const double &v = -1.0);
453 
454 
455 
456  bool findFirstBorder(const vpImage<unsigned char> &I, const unsigned int &u,
457  const unsigned int &v, unsigned int &border_u,
458  unsigned int &border_v);
459  void computeMeanGrayLevel(const vpImage<unsigned char>& I);
460 
469  unsigned int getFirstBorder_u() const {
470  return this->firstBorder_u;
471  }
480  unsigned int getFirstBorder_v() const {
481  return this->firstBorder_v;
482  }
483 
484  bool computeFreemanChainElement(const vpImage<unsigned char> &I,
485  const unsigned int &u,
486  const unsigned int &v,
487  unsigned int &element);
488  void computeFreemanParameters(const int &u_p,
489  const int &v_p, unsigned int &element,
490  int &du, int &dv, float &dS,
491  float &dMu, float &dMv,
492  float &dMuv,
493  float &dMu2, float &dMv2);
494  void updateFreemanPosition( unsigned int& u, unsigned int& v,
495  const unsigned int &dir );
496 
497 
498  bool isInImage(const vpImage<unsigned char> &I ) const;
499  bool isInImage(const vpImage<unsigned char> &I, const vpImagePoint &ip) const;
500 
501  bool isInArea(const unsigned int &u, const unsigned int &v) const;
502 
503  void getGridSize( unsigned int &gridWidth, unsigned int &gridHeight );
504  void setArea(const vpImage<unsigned char> &I,
505  int u, int v, unsigned int w, unsigned int h);
506  void setArea(const vpImage<unsigned char> &I);
507  void setArea(const vpRect & a);
508 
509  unsigned char getMeanGrayLevel(vpImage<unsigned char>& I) const;
511  vpImagePoint cog;
512 
513  double width;
514  double height;
515  double surface;
516  unsigned int gray_level_min; // minumum gray level for the dot.
517  // pixel with lower level don't belong
518  // to this dot.
519 
520  unsigned int gray_level_max; // maximum gray level for the dot.
521  // pixel with higher level don't belong
522  // to this dot.
523  double mean_gray_level; // Mean gray level of the dot
524  double grayLevelPrecision ;
525  double gamma ;
526  double sizePrecision ;
527  double ellipsoidShapePrecision;
528  double maxSizeSearchDistancePrecision;
529  double allowedBadPointsPercentage_;
530  // Area where the dot is to search
531  vpRect area;
532 
533  // other
534  std::list<unsigned int> direction_list;
535  std::list<vpImagePoint> ip_edges_list;
536 
537  // flag
538  bool compute_moment ; // true moment are computed
539  bool graphics ; // true for graphic overlay display
540 
541  // Bounding box
542  int bbox_u_min, bbox_u_max, bbox_v_min, bbox_v_max;
543 
544  // The first point coodinate on the dot border
545  unsigned int firstBorder_u;
546  unsigned int firstBorder_v;
547 
548 //Static funtions
549 public:
550  static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
551  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
552  unsigned int thickness=1);
553 
554 };
555 
556 #endif
557 
558 /*
559  * Local variables:
560  * c-basic-offset: 2
561  * End:
562  */
563 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:72
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
double m02
Definition: vpDot2.h:379
void setGrayLevelMax(const unsigned int &max)
Definition: vpDot2.h:207
double mu02
Definition: vpDot2.h:398
void setCog(const vpImagePoint &cog)
Definition: vpDot2.h:126
Provide simple list management.
Definition: vpList.h:112
Class to define colors available for display functionnalities.
Definition: vpColor.h:123
void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
Definition: vpDot2.h:157
double m11
Definition: vpDot2.h:363
void print(std::ostream &os)
Definition: vpDot2.h:318
void kill()
Destroy the list.
Definition: vpList.h:694
double getGamma()
Definition: vpDot2.h:285
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:114
double m01
Definition: vpDot2.h:355
vpRect getBBox()
Definition: vpDot2.h:239
static const vpColor red
Definition: vpColor.h:165
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:69
double getEllipsoidBadPointsPercentage()
Definition: vpDot2.h:277
vpImagePoint getCog() const
Definition: vpDot2.h:254
void setRect(double left, double top, double width, double height)
Definition: vpRect.h:234
double mu11
Definition: vpDot2.h:388
double m20
Definition: vpDot2.h:370
unsigned int getGrayLevelMin() const
Definition: vpDot2.h:291
void setComputeMoments(const bool activate)
Definition: vpDot2.h:143
void setGrayLevelMin(const unsigned int &min)
Definition: vpDot2.h:191
void getEdges(std::list< vpImagePoint > &edges_list)
Definition: vpDot2.h:268
double getMeanGrayLevel()
Definition: vpDot2.h:311
void init()
Default initialization.
Definition: vpTracker.cpp:54
double m10
Definition: vpDot2.h:347
double mu20
Definition: vpDot2.h:393
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
unsigned int getGrayLevelMax() const
Definition: vpDot2.h:299
void setGraphics(const bool activate)
Definition: vpDot2.h:178
static const vpColor blue
Definition: vpColor.h:171
vp_deprecated void getEdges(vpList< vpImagePoint > &edges_list)
Definition: vpDot2.h:420