ViSP  2.7.0
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 - 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  * 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 
150 class VISP_EXPORT vpDot2 : public vpTracker
151 {
152 public:
153  vpDot2();
154  vpDot2(const vpImagePoint &ip) ;
155  vpDot2(const vpDot2& twinDot );
156  virtual ~vpDot2();
157 
158  static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage<unsigned char> &I, vpColor col = vpColor::blue, bool trackDot = true);
159 
160  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
161  unsigned int thickness=1);
162 
170  inline vpRect getBBox() {
171  vpRect bbox;
172 
173  bbox.setRect(this->bbox_u_min,
174  this->bbox_v_min,
175  this->bbox_u_max - this->bbox_u_min + 1,
176  this->bbox_v_max - this->bbox_v_min + 1);
177 
178  return (bbox);
179  };
185  inline vpImagePoint getCog() const {
186  return cog;
187  }
188 
189  double getDistance( const vpDot2& distantDot ) const;
199  void getEdges(std::list<vpImagePoint> &edges_list) {
200  edges_list = this->ip_edges_list;
201  };
209  {
210  return allowedBadPointsPercentage_;
211  }
212 
213  double getEllipsoidShapePrecision() const;
214  void getFreemanChain(std::list<unsigned int> &freeman_chain) ;
215 
216  inline double getGamma() {return this->gamma;};
222  inline unsigned int getGrayLevelMin() const {
223  return gray_level_min;
224  };
230  inline unsigned int getGrayLevelMax() const {
231  return gray_level_max;
232  };
233  double getGrayLevelPrecision() const;
234 
235  double getHeight() const;
236  double getMaxSizeSearchDistancePrecision() const;
240  double getMeanGrayLevel() {
241  return (this->mean_gray_level);
242  };
243  double getSizePrecision() const;
244  double getSurface() const;
245  double getWidth() const;
246 
247  void initTracking(const vpImage<unsigned char>& I, unsigned int size = 0);
248  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
249  unsigned int size = 0);
250  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
251  unsigned int gray_level_min, unsigned int gray_level_max,
252  unsigned int size = 0 );
253 
254  void operator=(const vpDot2& twinDot );
260  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot2& d) {
261  return (os << "(" << d.getCog() << ")" ) ;
262  } ;
263 
264  void print(std::ostream& os) { os << *this << std::endl ; }
265  void searchDotsInArea(const vpImage<unsigned char>& I,
266  int area_u, int area_v,
267  unsigned int area_w, unsigned int area_h, std::list<vpDot2> &niceDots );
268 
269  void searchDotsInArea(const vpImage<unsigned char>& I, std::list<vpDot2> &niceDots );
270 
274  inline void setCog(const vpImagePoint &cog) {
275  this->cog = cog;
276  }
291  void setComputeMoments(const bool activate) { compute_moment = activate; }
292 
305  void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
306  {
307  if (percentage < 0.)
308  allowedBadPointsPercentage_ = 0.;
309  else if (percentage > 1.)
310  allowedBadPointsPercentage_ = 1.;
311  else
312  allowedBadPointsPercentage_ = percentage;
313  }
314 
315  void setEllipsoidShapePrecision(const double & ellipsoidShapePrecision);
329  void setGraphics(const bool activate) { graphics = activate ; }
335  void setGraphicsThickness(unsigned int thickness) {this->thickness = thickness;};
348  inline void setGrayLevelMin( const unsigned int & min ) {
349  if (min > 255)
350  this->gray_level_min = 255;
351  else
352  this->gray_level_min = min;
353  };
354 
364  inline void setGrayLevelMax( const unsigned int & max ) {
365  if (max > 255)
366  this->gray_level_max = 255;
367  else
368  this->gray_level_max = max;
369  };
370  void setGrayLevelPrecision( const double & grayLevelPrecision );
371  void setHeight( const double & height );
372  void setMaxSizeSearchDistancePrecision(const double & maxSizeSearchDistancePrecision);
373  void setSizePrecision( const double & sizePrecision );
374  void setSurface( const double & surface );
375  void setWidth( const double & width );
376 
377  void track(const vpImage<unsigned char> &I);
378  void track(const vpImage<unsigned char> &I, vpImagePoint &cog);
379 
380  static void trackAndDisplay(vpDot2 dot[], const unsigned int &n, vpImage<unsigned char> &I,
381  std::vector<vpImagePoint> &cogs, vpImagePoint* cogStar = NULL);
382 
383 public:
384  double m00;
392  double m10;
400  double m01;
408  double m11;
415  double m20;
424  double m02;
433  double mu11;
438  double mu20;
443  double mu02;
449 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
450 
464  vp_deprecated void getEdges(vpList<vpImagePoint> &edges_list) {
465  // convert a vpList in a std::list
466  edges_list.kill();
467  std::list<vpImagePoint>::const_iterator it;
468  for (it = ip_edges_list.begin(); it != ip_edges_list.end(); ++it) {
469  edges_list += *it;
470  }
471  };
472  vp_deprecated void getFreemanChain(vpList<unsigned int> &freeman_chain) ;
473  vp_deprecated vpList<vpDot2>* searchDotsInArea(const vpImage<unsigned char>& I,
474  int area_u, int area_v,
475  unsigned int area_w, unsigned int area_h );
476 
477  /* vp_deprecated */ vpList<vpDot2>* searchDotsInArea(const vpImage<unsigned char>& I );
478 #endif
479 
480 private:
481  virtual bool isValid(const vpImage<unsigned char>& I, const vpDot2& wantedDot);
482 
483  virtual bool hasGoodLevel(const vpImage<unsigned char>& I,
484  const unsigned int &u,
485  const unsigned int &v) const;
486  virtual bool hasReverseLevel(const vpImage<unsigned char>& I,
487  const unsigned int &u,
488  const unsigned int &v) const;
489 
490  virtual vpDot2* getInstance();
491 
492  void init();
493 
494  bool computeParameters(const vpImage<unsigned char> &I,
495  const double &u = -1.0,
496  const double &v = -1.0);
497 
498 
499 
500  bool findFirstBorder(const vpImage<unsigned char> &I, const unsigned int &u,
501  const unsigned int &v, unsigned int &border_u,
502  unsigned int &border_v);
503  void computeMeanGrayLevel(const vpImage<unsigned char>& I);
504 
513  unsigned int getFirstBorder_u() const {
514  return this->firstBorder_u;
515  }
524  unsigned int getFirstBorder_v() const {
525  return this->firstBorder_v;
526  }
527 
528  bool computeFreemanChainElement(const vpImage<unsigned char> &I,
529  const unsigned int &u,
530  const unsigned int &v,
531  unsigned int &element);
532  void computeFreemanParameters(const int &u_p,
533  const int &v_p, unsigned int &element,
534  int &du, int &dv, float &dS,
535  float &dMu, float &dMv,
536  float &dMuv,
537  float &dMu2, float &dMv2);
538  void updateFreemanPosition( unsigned int& u, unsigned int& v,
539  const unsigned int &dir );
540 
541 
542  bool isInImage(const vpImage<unsigned char> &I ) const;
543  bool isInImage(const vpImage<unsigned char> &I, const vpImagePoint &ip) const;
544 
545  bool isInArea(const unsigned int &u, const unsigned int &v) const;
546 
547  void getGridSize( unsigned int &gridWidth, unsigned int &gridHeight );
548  void setArea(const vpImage<unsigned char> &I,
549  int u, int v, unsigned int w, unsigned int h);
550  void setArea(const vpImage<unsigned char> &I);
551  void setArea(const vpRect & a);
552 
553  unsigned char getMeanGrayLevel(vpImage<unsigned char>& I) const;
555  vpImagePoint cog;
556 
557  double width;
558  double height;
559  double surface;
560  unsigned int gray_level_min; // minumum gray level for the dot.
561  // pixel with lower level don't belong
562  // to this dot.
563 
564  unsigned int gray_level_max; // maximum gray level for the dot.
565  // pixel with higher level don't belong
566  // to this dot.
567  double mean_gray_level; // Mean gray level of the dot
568  double grayLevelPrecision ;
569  double gamma ;
570  double sizePrecision ;
571  double ellipsoidShapePrecision;
572  double maxSizeSearchDistancePrecision;
573  double allowedBadPointsPercentage_;
574  // Area where the dot is to search
575  vpRect area;
576 
577  // other
578  std::list<unsigned int> direction_list;
579  std::list<vpImagePoint> ip_edges_list;
580 
581  // flag
582  bool compute_moment ; // true moment are computed
583  bool graphics ; // true for graphic overlay display
584 
585  unsigned int thickness; // Graphics thickness
586 
587  // Bounding box
588  int bbox_u_min, bbox_u_max, bbox_v_min, bbox_v_max;
589 
590  // The first point coodinate on the dot border
591  unsigned int firstBorder_u;
592  unsigned int firstBorder_v;
593 
594 //Static funtions
595 public:
596  static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
597  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
598  unsigned int thickness=1);
599  static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
600  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
601  unsigned int thickness=1);
602 
603 };
604 
605 #endif
606 
607 
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:424
void setGrayLevelMax(const unsigned int &max)
Definition: vpDot2.h:364
double mu02
Definition: vpDot2.h:443
void setCog(const vpImagePoint &cog)
Definition: vpDot2.h:274
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:305
double m11
Definition: vpDot2.h:408
void print(std::ostream &os)
Definition: vpDot2.h:264
void kill()
Destroy the list.
Definition: vpList.h:694
double getGamma()
Definition: vpDot2.h:216
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:150
double m01
Definition: vpDot2.h:400
vpRect getBBox()
Definition: vpDot2.h:170
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:208
vpImagePoint getCog() const
Definition: vpDot2.h:185
void setRect(double left, double top, double width, double height)
Definition: vpRect.h:234
double mu11
Definition: vpDot2.h:433
double m20
Definition: vpDot2.h:415
unsigned int getGrayLevelMin() const
Definition: vpDot2.h:222
void setComputeMoments(const bool activate)
Definition: vpDot2.h:291
void setGraphicsThickness(unsigned int thickness)
Definition: vpDot2.h:335
void setGrayLevelMin(const unsigned int &min)
Definition: vpDot2.h:348
void getEdges(std::list< vpImagePoint > &edges_list)
Definition: vpDot2.h:199
double getMeanGrayLevel()
Definition: vpDot2.h:240
void init()
Default initialization.
Definition: vpTracker.cpp:54
double m10
Definition: vpDot2.h:392
double mu20
Definition: vpDot2.h:438
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
double m00
Definition: vpDot2.h:384
unsigned int getGrayLevelMax() const
Definition: vpDot2.h:230
void setGraphics(const bool activate)
Definition: vpDot2.h:329
static const vpColor blue
Definition: vpColor.h:171
vp_deprecated void getEdges(vpList< vpImagePoint > &edges_list)
Definition: vpDot2.h:464