Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpDot2.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Track a white dot.
33  *
34  * Authors:
35  * Fabien Spindler
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/vpColor.h>
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpImagePoint.h>
50 #include <visp3/core/vpPolygon.h>
51 #include <visp3/core/vpRect.h>
52 #include <visp3/core/vpTracker.h>
53 
54 #include <list>
55 #include <vector>
56 
126 class VISP_EXPORT vpDot2 : public vpTracker
127 {
128 public:
129  vpDot2();
130  explicit vpDot2(const vpImagePoint &ip);
131  vpDot2(const vpDot2 &twinDot);
132  virtual ~vpDot2();
133 
134  static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage<unsigned char> &I,
135  vpColor col = vpColor::blue, bool trackDot = true);
136 
137  void display(const vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1) const;
138 
139  double getArea() const;
147  inline vpRect getBBox() const
148  {
149  vpRect bbox;
150 
151  bbox.setRect(this->bbox_u_min, this->bbox_v_min, 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 { return cog; }
162 
163  double getDistance(const vpDot2 &distantDot) const;
173  void getEdges(std::list<vpImagePoint> &edges_list) const { edges_list = this->ip_edges_list; };
183  std::list<vpImagePoint> getEdges() const { return (this->ip_edges_list); };
190  double getEllipsoidBadPointsPercentage() const { return allowedBadPointsPercentage_; }
191 
192  double getEllipsoidShapePrecision() const;
193  void getFreemanChain(std::list<unsigned int> &freeman_chain) const;
194 
195  inline double getGamma() const { return this->gamma; };
201  inline unsigned int getGrayLevelMin() const { return gray_level_min; };
207  inline unsigned int getGrayLevelMax() const { return gray_level_max; };
208  double getGrayLevelPrecision() const;
209 
210  double getHeight() const;
211  double getMaxSizeSearchDistancePrecision() const;
215  double getMeanGrayLevel() const { return (this->mean_gray_level); };
219  vpPolygon getPolygon() const { return (vpPolygon(ip_edges_list)); };
220  double getSizePrecision() const;
221  double getWidth() const;
222 
223  void initTracking(const vpImage<unsigned char> &I, unsigned int size = 0);
224  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int size = 0);
225  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int gray_lvl_min,
226  unsigned int gray_lvl_max, unsigned int size = 0);
227 
228  vpDot2 &operator=(const vpDot2 &twinDot);
229  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpDot2 &d);
230 
231  void print(std::ostream &os) { os << *this << std::endl; }
232  void searchDotsInArea(const vpImage<unsigned char> &I, int area_u, int area_v, unsigned int area_w,
233  unsigned int area_h, std::list<vpDot2> &niceDots);
234 
235  void searchDotsInArea(const vpImage<unsigned char> &I, std::list<vpDot2> &niceDots);
236 
237  void setArea(const double &area);
241  inline void setCog(const vpImagePoint &ip) { this->cog = ip; }
256  void setComputeMoments(const bool activate) { compute_moment = activate; }
257 
270  void setEllipsoidBadPointsPercentage(const double &percentage = 0.0)
271  {
272  if (percentage < 0.)
273  allowedBadPointsPercentage_ = 0.;
274  else if (percentage > 1.)
275  allowedBadPointsPercentage_ = 1.;
276  else
277  allowedBadPointsPercentage_ = percentage;
278  }
279 
280  void setEllipsoidShapePrecision(const double &ellipsoidShapePrecision);
294  void setGraphics(const bool activate) { graphics = activate; }
301  void setGraphicsThickness(unsigned int t) { this->thickness = t; };
314  inline void setGrayLevelMin(const unsigned int &min)
315  {
316  if (min > 255)
317  this->gray_level_min = 255;
318  else
319  this->gray_level_min = min;
320  };
321 
331  inline void setGrayLevelMax(const unsigned int &max)
332  {
333  if (max > 255)
334  this->gray_level_max = 255;
335  else
336  this->gray_level_max = max;
337  };
338  void setGrayLevelPrecision(const double &grayLevelPrecision);
339  void setHeight(const double &height);
340  void setMaxSizeSearchDistancePrecision(const double &maxSizeSearchDistancePrecision);
341  void setSizePrecision(const double &sizePrecision);
342  void setWidth(const double &width);
343 
344  void track(const vpImage<unsigned char> &I);
345  void track(const vpImage<unsigned char> &I, vpImagePoint &cog);
346 
347  static void trackAndDisplay(vpDot2 dot[], const unsigned int &n, vpImage<unsigned char> &I,
348  std::vector<vpImagePoint> &cogs, vpImagePoint *cogStar = NULL);
349 
350 public:
351  double m00;
359  double m10;
367  double m01;
375  double m11;
382  double m20;
391  double m02;
400  double mu11;
405  double mu20;
410  double mu02;
416 private:
417  virtual bool isValid(const vpImage<unsigned char> &I, const vpDot2 &wantedDot);
418 
419  virtual bool hasGoodLevel(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v) const;
420  virtual bool hasReverseLevel(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v) const;
421 
422  virtual vpDot2 *getInstance();
423 
424  void init();
425 
426  bool computeParameters(const vpImage<unsigned char> &I, const double &u = -1.0, const double &v = -1.0);
427 
428  bool findFirstBorder(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v,
429  unsigned int &border_u, unsigned int &border_v);
430  void computeMeanGrayLevel(const vpImage<unsigned char> &I);
431 
440  unsigned int getFirstBorder_u() const { return this->firstBorder_u; }
449  unsigned int getFirstBorder_v() const { return this->firstBorder_v; }
450 
451  bool computeFreemanChainElement(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v,
452  unsigned int &element);
453  void computeFreemanParameters(const int &u_p, const int &v_p, unsigned int &element, int &du, int &dv, float &dS,
454  float &dMu, float &dMv, float &dMuv, float &dMu2, float &dMv2);
455  void updateFreemanPosition(unsigned int &u, unsigned int &v, const unsigned int &dir);
456 
457  bool isInImage(const vpImage<unsigned char> &I) const;
458  bool isInImage(const vpImage<unsigned char> &I, const vpImagePoint &ip) const;
459 
460  bool isInArea(const unsigned int &u, const unsigned int &v) const;
461 
462  void getGridSize(unsigned int &gridWidth, unsigned int &gridHeight);
463  void setArea(const vpImage<unsigned char> &I, int u, int v, unsigned int w, unsigned int h);
464  void setArea(const vpImage<unsigned char> &I);
465  void setArea(const vpRect &a);
466 
467  unsigned char getMeanGrayLevel(vpImage<unsigned char> &I) const;
469  vpImagePoint cog;
470 
471  double width;
472  double height;
473  double surface;
474  unsigned int gray_level_min; // minumum gray level for the dot.
475  // pixel with lower level don't belong
476  // to this dot.
477 
478  unsigned int gray_level_max; // maximum gray level for the dot.
479  // pixel with higher level don't belong
480  // to this dot.
481  double mean_gray_level; // Mean gray level of the dot
482  double grayLevelPrecision;
483  double gamma;
484  double sizePrecision;
485  double ellipsoidShapePrecision;
486  double maxSizeSearchDistancePrecision;
487  double allowedBadPointsPercentage_;
488  // Area where the dot is to search
489  vpRect area;
490 
491  // other
492  std::list<unsigned int> direction_list;
493  std::list<vpImagePoint> ip_edges_list;
494 
495  // flag
496  bool compute_moment; // true moment are computed
497  bool graphics; // true for graphic overlay display
498 
499  unsigned int thickness; // Graphics thickness
500 
501  // Bounding box
502  int bbox_u_min, bbox_u_max, bbox_v_min, bbox_v_max;
503 
504  // The first point coodinate on the dot border
505  unsigned int firstBorder_u;
506  unsigned int firstBorder_v;
507 
508  // Static funtions
509 public:
510  static void display(const vpImage<unsigned char> &I, const vpImagePoint &cog,
511  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
512  unsigned int thickness = 1);
513  static void display(const vpImage<vpRGBa> &I, const vpImagePoint &cog, const std::list<vpImagePoint> &edges_list,
514  vpColor color = vpColor::red, unsigned int thickness = 1);
515 };
516 
517 #endif
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:53
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
double m02
Definition: vpDot2.h:391
void setGrayLevelMax(const unsigned int &max)
Definition: vpDot2.h:331
double mu02
Definition: vpDot2.h:410
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
Definition: vpDot2.h:270
void setCog(const vpImagePoint &ip)
Definition: vpDot2.h:241
double m11
Definition: vpDot2.h:375
void print(std::ostream &os)
Definition: vpDot2.h:231
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:126
double m01
Definition: vpDot2.h:367
static const vpColor red
Definition: vpColor.h:180
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:64
vpImagePoint getCog() const
Definition: vpDot2.h:161
void setGraphicsThickness(unsigned int t)
Definition: vpDot2.h:301
Defines a generic 2D polygon.
Definition: vpPolygon.h:103
double mu11
Definition: vpDot2.h:400
double m20
Definition: vpDot2.h:382
unsigned int getGrayLevelMin() const
Definition: vpDot2.h:201
void setComputeMoments(const bool activate)
Definition: vpDot2.h:256
std::list< vpImagePoint > getEdges() const
Definition: vpDot2.h:183
vpPolygon getPolygon() const
Definition: vpDot2.h:219
void setGrayLevelMin(const unsigned int &min)
Definition: vpDot2.h:314
vpRect getBBox() const
Definition: vpDot2.h:147
void init()
Default initialization.
Definition: vpTracker.cpp:47
double m10
Definition: vpDot2.h:359
double mu20
Definition: vpDot2.h:405
Defines a rectangle in the plane.
Definition: vpRect.h:78
double getMeanGrayLevel() const
Definition: vpDot2.h:215
double getEllipsoidBadPointsPercentage() const
Definition: vpDot2.h:190
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:351
double getGamma() const
Definition: vpDot2.h:195
unsigned int getGrayLevelMax() const
Definition: vpDot2.h:207
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:268
void setGraphics(const bool activate)
Definition: vpDot2.h:294
void getEdges(std::list< vpImagePoint > &edges_list) const
Definition: vpDot2.h:173
static const vpColor blue
Definition: vpColor.h:186