Visual Servoing Platform  version 3.0.0
vpDot2.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 
53 #include <vector>
54 #include <list>
55 
124 class VISP_EXPORT vpDot2 : public vpTracker
125 {
126 public:
127  vpDot2();
128  vpDot2(const vpImagePoint &ip) ;
129  vpDot2(const vpDot2& twinDot );
130  virtual ~vpDot2();
131 
132  static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage<unsigned char> &I, vpColor col = vpColor::blue, bool trackDot = true);
133 
134  void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
135  unsigned int thickness=1) const;
136 
137  double getArea() const;
145  inline vpRect getBBox() const {
146  vpRect bbox;
147 
148  bbox.setRect(this->bbox_u_min,
149  this->bbox_v_min,
150  this->bbox_u_max - this->bbox_u_min + 1,
151  this->bbox_v_max - this->bbox_v_min + 1);
152 
153  return (bbox);
154  };
160  inline vpImagePoint getCog() const {
161  return cog;
162  }
163 
164  double getDistance( const vpDot2& distantDot ) const;
174  void getEdges(std::list<vpImagePoint> &edges_list) const {
175  edges_list = this->ip_edges_list;
176  };
186  std::list<vpImagePoint> getEdges() const {
187  return(this->ip_edges_list);
188  };
196  {
197  return allowedBadPointsPercentage_;
198  }
199 
200  double getEllipsoidShapePrecision() const;
201  void getFreemanChain(std::list<unsigned int> &freeman_chain) const;
202 
203  inline double getGamma() const {return this->gamma;};
209  inline unsigned int getGrayLevelMin() const {
210  return gray_level_min;
211  };
217  inline unsigned int getGrayLevelMax() const {
218  return gray_level_max;
219  };
220  double getGrayLevelPrecision() const;
221 
222  double getHeight() const;
223  double getMaxSizeSearchDistancePrecision() const;
227  double getMeanGrayLevel() const {
228  return (this->mean_gray_level);
229  };
230  double getSizePrecision() const;
231  double getWidth() const;
232 
233  void initTracking(const vpImage<unsigned char>& I, unsigned int size = 0);
234  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
235  unsigned int size = 0);
236  void initTracking(const vpImage<unsigned char>& I, const vpImagePoint &ip,
237  unsigned int gray_lvl_min, unsigned int gray_lvl_max,
238  unsigned int size = 0 );
239 
240  vpDot2& operator=(const vpDot2& twinDot );
241  friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot2& d);
242 
243  void print(std::ostream& os) { os << *this << std::endl ; }
244  void searchDotsInArea(const vpImage<unsigned char>& I,
245  int area_u, int area_v,
246  unsigned int area_w, unsigned int area_h, std::list<vpDot2> &niceDots );
247 
248  void searchDotsInArea(const vpImage<unsigned char>& I, std::list<vpDot2> &niceDots );
249 
250  void setArea( const double & area );
254  inline void setCog(const vpImagePoint &ip) {
255  this->cog = ip;
256  }
271  void setComputeMoments(const bool activate) { compute_moment = activate; }
272 
285  void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
286  {
287  if (percentage < 0.)
288  allowedBadPointsPercentage_ = 0.;
289  else if (percentage > 1.)
290  allowedBadPointsPercentage_ = 1.;
291  else
292  allowedBadPointsPercentage_ = percentage;
293  }
294 
295  void setEllipsoidShapePrecision(const double & ellipsoidShapePrecision);
309  void setGraphics(const bool activate) { graphics = activate ; }
315  void setGraphicsThickness(unsigned int t) {this->thickness = t;};
328  inline void setGrayLevelMin( const unsigned int & min ) {
329  if (min > 255)
330  this->gray_level_min = 255;
331  else
332  this->gray_level_min = min;
333  };
334 
344  inline void setGrayLevelMax( const unsigned int & max ) {
345  if (max > 255)
346  this->gray_level_max = 255;
347  else
348  this->gray_level_max = max;
349  };
350  void setGrayLevelPrecision( const double & grayLevelPrecision );
351  void setHeight( const double & height );
352  void setMaxSizeSearchDistancePrecision(const double & maxSizeSearchDistancePrecision);
353  void setSizePrecision( const double & sizePrecision );
354  void setWidth( const double & width );
355 
356  void track(const vpImage<unsigned char> &I);
357  void track(const vpImage<unsigned char> &I, vpImagePoint &cog);
358 
359  static void trackAndDisplay(vpDot2 dot[], const unsigned int &n, vpImage<unsigned char> &I,
360  std::vector<vpImagePoint> &cogs, vpImagePoint* cogStar = NULL);
361 
362 public:
363  double m00;
371  double m10;
379  double m01;
387  double m11;
394  double m20;
403  double m02;
412  double mu11;
417  double mu20;
422  double mu02;
428 private:
429  virtual bool isValid(const vpImage<unsigned char>& I, const vpDot2& wantedDot);
430 
431  virtual bool hasGoodLevel(const vpImage<unsigned char>& I,
432  const unsigned int &u,
433  const unsigned int &v) const;
434  virtual bool hasReverseLevel(const vpImage<unsigned char>& I,
435  const unsigned int &u,
436  const unsigned int &v) const;
437 
438  virtual vpDot2* getInstance();
439 
440  void init();
441 
442  bool computeParameters(const vpImage<unsigned char> &I,
443  const double &u = -1.0,
444  const double &v = -1.0);
445 
446 
447 
448  bool findFirstBorder(const vpImage<unsigned char> &I, const unsigned int &u,
449  const unsigned int &v, unsigned int &border_u,
450  unsigned int &border_v);
451  void computeMeanGrayLevel(const vpImage<unsigned char>& I);
452 
461  unsigned int getFirstBorder_u() const {
462  return this->firstBorder_u;
463  }
472  unsigned int getFirstBorder_v() const {
473  return this->firstBorder_v;
474  }
475 
476  bool computeFreemanChainElement(const vpImage<unsigned char> &I,
477  const unsigned int &u,
478  const unsigned int &v,
479  unsigned int &element);
480  void computeFreemanParameters(const int &u_p,
481  const int &v_p, unsigned int &element,
482  int &du, int &dv, float &dS,
483  float &dMu, float &dMv,
484  float &dMuv,
485  float &dMu2, float &dMv2);
486  void updateFreemanPosition( unsigned int& u, unsigned int& v,
487  const unsigned int &dir );
488 
489 
490  bool isInImage(const vpImage<unsigned char> &I ) const;
491  bool isInImage(const vpImage<unsigned char> &I, const vpImagePoint &ip) const;
492 
493  bool isInArea(const unsigned int &u, const unsigned int &v) const;
494 
495  void getGridSize( unsigned int &gridWidth, unsigned int &gridHeight );
496  void setArea(const vpImage<unsigned char> &I,
497  int u, int v, unsigned int w, unsigned int h);
498  void setArea(const vpImage<unsigned char> &I);
499  void setArea(const vpRect & a);
500 
501  unsigned char getMeanGrayLevel(vpImage<unsigned char>& I) const;
503  vpImagePoint cog;
504 
505  double width;
506  double height;
507  double surface;
508  unsigned int gray_level_min; // minumum gray level for the dot.
509  // pixel with lower level don't belong
510  // to this dot.
511 
512  unsigned int gray_level_max; // maximum gray level for the dot.
513  // pixel with higher level don't belong
514  // to this dot.
515  double mean_gray_level; // Mean gray level of the dot
516  double grayLevelPrecision ;
517  double gamma ;
518  double sizePrecision ;
519  double ellipsoidShapePrecision;
520  double maxSizeSearchDistancePrecision;
521  double allowedBadPointsPercentage_;
522  // Area where the dot is to search
523  vpRect area;
524 
525  // other
526  std::list<unsigned int> direction_list;
527  std::list<vpImagePoint> ip_edges_list;
528 
529  // flag
530  bool compute_moment ; // true moment are computed
531  bool graphics ; // true for graphic overlay display
532 
533  unsigned int thickness; // Graphics thickness
534 
535  // Bounding box
536  int bbox_u_min, bbox_u_max, bbox_v_min, bbox_v_max;
537 
538  // The first point coodinate on the dot border
539  unsigned int firstBorder_u;
540  unsigned int firstBorder_v;
541 
542 //Static funtions
543 public:
544  static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
545  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
546  unsigned int thickness=1);
547  static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
548  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
549  unsigned int thickness=1);
550 
551 };
552 
553 #endif
554 
555 
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:65
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
double m02
Definition: vpDot2.h:403
void setGrayLevelMax(const unsigned int &max)
Definition: vpDot2.h:344
double mu02
Definition: vpDot2.h:422
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
Definition: vpDot2.h:285
void setCog(const vpImagePoint &ip)
Definition: vpDot2.h:254
double m11
Definition: vpDot2.h:387
void print(std::ostream &os)
Definition: vpDot2.h:243
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:124
double m01
Definition: vpDot2.h:379
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:160
void setGraphicsThickness(unsigned int t)
Definition: vpDot2.h:315
double mu11
Definition: vpDot2.h:412
double m20
Definition: vpDot2.h:394
unsigned int getGrayLevelMin() const
Definition: vpDot2.h:209
void setComputeMoments(const bool activate)
Definition: vpDot2.h:271
std::list< vpImagePoint > getEdges() const
Definition: vpDot2.h:186
void setGrayLevelMin(const unsigned int &min)
Definition: vpDot2.h:328
vpRect getBBox() const
Definition: vpDot2.h:145
void init()
Default initialization.
Definition: vpTracker.cpp:50
double m10
Definition: vpDot2.h:371
double mu20
Definition: vpDot2.h:417
Defines a rectangle in the plane.
Definition: vpRect.h:81
double getMeanGrayLevel() const
Definition: vpDot2.h:227
double getEllipsoidBadPointsPercentage() const
Definition: vpDot2.h:195
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:363
double getGamma() const
Definition: vpDot2.h:203
unsigned int getGrayLevelMax() const
Definition: vpDot2.h:217
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:252
void setGraphics(const bool activate)
Definition: vpDot2.h:309
void getEdges(std::list< vpImagePoint > &edges_list) const
Definition: vpDot2.h:174
static const vpColor blue
Definition: vpColor.h:169