Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpDot2.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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
38
39#ifndef VP_DOT2_H
40#define VP_DOT2_H
41
42#include <visp3/core/vpColor.h>
43#include <visp3/core/vpConfig.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 <list>
51#include <vector>
52
54
126class VISP_EXPORT vpDot2 : public vpTracker
127{
128public:
129 vpDot2();
130 VP_EXPLICIT vpDot2(const vpImagePoint &ip);
131 vpDot2(const vpDot2 &twinDot);
132
133 static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage<unsigned char> &I,
134 vpColor col = vpColor::blue, bool trackDot = true);
135
136 void display(const vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1) const;
137
147 inline vpColVector get_nij() const
148 {
149 vpColVector nij(3);
150 const unsigned int index_0 = 0;
151 const unsigned int index_1 = 1;
152 const unsigned int index_2 = 2;
153
154 nij[index_0] = mu20 / m00;
155 nij[index_1] = mu11 / m00;
156 nij[index_2] = mu02 / m00;
157
158 return nij;
159 }
160
161 double getArea() const;
162
168 inline vpRect getBBox() const
169 {
170 vpRect bbox;
171
172 bbox.setRect(m_bbox_u_min, m_bbox_v_min, (m_bbox_u_max - m_bbox_u_min) + 1,
173 (m_bbox_v_max - m_bbox_v_min) + 1);
174
175 return bbox;
176 }
177
183 inline vpImagePoint getCog() const { return m_cog; }
184
185 double getDistance(const vpDot2 &distantDot) const;
193 void getEdges(std::list<vpImagePoint> &edges_list) const { edges_list = m_ip_edges_list; }
194
202 std::list<vpImagePoint> getEdges() const { return m_ip_edges_list; }
203
210 double getEllipsoidBadPointsPercentage() const { return m_allowedBadPointsPercentage; }
211
212 double getEllipsoidShapePrecision() const;
213 void getFreemanChain(std::list<unsigned int> &freeman_chain) const;
214
215 inline double getGamma() const { return m_gamma; }
221 inline unsigned int getGrayLevelMin() const { return m_gray_level_min; }
227 inline unsigned int getGrayLevelMax() const { return m_gray_level_max; }
228 double getGrayLevelPrecision() const;
229
230 double getHeight() const;
231 double getMaxSizeSearchDistPrecision() const;
232
236 double getMeanGrayLevel() const { return m_mean_gray_level; }
237
241 vpPolygon getPolygon() const { return (vpPolygon(m_ip_edges_list)); }
242 double getSizePrecision() const;
243 double getWidth() const;
244
245 void initTracking(const vpImage<unsigned char> &I, unsigned int size = 0);
246 void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int size = 0);
247 void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int gray_lvl_min,
248 unsigned int gray_lvl_max, unsigned int size = 0);
249
250 vpDot2 &operator=(const vpDot2 &twinDot);
251 friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpDot2 &d);
252
253 void print(std::ostream &os) { os << *this << std::endl; }
254 void searchDotsInArea(const vpImage<unsigned char> &I, int area_u, int area_v, unsigned int area_w,
255 unsigned int area_h, std::list<vpDot2> &niceDots);
256
257 void searchDotsInArea(const vpImage<unsigned char> &I, std::list<vpDot2> &niceDots);
258
259 void setArea(const double &area);
263 inline void setCog(const vpImagePoint &ip) { m_cog = ip; }
264
278 void setComputeMoments(bool activate) { m_compute_moment = activate; }
279
292 void setEllipsoidBadPointsPercentage(const double &percentage = 0.0)
293 {
294 if (percentage < 0.) {
295 m_allowedBadPointsPercentage = 0.;
296 }
297 else if (percentage > 1.) {
298 m_allowedBadPointsPercentage = 1.;
299 }
300 else {
301 m_allowedBadPointsPercentage = percentage;
302 }
303 }
304
305 void setEllipsoidShapePrecision(const double &ellipsoidShapePrecision);
306
320 void setGraphics(bool activate) { m_graphics = activate; }
321
328 void setGraphicsThickness(unsigned int thickness) { m_thickness = thickness; }
329
340 inline void setGrayLevelMin(const unsigned int &min)
341 {
342 const unsigned int val_max = 255;
343 if (min > val_max) {
344 m_gray_level_min = val_max;
345 }
346 else {
347 m_gray_level_min = min;
348 }
349 }
350
359 inline void setGrayLevelMax(const unsigned int &max)
360 {
361 const unsigned int val_max = 255;
362 if (max > val_max) {
363 m_gray_level_max = val_max;
364 }
365 else {
366 m_gray_level_max = max;
367 }
368 }
369
370 void setGrayLevelPrecision(const double &grayLevelPrecision);
371 void setHeight(const double &height);
372 void setMaxSizeSearchDistPrecision(const double &maxSizeSearchDistancePrecision);
373 void setSizePrecision(const double &sizePrecision);
374 void setWidth(const double &width);
375
376 void track(const vpImage<unsigned char> &I, bool canMakeTheWindowGrow = true);
377 void track(const vpImage<unsigned char> &I, vpImagePoint &cog, bool canMakeTheWindowGrow = true);
378
379 static void trackAndDisplay(vpDot2 dot[], const unsigned int &n, vpImage<unsigned char> &I,
380 std::vector<vpImagePoint> &cogs, vpImagePoint *cogStar = nullptr);
381
382 // Static funtions
383 static void display(const vpImage<unsigned char> &I, const vpImagePoint &cog,
384 const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
385 unsigned int thickness = 1);
386 static void display(const vpImage<vpRGBa> &I, const vpImagePoint &cog, const std::list<vpImagePoint> &edges_list,
387 vpColor color = vpColor::red, unsigned int thickness = 1);
388
389#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
390public:
391#else
392private:
393#endif
394 double m00;
402 double m10;
410 double m01;
418 double m11;
425 double m20;
434 double m02;
443 double mu11;
448 double mu20;
453 double mu02;
458
459private:
460 virtual bool isValid(const vpImage<unsigned char> &I, const vpDot2 &wantedDot);
461
462 virtual bool hasGoodLevel(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v) const;
463 virtual bool hasReverseLevel(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v) const;
464
465 virtual vpDot2 *getInstance();
466
467 void init();
468
469 bool computeParameters(const vpImage<unsigned char> &I, const double &u = -1.0, const double &v = -1.0);
470
471 bool findFirstBorder(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v,
472 unsigned int &border_u, unsigned int &border_v);
473 void computeMeanGrayLevel(const vpImage<unsigned char> &I);
474
481 unsigned int getFirstBorder_u() const { return m_firstBorder_u; }
482
489 unsigned int getFirstBorder_v() const { return m_firstBorder_v; }
490
491 bool computeFreemanChainElement(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v,
492 unsigned int &element);
493 void computeFreemanParameters(const int &u_p, const int &v_p, unsigned int &element, int &du, int &dv, float &dS,
494 float &dMu, float &dMv, float &dMuv, float &dMu2, float &dMv2);
495 void updateFreemanPosition(unsigned int &u, unsigned int &v, const unsigned int &dir);
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, int u, int v, unsigned int w, unsigned int h);
504 void setArea(const vpImage<unsigned char> &I);
505 void setArea(const vpRect &a);
506
507 unsigned char getMeanGrayLevel(vpImage<unsigned char> &I) const;
508
509 typedef struct vpSearchDotsInAreaGoodGermData
510 {
511 const vpImage<unsigned char> &m_I;
512 const vpRect &m_area;
513 unsigned int &m_u;
514 unsigned int &m_v;
515 std::list<vpDot2> &m_niceDots;
516 std::list<vpDot2> &m_badDotsVector;
517
518 vpSearchDotsInAreaGoodGermData(const vpImage<unsigned char> &I, const vpRect &area,
519 unsigned int &u, unsigned int &v,
520 std::list<vpDot2> &niceDots, std::list<vpDot2> &badDotsVector)
521 : m_I(I)
522 , m_area(area)
523 , m_u(u)
524 , m_v(v)
525 , m_niceDots(niceDots)
526 , m_badDotsVector(badDotsVector)
527 {
528
529 }
530 } vpSearchDotsInAreaGoodGermData;
531
532 void searchDotsAreaGoodGerm(vpSearchDotsInAreaGoodGermData &data);
534 vpImagePoint m_cog;
535
536 double m_width;
537 double m_height;
538 double m_surface;
539 unsigned int m_gray_level_min; // minumum gray level for the dot. Pixel with lower level don't belong to this dot.
540
541 unsigned int m_gray_level_max; // maximum gray level for the dot. Pixel with higher level don't belong to this dot.
542 double m_mean_gray_level; // Mean gray level of the dot
543 double m_grayLevelPrecision;
544 double m_gamma;
545 double m_sizePrecision;
546 double m_ellipsoidShapePrecision;
547 double m_maxSizeSearchDistPrecision;
548 double m_allowedBadPointsPercentage;
549 // Area where the dot is to search
550 vpRect m_area;
551
552 // other
553 std::list<unsigned int> m_direction_list;
554 std::list<vpImagePoint> m_ip_edges_list;
555
556 // flag
557 bool m_compute_moment; // true moment are computed
558 bool m_graphics; // true for graphic overlay display
559
560 unsigned int m_thickness; // Graphics thickness
561
562 // Bounding box
563 int m_bbox_u_min, m_bbox_u_max, m_bbox_v_min, m_bbox_v_max;
564
565 // The first point coordinate on the dot border
566 unsigned int m_firstBorder_u;
567 unsigned int m_firstBorder_v;
568
569};
570
571END_VISP_NAMESPACE
572#endif
Implementation of column vector and the associated operations.
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
static const vpColor red
Definition vpColor.h:198
static const vpColor blue
Definition vpColor.h:204
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition vpDot2.h:127
unsigned int getGrayLevelMin() const
Definition vpDot2.h:221
vpDot2()
Definition vpDot2.cpp:109
unsigned int getGrayLevelMax() const
Definition vpDot2.h:227
double m02
Definition vpDot2.h:434
double m01
Definition vpDot2.h:410
void setGraphics(bool activate)
Definition vpDot2.h:320
void getEdges(std::list< vpImagePoint > &edges_list) const
Definition vpDot2.h:193
double mu11
Definition vpDot2.h:443
void setGraphicsThickness(unsigned int thickness)
Definition vpDot2.h:328
double getGamma() const
Definition vpDot2.h:215
void display(const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1) const
Definition vpDot2.cpp:219
double m20
Definition vpDot2.h:425
double m00
Definition vpDot2.h:394
void print(std::ostream &os)
Definition vpDot2.h:253
void setGrayLevelMax(const unsigned int &max)
Definition vpDot2.h:359
double getEllipsoidBadPointsPercentage() const
Definition vpDot2.h:210
double m11
Definition vpDot2.h:418
void setGrayLevelMin(const unsigned int &min)
Definition vpDot2.h:340
vpPolygon getPolygon() const
Definition vpDot2.h:241
vpRect getBBox() const
Definition vpDot2.h:168
void setCog(const vpImagePoint &ip)
Definition vpDot2.h:263
vpImagePoint getCog() const
Definition vpDot2.h:183
double m10
Definition vpDot2.h:402
void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
Definition vpDot2.h:292
double mu02
Definition vpDot2.h:453
double mu20
Definition vpDot2.h:448
std::list< vpImagePoint > getEdges() const
Definition vpDot2.h:202
double getMeanGrayLevel() const
Definition vpDot2.h:236
void setComputeMoments(bool activate)
Definition vpDot2.h:278
vpColVector get_nij() const
Definition vpDot2.h:147
static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage< unsigned char > &I, vpColor col=vpColor::blue, bool trackDot=true)
Definition vpDot2.cpp:1690
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
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
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition vpTracker.cpp:49
void init()
Default initialization.
Definition vpTracker.cpp:43
vpTracker()
Default constructor.
Definition vpTracker.cpp:45