Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpDot2.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Track a white dot.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
38 
39 /*
40  \file vpDot2.h
41  \brief This tracker is meant to track some zones on a vpImage.
42 */
43 
44 #ifndef vpDot2_hh
45 #define vpDot2_hh
46 
47 #include <visp3/core/vpImage.h>
48 #include <visp3/core/vpRect.h>
49 #include <visp3/core/vpTracker.h>
50 #include <visp3/core/vpColor.h>
51 #include <visp3/core/vpImagePoint.h>
52 #include <visp3/core/vpPolygon.h>
53 
54 #include <vector>
55 #include <list>
56 
125 class VISP_EXPORT vpDot2 : public vpTracker
126 {
127 public:
128  vpDot2();
129  vpDot2(const vpImagePoint &ip) ;
130  vpDot2(const vpDot2& twinDot );
131  virtual ~vpDot2();
132 
133  static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage<unsigned char> &I, vpColor col = vpColor::blue, bool trackDot = true);
134 
135  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
136  unsigned int thickness=1) const;
137 
138  double getArea() const;
146  inline vpRect getBBox() const {
147  vpRect bbox;
148 
149  bbox.setRect(this->bbox_u_min,
150  this->bbox_v_min,
151  this->bbox_u_max - this->bbox_u_min + 1,
152  this->bbox_v_max - this->bbox_v_min + 1);
153 
154  return (bbox);
155  };
161  inline vpImagePoint getCog() const {
162  return cog;
163  }
164 
165  double getDistance( const vpDot2& distantDot ) const;
175  void getEdges(std::list<vpImagePoint> &edges_list) const {
176  edges_list = this->ip_edges_list;
177  };
187  std::list<vpImagePoint> getEdges() const {
188  return(this->ip_edges_list);
189  };
197  {
198  return allowedBadPointsPercentage_;
199  }
200 
201  double getEllipsoidShapePrecision() const;
202  void getFreemanChain(std::list<unsigned int> &freeman_chain) const;
203 
204  inline double getGamma() const {return this->gamma;};
210  inline unsigned int getGrayLevelMin() const {
211  return gray_level_min;
212  };
218  inline unsigned int getGrayLevelMax() const {
219  return gray_level_max;
220  };
221  double getGrayLevelPrecision() const;
222 
223  double getHeight() const;
224  double getMaxSizeSearchDistancePrecision() const;
228  double getMeanGrayLevel() const {
229  return (this->mean_gray_level);
230  };
235  return (vpPolygon(ip_edges_list));
236  };
237  double getSizePrecision() const;
238  double getWidth() const;
239 
240  void initTracking(const vpImage<unsigned char>& I, unsigned int size = 0);
241  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
242  unsigned int size = 0);
243  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
244  unsigned int gray_lvl_min, unsigned int gray_lvl_max,
245  unsigned int size = 0 );
246 
247  vpDot2& operator=(const vpDot2& twinDot );
248  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot2& d);
249 
250  void print(std::ostream& os) { os << *this << std::endl ; }
251  void searchDotsInArea(const vpImage<unsigned char>& I,
252  int area_u, int area_v,
253  unsigned int area_w, unsigned int area_h, std::list<vpDot2> &niceDots );
254 
255  void searchDotsInArea(const vpImage<unsigned char>& I, std::list<vpDot2> &niceDots );
256 
257  void setArea( const double & area );
261  inline void setCog(const vpImagePoint &ip) {
262  this->cog = ip;
263  }
278  void setComputeMoments(const bool activate) { compute_moment = activate; }
279 
292  void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
293  {
294  if (percentage < 0.)
295  allowedBadPointsPercentage_ = 0.;
296  else if (percentage > 1.)
297  allowedBadPointsPercentage_ = 1.;
298  else
299  allowedBadPointsPercentage_ = percentage;
300  }
301 
302  void setEllipsoidShapePrecision(const double & ellipsoidShapePrecision);
316  void setGraphics(const bool activate) { graphics = activate ; }
322  void setGraphicsThickness(unsigned int t) {this->thickness = t;};
335  inline void setGrayLevelMin( const unsigned int & min ) {
336  if (min > 255)
337  this->gray_level_min = 255;
338  else
339  this->gray_level_min = min;
340  };
341 
351  inline void setGrayLevelMax( const unsigned int & max ) {
352  if (max > 255)
353  this->gray_level_max = 255;
354  else
355  this->gray_level_max = max;
356  };
357  void setGrayLevelPrecision( const double & grayLevelPrecision );
358  void setHeight( const double & height );
359  void setMaxSizeSearchDistancePrecision(const double & maxSizeSearchDistancePrecision);
360  void setSizePrecision( const double & sizePrecision );
361  void setWidth( const double & width );
362 
363  void track(const vpImage<unsigned char> &I);
364  void track(const vpImage<unsigned char> &I, vpImagePoint &cog);
365 
366  static void trackAndDisplay(vpDot2 dot[], const unsigned int &n, vpImage<unsigned char> &I,
367  std::vector<vpImagePoint> &cogs, vpImagePoint* cogStar = NULL);
368 
369 public:
370  double m00;
378  double m10;
386  double m01;
394  double m11;
401  double m20;
410  double m02;
419  double mu11;
424  double mu20;
429  double mu02;
435 private:
436  virtual bool isValid(const vpImage<unsigned char>& I, const vpDot2& wantedDot);
437 
438  virtual bool hasGoodLevel(const vpImage<unsigned char>& I,
439  const unsigned int &u,
440  const unsigned int &v) const;
441  virtual bool hasReverseLevel(const vpImage<unsigned char>& I,
442  const unsigned int &u,
443  const unsigned int &v) const;
444 
445  virtual vpDot2* getInstance();
446 
447  void init();
448 
449  bool computeParameters(const vpImage<unsigned char> &I,
450  const double &u = -1.0,
451  const double &v = -1.0);
452 
453 
454 
455  bool findFirstBorder(const vpImage<unsigned char> &I, const unsigned int &u,
456  const unsigned int &v, unsigned int &border_u,
457  unsigned int &border_v);
458  void computeMeanGrayLevel(const vpImage<unsigned char>& I);
459 
468  unsigned int getFirstBorder_u() const {
469  return this->firstBorder_u;
470  }
479  unsigned int getFirstBorder_v() const {
480  return this->firstBorder_v;
481  }
482 
483  bool computeFreemanChainElement(const vpImage<unsigned char> &I,
484  const unsigned int &u,
485  const unsigned int &v,
486  unsigned int &element);
487  void computeFreemanParameters(const int &u_p,
488  const int &v_p, unsigned int &element,
489  int &du, int &dv, float &dS,
490  float &dMu, float &dMv,
491  float &dMuv,
492  float &dMu2, float &dMv2);
493  void updateFreemanPosition( unsigned int& u, unsigned int& v,
494  const unsigned int &dir );
495 
496 
497  bool isInImage(const vpImage<unsigned char> &I ) const;
498  bool isInImage(const vpImage<unsigned char> &I, const vpImagePoint &ip) const;
499 
500  bool isInArea(const unsigned int &u, const unsigned int &v) const;
501 
502  void getGridSize( unsigned int &gridWidth, unsigned int &gridHeight );
503  void setArea(const vpImage<unsigned char> &I,
504  int u, int v, unsigned int w, unsigned int h);
505  void setArea(const vpImage<unsigned char> &I);
506  void setArea(const vpRect & a);
507 
508  unsigned char getMeanGrayLevel(vpImage<unsigned char>& I) const;
510  vpImagePoint cog;
511 
512  double width;
513  double height;
514  double surface;
515  unsigned int gray_level_min; // minumum gray level for the dot.
516  // pixel with lower level don't belong
517  // to this dot.
518 
519  unsigned int gray_level_max; // maximum gray level for the dot.
520  // pixel with higher level don't belong
521  // to this dot.
522  double mean_gray_level; // Mean gray level of the dot
523  double grayLevelPrecision ;
524  double gamma ;
525  double sizePrecision ;
526  double ellipsoidShapePrecision;
527  double maxSizeSearchDistancePrecision;
528  double allowedBadPointsPercentage_;
529  // Area where the dot is to search
530  vpRect area;
531 
532  // other
533  std::list<unsigned int> direction_list;
534  std::list<vpImagePoint> ip_edges_list;
535 
536  // flag
537  bool compute_moment ; // true moment are computed
538  bool graphics ; // true for graphic overlay display
539 
540  unsigned int thickness; // Graphics thickness
541 
542  // Bounding box
543  int bbox_u_min, bbox_u_max, bbox_v_min, bbox_v_max;
544 
545  // The first point coodinate on the dot border
546  unsigned int firstBorder_u;
547  unsigned int firstBorder_v;
548 
549 //Static funtions
550 public:
551  static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
552  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
553  unsigned int thickness=1);
554  static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
555  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
556  unsigned int thickness=1);
557 
558 };
559 
560 #endif
561 
562 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:65
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
double m02
Definition: vpDot2.h:410
void setGrayLevelMax(const unsigned int &max)
Definition: vpDot2.h:351
double mu02
Definition: vpDot2.h:429
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
Definition: vpDot2.h:292
void setCog(const vpImagePoint &ip)
Definition: vpDot2.h:261
double m11
Definition: vpDot2.h:394
void print(std::ostream &os)
Definition: vpDot2.h:250
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:125
double m01
Definition: vpDot2.h:386
static const vpColor red
Definition: vpColor.h:163
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:66
vpImagePoint getCog() const
Definition: vpDot2.h:161
void setGraphicsThickness(unsigned int t)
Definition: vpDot2.h:322
Defines a generic 2D polygon.
Definition: vpPolygon.h:99
double mu11
Definition: vpDot2.h:419
double m20
Definition: vpDot2.h:401
unsigned int getGrayLevelMin() const
Definition: vpDot2.h:210
void setComputeMoments(const bool activate)
Definition: vpDot2.h:278
std::list< vpImagePoint > getEdges() const
Definition: vpDot2.h:187
vpPolygon getPolygon() const
Definition: vpDot2.h:234
void setGrayLevelMin(const unsigned int &min)
Definition: vpDot2.h:335
vpRect getBBox() const
Definition: vpDot2.h:146
void init()
Default initialization.
Definition: vpTracker.cpp:50
double m10
Definition: vpDot2.h:378
double mu20
Definition: vpDot2.h:424
Defines a rectangle in the plane.
Definition: vpRect.h:82
double getMeanGrayLevel() const
Definition: vpDot2.h:228
double getEllipsoidBadPointsPercentage() const
Definition: vpDot2.h:196
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
double m00
Definition: vpDot2.h:370
double getGamma() const
Definition: vpDot2.h:204
unsigned int getGrayLevelMax() const
Definition: vpDot2.h:218
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:269
void setGraphics(const bool activate)
Definition: vpDot2.h:316
void getEdges(std::list< vpImagePoint > &edges_list) const
Definition: vpDot2.h:175
static const vpColor blue
Definition: vpColor.h:169