ViSP  2.9.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 - 2014 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 #include <vector>
57 #include <list>
58 
127 class VISP_EXPORT vpDot2 : public vpTracker
128 {
129 public:
130  vpDot2();
131  vpDot2(const vpImagePoint &ip) ;
132  vpDot2(const vpDot2& twinDot );
133  virtual ~vpDot2();
134 
135  static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage<unsigned char> &I, vpColor col = vpColor::blue, bool trackDot = true);
136 
137  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
138  unsigned int thickness=1) const;
139 
140  double getArea() const;
148  inline vpRect getBBox() const {
149  vpRect bbox;
150 
151  bbox.setRect(this->bbox_u_min,
152  this->bbox_v_min,
153  this->bbox_u_max - this->bbox_u_min + 1,
154  this->bbox_v_max - this->bbox_v_min + 1);
155 
156  return (bbox);
157  };
163  inline vpImagePoint getCog() const {
164  return cog;
165  }
166 
167  double getDistance( const vpDot2& distantDot ) const;
177  void getEdges(std::list<vpImagePoint> &edges_list) const {
178  edges_list = this->ip_edges_list;
179  };
189  std::list<vpImagePoint> getEdges() const {
190  return(this->ip_edges_list);
191  };
199  {
200  return allowedBadPointsPercentage_;
201  }
202 
203  double getEllipsoidShapePrecision() const;
204  void getFreemanChain(std::list<unsigned int> &freeman_chain) const;
205 
206  inline double getGamma() const {return this->gamma;};
212  inline unsigned int getGrayLevelMin() const {
213  return gray_level_min;
214  };
220  inline unsigned int getGrayLevelMax() const {
221  return gray_level_max;
222  };
223  double getGrayLevelPrecision() const;
224 
225  double getHeight() const;
226  double getMaxSizeSearchDistancePrecision() const;
230  double getMeanGrayLevel() const {
231  return (this->mean_gray_level);
232  };
233  double getSizePrecision() const;
234  double getWidth() const;
235 
236  void initTracking(const vpImage<unsigned char>& I, unsigned int size = 0);
237  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
238  unsigned int size = 0);
239  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
240  unsigned int gray_lvl_min, unsigned int gray_lvl_max,
241  unsigned int size = 0 );
242 
243  vpDot2& operator=(const vpDot2& twinDot );
244  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot2& d);
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 &ip) {
258  this->cog = ip;
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 t) {this->thickness = t;};
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 setWidth( const double & width );
358 
359  void track(const vpImage<unsigned char> &I);
360  void track(const vpImage<unsigned char> &I, vpImagePoint &cog);
361 
362  static void trackAndDisplay(vpDot2 dot[], const unsigned int &n, vpImage<unsigned char> &I,
363  std::vector<vpImagePoint> &cogs, vpImagePoint* cogStar = NULL);
364 
365 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
366 
369  vp_deprecated double getSurface() const;
370  vp_deprecated void setSurface( const double & surface );
371 #endif
372 
373 public:
374  double m00;
382  double m10;
390  double m01;
398  double m11;
405  double m20;
414  double m02;
423  double mu11;
428  double mu20;
433  double mu02;
439 private:
440  virtual bool isValid(const vpImage<unsigned char>& I, const vpDot2& wantedDot);
441 
442  virtual bool hasGoodLevel(const vpImage<unsigned char>& I,
443  const unsigned int &u,
444  const unsigned int &v) const;
445  virtual bool hasReverseLevel(const vpImage<unsigned char>& I,
446  const unsigned int &u,
447  const unsigned int &v) const;
448 
449  virtual vpDot2* getInstance();
450 
451  void init();
452 
453  bool computeParameters(const vpImage<unsigned char> &I,
454  const double &u = -1.0,
455  const double &v = -1.0);
456 
457 
458 
459  bool findFirstBorder(const vpImage<unsigned char> &I, const unsigned int &u,
460  const unsigned int &v, unsigned int &border_u,
461  unsigned int &border_v);
462  void computeMeanGrayLevel(const vpImage<unsigned char>& I);
463 
472  unsigned int getFirstBorder_u() const {
473  return this->firstBorder_u;
474  }
483  unsigned int getFirstBorder_v() const {
484  return this->firstBorder_v;
485  }
486 
487  bool computeFreemanChainElement(const vpImage<unsigned char> &I,
488  const unsigned int &u,
489  const unsigned int &v,
490  unsigned int &element);
491  void computeFreemanParameters(const int &u_p,
492  const int &v_p, unsigned int &element,
493  int &du, int &dv, float &dS,
494  float &dMu, float &dMv,
495  float &dMuv,
496  float &dMu2, float &dMv2);
497  void updateFreemanPosition( unsigned int& u, unsigned int& v,
498  const unsigned int &dir );
499 
500 
501  bool isInImage(const vpImage<unsigned char> &I ) const;
502  bool isInImage(const vpImage<unsigned char> &I, const vpImagePoint &ip) const;
503 
504  bool isInArea(const unsigned int &u, const unsigned int &v) const;
505 
506  void getGridSize( unsigned int &gridWidth, unsigned int &gridHeight );
507  void setArea(const vpImage<unsigned char> &I,
508  int u, int v, unsigned int w, unsigned int h);
509  void setArea(const vpImage<unsigned char> &I);
510  void setArea(const vpRect & a);
511 
512  unsigned char getMeanGrayLevel(vpImage<unsigned char>& I) const;
514  vpImagePoint cog;
515 
516  double width;
517  double height;
518  double surface;
519  unsigned int gray_level_min; // minumum gray level for the dot.
520  // pixel with lower level don't belong
521  // to this dot.
522 
523  unsigned int gray_level_max; // maximum gray level for the dot.
524  // pixel with higher level don't belong
525  // to this dot.
526  double mean_gray_level; // Mean gray level of the dot
527  double grayLevelPrecision ;
528  double gamma ;
529  double sizePrecision ;
530  double ellipsoidShapePrecision;
531  double maxSizeSearchDistancePrecision;
532  double allowedBadPointsPercentage_;
533  // Area where the dot is to search
534  vpRect area;
535 
536  // other
537  std::list<unsigned int> direction_list;
538  std::list<vpImagePoint> ip_edges_list;
539 
540  // flag
541  bool compute_moment ; // true moment are computed
542  bool graphics ; // true for graphic overlay display
543 
544  unsigned int thickness; // Graphics thickness
545 
546  // Bounding box
547  int bbox_u_min, bbox_u_max, bbox_v_min, bbox_v_max;
548 
549  // The first point coodinate on the dot border
550  unsigned int firstBorder_u;
551  unsigned int firstBorder_v;
552 
553 //Static funtions
554 public:
555  static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
556  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
557  unsigned int thickness=1);
558  static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
559  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
560  unsigned int thickness=1);
561 
562 };
563 
564 #endif
565 
566 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:69
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
double m02
Definition: vpDot2.h:414
void setGrayLevelMax(const unsigned int &max)
Definition: vpDot2.h:347
double mu02
Definition: vpDot2.h:433
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
Definition: vpDot2.h:288
void setCog(const vpImagePoint &ip)
Definition: vpDot2.h:257
double m11
Definition: vpDot2.h:398
void print(std::ostream &os)
Definition: vpDot2.h:246
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:127
double m01
Definition: vpDot2.h:390
static const vpColor red
Definition: vpColor.h:167
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:69
vpImagePoint getCog() const
Definition: vpDot2.h:163
void setGraphicsThickness(unsigned int t)
Definition: vpDot2.h:318
double mu11
Definition: vpDot2.h:423
double m20
Definition: vpDot2.h:405
unsigned int getGrayLevelMin() const
Definition: vpDot2.h:212
void setComputeMoments(const bool activate)
Definition: vpDot2.h:274
std::list< vpImagePoint > getEdges() const
Definition: vpDot2.h:189
void setGrayLevelMin(const unsigned int &min)
Definition: vpDot2.h:331
vpRect getBBox() const
Definition: vpDot2.h:148
void init()
Default initialization.
Definition: vpTracker.cpp:54
double m10
Definition: vpDot2.h:382
double mu20
Definition: vpDot2.h:428
Defines a rectangle in the plane.
Definition: vpRect.h:85
double getMeanGrayLevel() const
Definition: vpDot2.h:230
double getEllipsoidBadPointsPercentage() const
Definition: vpDot2.h:198
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:374
double getGamma() const
Definition: vpDot2.h:206
unsigned int getGrayLevelMax() const
Definition: vpDot2.h:220
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:246
void setGraphics(const bool activate)
Definition: vpDot2.h:312
void getEdges(std::list< vpImagePoint > &edges_list) const
Definition: vpDot2.h:177
static const vpColor blue
Definition: vpColor.h:173