Visual Servoing Platform  version 3.6.1 under development (2024-11-14)
vpDot.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 
39 #ifndef VP_DOT_H
40 #define VP_DOT_H
41 
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpDisplay.h>
44 #include <visp3/core/vpImage.h>
45 #include <visp3/core/vpImagePoint.h>
46 #include <visp3/core/vpPolygon.h>
47 #include <visp3/core/vpRect.h>
48 #include <visp3/core/vpTracker.h>
49 
50 #include <fstream>
51 #include <list>
52 #include <math.h>
53 #include <vector>
54 
55 #ifdef VISP_USE_MSVC
56 #pragma comment(linker, "/STACK:256000000") // Increase max recursion depth
57 #endif
58 
59 BEGIN_VISP_NAMESPACE
60 
115 class VISP_EXPORT vpDot : public vpTracker
116 {
117 public:
121  typedef enum
122  {
123  CONNEXITY_4,
125  CONNEXITY_8
127  } vpConnexityType;
128 
129 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
130 public:
131  static const unsigned int SPIRAL_SEARCH_SIZE;
133  double m00;
140  double m01;
147  double m10;
154  double m11;
161  double m20;
168  double m02;
175  double mu11;
180  double mu20;
185  double mu02;
190 #endif
191 
192 public:
193  vpDot();
194  VP_EXPLICIT vpDot(const vpImagePoint &ip);
195  vpDot(const vpDot &d);
196  virtual ~vpDot() VP_OVERRIDE;
197 
198  void display(const vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1) const;
199 
209  inline vpColVector get_nij() const
210  {
211  vpColVector nij(3);
212  const unsigned int index_0 = 0;
213  const unsigned int index_1 = 1;
214  const unsigned int index_2 = 2;
215  nij[index_0] = mu20 / m00;
216  nij[index_1] = mu11 / m00;
217  nij[index_2] = mu02 / m00;
218 
219  return nij;
220  }
221 
227  inline double getArea() const { return m00; }
228 
234  inline vpRect getBBox() const
235  {
236  vpRect bbox;
237 
238  bbox.setRect(m_u_min, m_v_min, (m_u_max - m_u_min) + 1, (m_v_max - m_v_min) + 1);
239 
240  return bbox;
241  };
247  inline vpImagePoint getCog() const { return m_cog; }
248 
255  inline std::list<vpImagePoint> getEdges() const { return m_ip_edges_list; };
256 
263  inline std::list<vpImagePoint> getConnexities() const { return m_ip_connexities_list; };
264 
265  inline double getGamma() const { return m_gamma; };
266 
272  double getGrayLevelPrecision() const { return m_grayLevelPrecision; }
273  double getMaxDotSize() const { return m_maxDotSizePercentage; }
274 
278  double getMeanGrayLevel() const { return m_mean_gray_level; };
279 
283  vpPolygon getPolygon() const { return (vpPolygon(m_ip_edges_list)); };
284 
290  inline unsigned int getWidth() const { return ((m_u_max - m_u_min) + 1); };
291 
297  inline unsigned int getHeight() const { return ((m_v_max - m_v_min) + 1); };
298 
299  void initTracking(const vpImage<unsigned char> &I);
300  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
301  void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int gray_level_min,
302  unsigned int gray_level_max);
303 
304  vpDot &operator=(const vpDot &d);
305  bool operator==(const vpDot &d) const;
306  bool operator!=(const vpDot &d) const;
307  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpDot &d);
308 
309  void print(std::ostream &os) { os << *this << std::endl; }
310 
314  inline void setCog(const vpImagePoint &cog) { m_cog = cog; }
315 
329  void setComputeMoments(bool activate) { m_compute_moment = activate; }
330 
334  void setConnexity(const vpConnexityType &connexityType) { m_connexityType = connexityType; };
335  void setMaxDotSize(double percentage);
336  void setGrayLevelMin(const unsigned int &level_min) { m_gray_level_min = level_min; };
337  void setGrayLevelMax(const unsigned int &level_max) { m_gray_level_max = level_max; };
338  void setGrayLevelPrecision(const double &grayLevelPrecision);
339 
354  void setGraphics(bool activate) { m_graphics = activate; }
361  void setGraphicsThickness(unsigned int thickness) { m_thickness = thickness; };
362 
363  void track(const vpImage<unsigned char> &I);
364  void track(const vpImage<unsigned char> &I, vpImagePoint &ip);
365 
366  // Static Functions
367 public:
368  static void display(const vpImage<unsigned char> &I, const vpImagePoint &cog,
369  const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
370  unsigned int thickness = 1);
371  static void display(const vpImage<vpRGBa> &I, const vpImagePoint &cog, const std::list<vpImagePoint> &edges_list,
372  vpColor color = vpColor::red, unsigned int thickness = 1);
373 
374 #ifndef VISP_BUILD_DEPRECATED_FUNCTIONS
375 private:
376  static const unsigned int SPIRAL_SEARCH_SIZE;
378  double m00;
385  double m01;
392  double m10;
399  double m11;
406  double m20;
413  double m02;
420  double mu11;
425  double mu20;
430  double mu02;
435 #endif
436 
437 private:
439  std::list<vpImagePoint> m_ip_connexities_list;
440 
442  std::list<vpImagePoint> m_ip_edges_list;
443 
448  vpConnexityType m_connexityType;
449 
451  vpImagePoint m_cog;
452 
453  // Bounding box
454  unsigned int m_u_min, m_u_max, m_v_min, m_v_max;
455 
456  // Flag used to allow display
457  bool m_graphics;
458 
459  unsigned int m_thickness; // Graphics thickness
460 
461  double m_maxDotSizePercentage;
462  unsigned char m_gray_level_out;
463 
464  double m_mean_gray_level; // Mean gray level of the dot
465  unsigned int m_gray_level_min; // left threshold for binarization
466  unsigned int m_gray_level_max; // right threshold for binarization
467  double m_grayLevelPrecision; // precision of the gray level of the dot.
468  // It is a double precision float witch value is in ]0,1].
469  // 1 means full precision, whereas values close to 0 show a very bad
470  // precision
471  double m_gamma;
473  bool m_compute_moment;
474  double m_nbMaxPoint;
475 
476  void init();
477  void setGrayLevelOut();
478  bool connexe(const vpImage<unsigned char> &I, unsigned int u, unsigned int v, double &mean_value,
479  vpImagePoint &uv_cog, unsigned int &npoints);
480  bool connexe(const vpImage<unsigned char> &I, unsigned int u, unsigned int v, double &mean_value,
481  vpImagePoint &uv_cog, unsigned int &npoints, std::vector<bool> &checkTab);
482  void COG(const vpImage<unsigned char> &I, double &u, double &v);
483 };
484 
485 END_VISP_NAMESPACE
486 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static const vpColor red
Definition: vpColor.h:217
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.
Definition: vpDot.h:116
vpRect getBBox() const
Definition: vpDot.h:234
std::list< vpImagePoint > getConnexities() const
Definition: vpDot.h:263
unsigned int getWidth() const
Definition: vpDot.h:290
void setGraphics(bool activate)
Definition: vpDot.h:354
void setConnexity(const vpConnexityType &connexityType)
Definition: vpDot.h:334
double getArea() const
Definition: vpDot.h:227
double getMeanGrayLevel() const
Definition: vpDot.h:278
void setCog(const vpImagePoint &cog)
Definition: vpDot.h:314
std::list< vpImagePoint > getEdges() const
Definition: vpDot.h:255
void setGraphicsThickness(unsigned int thickness)
Definition: vpDot.h:361
double getMaxDotSize() const
Definition: vpDot.h:273
void print(std::ostream &os)
Definition: vpDot.h:309
vpPolygon getPolygon() const
Definition: vpDot.h:283
void setGrayLevelMax(const unsigned int &level_max)
Definition: vpDot.h:337
void setGrayLevelMin(const unsigned int &level_min)
Definition: vpDot.h:336
void setComputeMoments(bool activate)
Definition: vpDot.h:329
double getGrayLevelPrecision() const
Definition: vpDot.h:272
vpConnexityType
Definition: vpDot.h:122
double getGamma() const
Definition: vpDot.h:265
vpImagePoint getCog() const
Definition: vpDot.h:247
unsigned int getHeight() const
Definition: vpDot.h:297
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
Definition of the vpImage class member functions.
Definition: vpImage.h:131
Defines a generic 2D polygon.
Definition: vpPolygon.h:103
Defines a rectangle in the plane.
Definition: vpRect.h:79
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:333
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:61
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition: vpTracker.cpp:50
void init()
Default initialization.
Definition: vpTracker.cpp:44