Visual Servoing Platform  version 3.1.0
vpDot.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 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  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
45 #ifndef vpDot_hh
46 #define vpDot_hh
47 
48 #include <visp3/core/vpConfig.h>
49 #include <visp3/core/vpDisplay.h>
50 #include <visp3/core/vpImage.h>
51 #include <visp3/core/vpImagePoint.h>
52 #include <visp3/core/vpPolygon.h>
53 #include <visp3/core/vpRect.h>
54 #include <visp3/core/vpTracker.h>
55 
56 #include <fstream>
57 #include <list>
58 #include <math.h>
59 #include <vector>
60 
61 #ifdef VISP_USE_MSVC
62 #pragma comment(linker, "/STACK:256000000") // Increase max recursion depth
63 #endif
64 
117 class VISP_EXPORT vpDot : public vpTracker
118 {
119 public:
123  typedef enum {
124  CONNEXITY_4,
126  CONNEXITY_8
128  } vpConnexityType;
129 
130  static const unsigned int SPIRAL_SEARCH_SIZE;
132  double m00;
139  double m01;
146  double m10;
153  double m11;
162  double m20;
171  double m02;
180  double mu11;
185  double mu20;
190  double mu02;
196  vpDot();
197  explicit vpDot(const vpImagePoint &ip);
198  vpDot(const vpDot &d);
199  virtual ~vpDot();
200 
201  void display(const vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1) const;
202 
210  inline vpRect getBBox() const
211  {
212  vpRect bbox;
213 
214  bbox.setRect(this->u_min, this->v_min, this->u_max - this->u_min + 1, this->v_max - this->v_min + 1);
215 
216  return (bbox);
217  };
223  inline vpImagePoint getCog() const { return cog; }
224 
231  inline std::list<vpImagePoint> getEdges() const { return this->ip_edges_list; };
232 
241  inline std::list<vpImagePoint> getConnexities() const { return this->ip_connexities_list; };
242 
243  inline double getGamma() const { return this->gamma; };
251  double getGrayLevelPrecision() const { return grayLevelPrecision; }
252  double getMaxDotSize() const { return this->maxDotSizePercentage; }
256  double getMeanGrayLevel() const { return (this->mean_gray_level); };
257 
261  vpPolygon getPolygon() const { return (vpPolygon(ip_edges_list)); };
262 
270  inline unsigned int getWidth() const { return (this->u_max - this->u_min + 1); };
271 
279  inline unsigned int getHeight() const { return (this->v_max - this->v_min + 1); };
280 
281  void initTracking(const vpImage<unsigned char> &I);
282  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
283  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int gray_level_min,
284  unsigned int gray_level_max);
285 
286  vpDot &operator=(const vpDot &d);
287  bool operator==(const vpDot &d) const;
288  bool operator!=(const vpDot &d) const;
289  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpDot &d);
290 
291  void print(std::ostream &os) { os << *this << std::endl; }
292 
296  inline void setCog(const vpImagePoint &ip) { this->cog = ip; }
297 
312  void setComputeMoments(const bool activate) { compute_moment = activate; }
313 
317  void setConnexity(vpConnexityType type) { this->connexityType = type; };
318  void setMaxDotSize(double percentage);
319  void setGrayLevelMin(const unsigned int &level_min) { this->gray_level_min = level_min; };
320  void setGrayLevelMax(const unsigned int &level_max) { this->gray_level_max = level_max; };
321  void setGrayLevelPrecision(const double &grayLevelPrecision);
322 
336  void setGraphics(const bool activate) { graphics = activate; }
343  void setGraphicsThickness(unsigned int t) { this->thickness = t; };
344 
345  void track(const vpImage<unsigned char> &I);
346  void track(const vpImage<unsigned char> &I, vpImagePoint &ip);
347 
348 private:
350  std::list<vpImagePoint> ip_connexities_list;
351 
353  std::list<vpImagePoint> ip_edges_list;
354 
359  vpConnexityType connexityType;
360 
362  vpImagePoint cog;
363 
364  // Bounding box
365  unsigned int u_min, u_max, v_min, v_max;
366 
367  // Flag used to allow display
368  bool graphics;
369 
370  unsigned int thickness; // Graphics thickness
371 
372  double maxDotSizePercentage;
373  unsigned char gray_level_out;
374 
375  double mean_gray_level; // Mean gray level of the dot
376  unsigned int gray_level_min; // left threshold for binarisation
377  unsigned int gray_level_max; // right threshold for binarisation
378  double grayLevelPrecision; // precision of the gray level of the dot.
379  // It is a double precision float witch value is in ]0,1].
380  // 1 means full precision, whereas values close to 0 show a very bad
381  // precision
382  double gamma;
384  bool compute_moment;
385  double nbMaxPoint;
386 
387  void init();
388  void setGrayLevelOut();
389  bool connexe(const vpImage<unsigned char> &I, unsigned int u, unsigned int v, double &mean_value, double &u_cog,
390  double &v_cog, double &n);
391  bool connexe(const vpImage<unsigned char> &I, unsigned int u, unsigned int v, double &mean_value, double &u_cog,
392  double &v_cog, double &n, std::vector<bool> &checkTab);
393  void COG(const vpImage<unsigned char> &I, double &u, double &v);
394 
395  // Static Functions
396 public:
397  static void display(const vpImage<unsigned char> &I, const vpImagePoint &cog,
398  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
399  unsigned int thickness = 1);
400  static void display(const vpImage<vpRGBa> &I, const vpImagePoint &cog, const std::list<vpImagePoint> &edges_list,
401  vpColor color = vpColor::red, unsigned int thickness = 1);
402 };
403 
404 #endif
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:53
double mu20
Definition: vpDot.h:185
void setConnexity(vpConnexityType type)
Definition: vpDot.h:317
double m10
Definition: vpDot.h:146
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
double getGrayLevelPrecision() const
Definition: vpDot.h:251
void print(std::ostream &os)
Definition: vpDot.h:291
void setGrayLevelMin(const unsigned int &level_min)
Definition: vpDot.h:319
double m00
Definition: vpDot.h:132
vpConnexityType
Definition: vpDot.h:123
double mu11
Definition: vpDot.h:180
double getMeanGrayLevel() const
Definition: vpDot.h:256
double mu02
Definition: vpDot.h:190
vpPolygon getPolygon() const
Definition: vpDot.h:261
static const unsigned int SPIRAL_SEARCH_SIZE
Definition: vpDot.h:130
double m20
Definition: vpDot.h:162
double m11
Definition: vpDot.h:153
static const vpColor red
Definition: vpColor.h:180
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:64
Defines a generic 2D polygon.
Definition: vpPolygon.h:103
double m01
Definition: vpDot.h:139
vpImagePoint getCog() const
Definition: vpDot.h:223
vpRect getBBox() const
Definition: vpDot.h:210
void setGraphicsThickness(unsigned int t)
Definition: vpDot.h:343
unsigned int getHeight() const
Definition: vpDot.h:279
double m02
Definition: vpDot.h:171
double getGamma() const
Definition: vpDot.h:243
void setGraphics(const bool activate)
Definition: vpDot.h:336
void setGrayLevelMax(const unsigned int &level_max)
Definition: vpDot.h:320
void init()
Default initialization.
Definition: vpTracker.cpp:47
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:117
void setComputeMoments(const bool activate)
Definition: vpDot.h:312
Defines a rectangle in the plane.
Definition: vpRect.h:78
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
unsigned int getWidth() const
Definition: vpDot.h:270
std::list< vpImagePoint > getEdges() const
Definition: vpDot.h:231
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:268
std::list< vpImagePoint > getConnexities() const
Definition: vpDot.h:241
void setCog(const vpImagePoint &ip)
Definition: vpDot.h:296
double getMaxDotSize() const
Definition: vpDot.h:252