Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpDot2.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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 https://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*****************************************************************************/
35
36/*
37 \file vpDot2.h
38 \brief This tracker is meant to track some zones on a vpImage.
39*/
40
41#ifndef vpDot2_hh
42#define vpDot2_hh
43
44#include <visp3/core/vpColor.h>
45#include <visp3/core/vpImage.h>
46#include <visp3/core/vpImagePoint.h>
47#include <visp3/core/vpPolygon.h>
48#include <visp3/core/vpRect.h>
49#include <visp3/core/vpTracker.h>
50
51#include <list>
52#include <vector>
53
123class VISP_EXPORT vpDot2 : public vpTracker
124{
125public:
126 vpDot2();
127 explicit vpDot2(const vpImagePoint &ip);
128 vpDot2(const vpDot2 &twinDot);
129 virtual ~vpDot2();
130
131 static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage<unsigned char> &I,
132 vpColor col = vpColor::blue, bool trackDot = true);
133
134 void display(const vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1) const;
135
145 inline vpColVector get_nij() const
146 {
147 vpColVector nij(3);
148 nij[0] = mu20 / m00;
149 nij[1] = mu11 / m00;
150 nij[2] = mu02 / m00;
151
152 return nij;
153 }
154
155 double getArea() const;
163 inline vpRect getBBox() const
164 {
165 vpRect bbox;
166
167 bbox.setRect(this->bbox_u_min, this->bbox_v_min, this->bbox_u_max - this->bbox_u_min + 1,
168 this->bbox_v_max - this->bbox_v_min + 1);
169
170 return (bbox);
171 };
177 inline vpImagePoint getCog() const { return cog; }
178
179 double getDistance(const vpDot2 &distantDot) const;
189 void getEdges(std::list<vpImagePoint> &edges_list) const { edges_list = this->ip_edges_list; };
199 std::list<vpImagePoint> getEdges() const { return (this->ip_edges_list); };
206 double getEllipsoidBadPointsPercentage() const { return allowedBadPointsPercentage_; }
207
208 double getEllipsoidShapePrecision() const;
209 void getFreemanChain(std::list<unsigned int> &freeman_chain) const;
210
211 inline double getGamma() const { return this->gamma; };
217 inline unsigned int getGrayLevelMin() const { return gray_level_min; };
223 inline unsigned int getGrayLevelMax() const { return gray_level_max; };
224 double getGrayLevelPrecision() const;
225
226 double getHeight() const;
227 double getMaxSizeSearchDistancePrecision() const;
231 double getMeanGrayLevel() const { return (this->mean_gray_level); };
235 vpPolygon getPolygon() const { return (vpPolygon(ip_edges_list)); };
236 double getSizePrecision() const;
237 double getWidth() const;
238
239 void initTracking(const vpImage<unsigned char> &I, unsigned int size = 0);
240 void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int size = 0);
241 void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int gray_lvl_min,
242 unsigned int gray_lvl_max, unsigned int size = 0);
243
244 vpDot2 &operator=(const vpDot2 &twinDot);
245 friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpDot2 &d);
246
247 void print(std::ostream &os) { os << *this << std::endl; }
248 void searchDotsInArea(const vpImage<unsigned char> &I, int area_u, int area_v, unsigned int area_w,
249 unsigned int area_h, std::list<vpDot2> &niceDots);
250
251 void searchDotsInArea(const vpImage<unsigned char> &I, std::list<vpDot2> &niceDots);
252
253 void setArea(const double &area);
257 inline void setCog(const vpImagePoint &ip) { this->cog = ip; }
273 void setComputeMoments(bool activate) { compute_moment = activate; }
274
287 void setEllipsoidBadPointsPercentage(const double &percentage = 0.0)
288 {
289 if (percentage < 0.)
290 allowedBadPointsPercentage_ = 0.;
291 else if (percentage > 1.)
292 allowedBadPointsPercentage_ = 1.;
293 else
294 allowedBadPointsPercentage_ = percentage;
295 }
296
297 void setEllipsoidShapePrecision(const double &ellipsoidShapePrecision);
311 void setGraphics(bool activate) { graphics = activate; }
318 void setGraphicsThickness(unsigned int t) { this->thickness = t; };
331 inline void setGrayLevelMin(const unsigned int &min)
332 {
333 if (min > 255)
334 this->gray_level_min = 255;
335 else
336 this->gray_level_min = min;
337 };
338
348 inline void setGrayLevelMax(const unsigned int &max)
349 {
350 if (max > 255)
351 this->gray_level_max = 255;
352 else
353 this->gray_level_max = max;
354 };
355 void setGrayLevelPrecision(const double &grayLevelPrecision);
356 void setHeight(const double &height);
357 void setMaxSizeSearchDistancePrecision(const double &maxSizeSearchDistancePrecision);
358 void setSizePrecision(const double &sizePrecision);
359 void setWidth(const double &width);
360
361 void track(const vpImage<unsigned char> &I, bool canMakeTheWindowGrow = true);
362 void track(const vpImage<unsigned char> &I, vpImagePoint &cog, bool canMakeTheWindowGrow = true);
363
364 static void trackAndDisplay(vpDot2 dot[], const unsigned int &n, vpImage<unsigned char> &I,
365 std::vector<vpImagePoint> &cogs, vpImagePoint *cogStar = NULL);
366
367#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
368public:
369#else
370private:
371#endif
372 double m00;
380 double m10;
388 double m01;
396 double m11;
403 double m20;
412 double m02;
421 double mu11;
426 double mu20;
431 double mu02;
437private:
438 virtual bool isValid(const vpImage<unsigned char> &I, const vpDot2 &wantedDot);
439
440 virtual bool hasGoodLevel(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v) const;
441 virtual bool hasReverseLevel(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v) const;
442
443 virtual vpDot2 *getInstance();
444
445 void init();
446
447 bool computeParameters(const vpImage<unsigned char> &I, const double &u = -1.0, const double &v = -1.0);
448
449 bool findFirstBorder(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v,
450 unsigned int &border_u, unsigned int &border_v);
451 void computeMeanGrayLevel(const vpImage<unsigned char> &I);
452
461 unsigned int getFirstBorder_u() const { return this->firstBorder_u; }
470 unsigned int getFirstBorder_v() const { return this->firstBorder_v; }
471
472 bool computeFreemanChainElement(const vpImage<unsigned char> &I, const unsigned int &u, const unsigned int &v,
473 unsigned int &element);
474 void computeFreemanParameters(const int &u_p, const int &v_p, unsigned int &element, int &du, int &dv, float &dS,
475 float &dMu, float &dMv, float &dMuv, float &dMu2, float &dMv2);
476 void updateFreemanPosition(unsigned int &u, unsigned int &v, const unsigned int &dir);
477
478 bool isInImage(const vpImage<unsigned char> &I) const;
479 bool isInImage(const vpImage<unsigned char> &I, const vpImagePoint &ip) const;
480
481 bool isInArea(const unsigned int &u, const unsigned int &v) const;
482
483 void getGridSize(unsigned int &gridWidth, unsigned int &gridHeight);
484 void setArea(const vpImage<unsigned char> &I, int u, int v, unsigned int w, unsigned int h);
485 void setArea(const vpImage<unsigned char> &I);
486 void setArea(const vpRect &a);
487
488 unsigned char getMeanGrayLevel(vpImage<unsigned char> &I) const;
490 vpImagePoint cog;
491
492 double width;
493 double height;
494 double surface;
495 unsigned int gray_level_min; // minumum gray level for the dot.
496 // pixel with lower level don't belong
497 // to this dot.
498
499 unsigned int gray_level_max; // maximum gray level for the dot.
500 // pixel with higher level don't belong
501 // to this dot.
502 double mean_gray_level; // Mean gray level of the dot
503 double grayLevelPrecision;
504 double gamma;
505 double sizePrecision;
506 double ellipsoidShapePrecision;
507 double maxSizeSearchDistancePrecision;
508 double allowedBadPointsPercentage_;
509 // Area where the dot is to search
510 vpRect area;
511
512 // other
513 std::list<unsigned int> direction_list;
514 std::list<vpImagePoint> ip_edges_list;
515
516 // flag
517 bool compute_moment; // true moment are computed
518 bool graphics; // true for graphic overlay display
519
520 unsigned int thickness; // Graphics thickness
521
522 // Bounding box
523 int bbox_u_min, bbox_u_max, bbox_v_min, bbox_v_max;
524
525 // The first point coodinate on the dot border
526 unsigned int firstBorder_u;
527 unsigned int firstBorder_v;
528
529 // Static funtions
530public:
531 static void display(const vpImage<unsigned char> &I, const vpImagePoint &cog,
532 const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
533 unsigned int thickness = 1);
534 static void display(const vpImage<vpRGBa> &I, const vpImagePoint &cog, const std::list<vpImagePoint> &edges_list,
535 vpColor color = vpColor::red, unsigned int thickness = 1);
536};
537
538#endif
Implementation of column vector and the associated operations.
Class to define RGB colors available for display functionalities.
Definition vpColor.h:152
static const vpColor red
Definition vpColor.h:211
static const vpColor blue
Definition vpColor.h:217
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition vpDot2.h:124
unsigned int getGrayLevelMin() const
Definition vpDot2.h:217
unsigned int getGrayLevelMax() const
Definition vpDot2.h:223
double m02
Definition vpDot2.h:412
double m01
Definition vpDot2.h:388
void setGraphics(bool activate)
Definition vpDot2.h:311
void getEdges(std::list< vpImagePoint > &edges_list) const
Definition vpDot2.h:189
double mu11
Definition vpDot2.h:421
void setGraphicsThickness(unsigned int t)
Definition vpDot2.h:318
double getGamma() const
Definition vpDot2.h:211
double m20
Definition vpDot2.h:403
double m00
Definition vpDot2.h:372
void print(std::ostream &os)
Definition vpDot2.h:247
void setGrayLevelMax(const unsigned int &max)
Definition vpDot2.h:348
double getEllipsoidBadPointsPercentage() const
Definition vpDot2.h:206
double m11
Definition vpDot2.h:396
void setGrayLevelMin(const unsigned int &min)
Definition vpDot2.h:331
vpPolygon getPolygon() const
Definition vpDot2.h:235
vpRect getBBox() const
Definition vpDot2.h:163
void setCog(const vpImagePoint &ip)
Definition vpDot2.h:257
vpImagePoint getCog() const
Definition vpDot2.h:177
double m10
Definition vpDot2.h:380
void setEllipsoidBadPointsPercentage(const double &percentage=0.0)
Definition vpDot2.h:287
double mu02
Definition vpDot2.h:431
double mu20
Definition vpDot2.h:426
std::list< vpImagePoint > getEdges() const
Definition vpDot2.h:199
double getMeanGrayLevel() const
Definition vpDot2.h:231
void setComputeMoments(bool activate)
Definition vpDot2.h:273
vpColVector get_nij() const
Definition vpDot2.h:145
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:135
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:152
Defines a generic 2D polygon.
Definition vpPolygon.h:97
Defines a rectangle in the plane.
Definition vpRect.h:76
void setRect(double l, double t, double w, double h)
Definition vpRect.h:330
Class that defines what is a feature generic tracker.
Definition vpTracker.h:60
vpTracker & operator=(const vpTracker &tracker)
Copy operator.
Definition vpTracker.cpp:50
void init()
Default initialization.
Definition vpTracker.cpp:44