ViSP  2.8.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 
131 class VISP_EXPORT vpDot2 : public vpTracker
132 {
133 public:
134  vpDot2();
135  vpDot2(const vpImagePoint &ip) ;
136  vpDot2(const vpDot2& twinDot );
137  virtual ~vpDot2();
138 
139  static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage<unsigned char> &I, vpColor col = vpColor::blue, bool trackDot = true);
140 
141  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
142  unsigned int thickness=1);
143 
144  double getArea() const;
152  inline vpRect getBBox() {
153  vpRect bbox;
154 
155  bbox.setRect(this->bbox_u_min,
156  this->bbox_v_min,
157  this->bbox_u_max - this->bbox_u_min + 1,
158  this->bbox_v_max - this->bbox_v_min + 1);
159 
160  return (bbox);
161  };
167  inline vpImagePoint getCog() const {
168  return cog;
169  }
170 
171  double getDistance( const vpDot2& distantDot ) const;
181  void getEdges(std::list<vpImagePoint> &edges_list) {
182  edges_list = this->ip_edges_list;
183  };
191  {
192  return allowedBadPointsPercentage_;
193  }
194 
195  double getEllipsoidShapePrecision() const;
196  void getFreemanChain(std::list<unsigned int> &freeman_chain) ;
197 
198  inline double getGamma() {return this->gamma;};
204  inline unsigned int getGrayLevelMin() const {
205  return gray_level_min;
206  };
212  inline unsigned int getGrayLevelMax() const {
213  return gray_level_max;
214  };
215  double getGrayLevelPrecision() const;
216 
217  double getHeight() const;
218  double getMaxSizeSearchDistancePrecision() const;
222  double getMeanGrayLevel() {
223  return (this->mean_gray_level);
224  };
225  double getSizePrecision() const;
226  double getSurface() const;
227  double getWidth() const;
228 
229  void initTracking(const vpImage<unsigned char>& I, unsigned int size = 0);
230  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
231  unsigned int size = 0);
232  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
233  unsigned int gray_level_min, unsigned int gray_level_max,
234  unsigned int size = 0 );
235 
236  void operator=(const vpDot2& twinDot );
242  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot2& d) {
243  return (os << "(" << d.getCog() << ")" ) ;
244  } ;
245 
246  void print(std::ostream& os) { os << *this << std::endl ; }
247  void searchDotsInArea(const vpImage<unsigned char>& I,
248  int area_u, int area_v,
249  unsigned int area_w, unsigned int area_h, std::list<vpDot2> &niceDots );
250 
251  void searchDotsInArea(const vpImage<unsigned char>& I, std::list<vpDot2> &niceDots );
252 
253  void setArea( const double & area );
257  inline void setCog(const vpImagePoint &cog) {
258  this->cog = cog;
259  }
274  void setComputeMoments(const bool activate) { compute_moment = activate; }
275 
288  void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
289  {
290  if (percentage < 0.)
291  allowedBadPointsPercentage_ = 0.;
292  else if (percentage > 1.)
293  allowedBadPointsPercentage_ = 1.;
294  else
295  allowedBadPointsPercentage_ = percentage;
296  }
297 
298  void setEllipsoidShapePrecision(const double & ellipsoidShapePrecision);
312  void setGraphics(const bool activate) { graphics = activate ; }
318  void setGraphicsThickness(unsigned int thickness) {this->thickness = thickness;};
331  inline void setGrayLevelMin( const unsigned int & min ) {
332  if (min > 255)
333  this->gray_level_min = 255;
334  else
335  this->gray_level_min = min;
336  };
337 
347  inline void setGrayLevelMax( const unsigned int & max ) {
348  if (max > 255)
349  this->gray_level_max = 255;
350  else
351  this->gray_level_max = max;
352  };
353  void setGrayLevelPrecision( const double & grayLevelPrecision );
354  void setHeight( const double & height );
355  void setMaxSizeSearchDistancePrecision(const double & maxSizeSearchDistancePrecision);
356  void setSizePrecision( const double & sizePrecision );
357  void setSurface( const double & surface );
358  void setWidth( const double & width );
359 
360  void track(const vpImage<unsigned char> &I);
361  void track(const vpImage<unsigned char> &I, vpImagePoint &cog);
362 
363  static void trackAndDisplay(vpDot2 dot[], const unsigned int &n, vpImage<unsigned char> &I,
364  std::vector<vpImagePoint> &cogs, vpImagePoint* cogStar = NULL);
365 
366 public:
367  double m00;
375  double m10;
383  double m01;
391  double m11;
398  double m20;
407  double m02;
416  double mu11;
421  double mu20;
426  double mu02;
432 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
433 
447  vp_deprecated void getEdges(vpList<vpImagePoint> &edges_list) {
448  // convert a vpList in a std::list
449  edges_list.kill();
450  std::list<vpImagePoint>::const_iterator it;
451  for (it = ip_edges_list.begin(); it != ip_edges_list.end(); ++it) {
452  edges_list += *it;
453  }
454  };
455  vp_deprecated void getFreemanChain(vpList<unsigned int> &freeman_chain) ;
456  vp_deprecated vpList<vpDot2>* searchDotsInArea(const vpImage<unsigned char>& I,
457  int area_u, int area_v,
458  unsigned int area_w, unsigned int area_h );
459 
460  /* vp_deprecated */ vpList<vpDot2>* searchDotsInArea(const vpImage<unsigned char>& I );
461 #endif
462 
463 private:
464  virtual bool isValid(const vpImage<unsigned char>& I, const vpDot2& wantedDot);
465 
466  virtual bool hasGoodLevel(const vpImage<unsigned char>& I,
467  const unsigned int &u,
468  const unsigned int &v) const;
469  virtual bool hasReverseLevel(const vpImage<unsigned char>& I,
470  const unsigned int &u,
471  const unsigned int &v) const;
472 
473  virtual vpDot2* getInstance();
474 
475  void init();
476 
477  bool computeParameters(const vpImage<unsigned char> &I,
478  const double &u = -1.0,
479  const double &v = -1.0);
480 
481 
482 
483  bool findFirstBorder(const vpImage<unsigned char> &I, const unsigned int &u,
484  const unsigned int &v, unsigned int &border_u,
485  unsigned int &border_v);
486  void computeMeanGrayLevel(const vpImage<unsigned char>& I);
487 
496  unsigned int getFirstBorder_u() const {
497  return this->firstBorder_u;
498  }
507  unsigned int getFirstBorder_v() const {
508  return this->firstBorder_v;
509  }
510 
511  bool computeFreemanChainElement(const vpImage<unsigned char> &I,
512  const unsigned int &u,
513  const unsigned int &v,
514  unsigned int &element);
515  void computeFreemanParameters(const int &u_p,
516  const int &v_p, unsigned int &element,
517  int &du, int &dv, float &dS,
518  float &dMu, float &dMv,
519  float &dMuv,
520  float &dMu2, float &dMv2);
521  void updateFreemanPosition( unsigned int& u, unsigned int& v,
522  const unsigned int &dir );
523 
524 
525  bool isInImage(const vpImage<unsigned char> &I ) const;
526  bool isInImage(const vpImage<unsigned char> &I, const vpImagePoint &ip) const;
527 
528  bool isInArea(const unsigned int &u, const unsigned int &v) const;
529 
530  void getGridSize( unsigned int &gridWidth, unsigned int &gridHeight );
531  void setArea(const vpImage<unsigned char> &I,
532  int u, int v, unsigned int w, unsigned int h);
533  void setArea(const vpImage<unsigned char> &I);
534  void setArea(const vpRect & a);
535 
536  unsigned char getMeanGrayLevel(vpImage<unsigned char>& I) const;
538  vpImagePoint cog;
539 
540  double width;
541  double height;
542  double surface;
543  unsigned int gray_level_min; // minumum gray level for the dot.
544  // pixel with lower level don't belong
545  // to this dot.
546 
547  unsigned int gray_level_max; // maximum gray level for the dot.
548  // pixel with higher level don't belong
549  // to this dot.
550  double mean_gray_level; // Mean gray level of the dot
551  double grayLevelPrecision ;
552  double gamma ;
553  double sizePrecision ;
554  double ellipsoidShapePrecision;
555  double maxSizeSearchDistancePrecision;
556  double allowedBadPointsPercentage_;
557  // Area where the dot is to search
558  vpRect area;
559 
560  // other
561  std::list<unsigned int> direction_list;
562  std::list<vpImagePoint> ip_edges_list;
563 
564  // flag
565  bool compute_moment ; // true moment are computed
566  bool graphics ; // true for graphic overlay display
567 
568  unsigned int thickness; // Graphics thickness
569 
570  // Bounding box
571  int bbox_u_min, bbox_u_max, bbox_v_min, bbox_v_max;
572 
573  // The first point coodinate on the dot border
574  unsigned int firstBorder_u;
575  unsigned int firstBorder_v;
576 
577 //Static funtions
578 public:
579  static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
580  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
581  unsigned int thickness=1);
582  static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
583  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
584  unsigned int thickness=1);
585 
586 };
587 
588 #endif
589 
590 
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:407
void setGrayLevelMax(const unsigned int &max)
Definition: vpDot2.h:347
double mu02
Definition: vpDot2.h:426
void setCog(const vpImagePoint &cog)
Definition: vpDot2.h:257
Provide simple list management.
Definition: vpList.h:112
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
Definition: vpDot2.h:288
double m11
Definition: vpDot2.h:391
void print(std::ostream &os)
Definition: vpDot2.h:246
void kill()
Destroy the list.
Definition: vpList.h:694
double getGamma()
Definition: vpDot2.h:198
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:131
double m01
Definition: vpDot2.h:383
vpRect getBBox()
Definition: vpDot2.h:152
static const vpColor red
Definition: vpColor.h:167
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:69
double getEllipsoidBadPointsPercentage()
Definition: vpDot2.h:190
vpImagePoint getCog() const
Definition: vpDot2.h:167
void setRect(double left, double top, double width, double height)
Definition: vpRect.h:234
double mu11
Definition: vpDot2.h:416
double m20
Definition: vpDot2.h:398
unsigned int getGrayLevelMin() const
Definition: vpDot2.h:204
void setComputeMoments(const bool activate)
Definition: vpDot2.h:274
void setGraphicsThickness(unsigned int thickness)
Definition: vpDot2.h:318
void setGrayLevelMin(const unsigned int &min)
Definition: vpDot2.h:331
void getEdges(std::list< vpImagePoint > &edges_list)
Definition: vpDot2.h:181
double getMeanGrayLevel()
Definition: vpDot2.h:222
void init()
Default initialization.
Definition: vpTracker.cpp:54
double m10
Definition: vpDot2.h:375
double mu20
Definition: vpDot2.h:421
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:367
unsigned int getGrayLevelMax() const
Definition: vpDot2.h:212
void setGraphics(const bool activate)
Definition: vpDot2.h:312
static const vpColor blue
Definition: vpColor.h:173
vp_deprecated void getEdges(vpList< vpImagePoint > &edges_list)
Definition: vpDot2.h:447