46 #include <visp3/blob/vpDot.h> 47 #include <visp3/core/vpColor.h> 48 #include <visp3/core/vpDisplay.h> 49 #include <visp3/core/vpTrackingException.h> 72 compute_moment =
false;
75 maxDotSizePercentage = 0.25;
80 grayLevelPrecision = 0.85;
87 u_min = u_max = v_min = v_max = 0;
94 :
m00(0.),
m01(0.),
m10(0.),
m11(0.),
m20(0.),
m02(0.),
mu11(0.),
mu20(0.),
mu02(0.), ip_connexities_list(),
95 ip_edges_list(), connexityType(
CONNEXITY_4), cog(), u_min(0), u_max(0), v_min(0), v_max(0), graphics(false),
96 thickness(1), maxDotSizePercentage(0.25), gray_level_out(0), mean_gray_level(0), gray_level_min(128),
97 gray_level_max(255), grayLevelPrecision(0.85), gamma(1.5), compute_moment(false), nbMaxPoint(0)
107 :
m00(0.),
m01(0.),
m10(0.),
m11(0.),
m20(0.),
m02(0.),
mu11(0.),
mu20(0.),
mu02(0.), ip_connexities_list(),
108 ip_edges_list(), connexityType(
CONNEXITY_4), cog(ip), u_min(0), u_max(0), v_min(0), v_max(0), graphics(false),
109 thickness(1), maxDotSizePercentage(0.25), gray_level_out(0), mean_gray_level(0), gray_level_min(128),
110 gray_level_max(255), grayLevelPrecision(0.85), gamma(1.5), compute_moment(false), nbMaxPoint(0)
118 :
vpTracker(d),
m00(0.),
m01(0.),
m10(0.),
m11(0.),
m20(0.),
m02(0.),
mu11(0.),
mu20(0.),
mu02(0.),
119 ip_connexities_list(), ip_edges_list(), connexityType(
CONNEXITY_4), cog(), u_min(0), u_max(0), v_min(0), v_max(0),
120 graphics(false), thickness(1), maxDotSizePercentage(0.25), gray_level_out(0), mean_gray_level(0),
121 gray_level_min(128), gray_level_max(255), grayLevelPrecision(0.85), gamma(1.5), compute_moment(false), nbMaxPoint(0)
136 ip_edges_list = d.ip_edges_list;
137 ip_connexities_list = d.ip_connexities_list;
138 connexityType = d.connexityType;
146 graphics = d.graphics;
147 thickness = d.thickness;
148 maxDotSizePercentage = d.maxDotSizePercentage;
149 gray_level_out = d.gray_level_out;
150 mean_gray_level = d.mean_gray_level;
151 gray_level_min = d.gray_level_min;
152 gray_level_max = d.gray_level_max;
153 grayLevelPrecision = d.grayLevelPrecision;
155 compute_moment = d.compute_moment;
156 nbMaxPoint = d.nbMaxPoint;
187 void vpDot::setGrayLevelOut()
189 if (gray_level_min == 0) {
190 if (gray_level_max == 255) {
195 gray_level_out =
static_cast<unsigned char>(gray_level_max + 1u);
216 bool vpDot::connexe(
const vpImage<unsigned char> &I,
unsigned int u,
unsigned int v,
double &mean_value,
double &u_cog,
217 double &v_cog,
double &n)
220 return connexe(I, u, v, mean_value, u_cog, v_cog, n, checkTab);
239 bool vpDot::connexe(
const vpImage<unsigned char> &I,
unsigned int u,
unsigned int v,
double &mean_value,
double &u_cog,
240 double &v_cog,
double &n, std::vector<bool> &checkTab)
247 if ((u >= width) || (v >= height)) {
259 if (I[v][u] >= gray_level_min && I[v][u] <= gray_level_max) {
260 checkTab[v * I.
getWidth() + u] =
true;
262 ip_connexities_list.push_back(ip);
268 if (n > nbMaxPoint) {
276 "Too many point %lf (%lf%% of image size). " 277 "This threshold can be modified using the setMaxDotSize() " 293 mean_value = (mean_value * (n - 1) + I[v][u]) / n;
294 if (compute_moment ==
true) {
311 if (!checkTab[u - 1 + v * I.
getWidth()])
312 if (!connexe(I, u - 1, v, mean_value, u_cog, v_cog, n, checkTab))
316 if (!checkTab[u + 1 + v * I.
getWidth()])
317 if (!connexe(I, u + 1, v, mean_value, u_cog, v_cog, n, checkTab))
321 if (!checkTab[u + (v - 1) * I.
getWidth()])
322 if (!connexe(I, u, v - 1, mean_value, u_cog, v_cog, n, checkTab))
326 if (!checkTab[u + (v + 1) * I.
getWidth()])
327 if (!connexe(I, u, v + 1, mean_value, u_cog, v_cog, n, checkTab))
331 if (v >= 1 && u >= 1)
332 if (!checkTab[u - 1 + (v - 1) * I.
getWidth()])
333 if (!connexe(I, u - 1, v - 1, mean_value, u_cog, v_cog, n, checkTab))
337 if (!checkTab[u + 1 + (v - 1) * I.
getWidth()])
338 if (!connexe(I, u + 1, v - 1, mean_value, u_cog, v_cog, n, checkTab))
342 if (!checkTab[u - 1 + (v + 1) * I.
getWidth()])
343 if (!connexe(I, u - 1, v + 1, mean_value, u_cog, v_cog, n, checkTab))
347 if (!checkTab[u + 1 + (v + 1) * I.
getWidth()])
348 if (!connexe(I, u + 1, v + 1, mean_value, u_cog, v_cog, n, checkTab))
353 ip_edges_list.push_back(ip);
354 if (graphics ==
true) {
356 for (
unsigned int t = 0; t < thickness; t++) {
400 this->mean_gray_level = 0;
402 ip_connexities_list.clear();
403 ip_edges_list.clear();
413 if ( connexe(I, (
unsigned int)u, (
unsigned int)v,
414 gray_level_min, gray_level_max,
415 mean_gray_level, u_cog, v_cog, npoint) == vpDot::out)
419 for (pas = 2 ; pas <= 25 ; pas ++ )
if (sol==
false)
421 for (
int k=-1 ; k <=1 ; k++)
if (sol==
false)
422 for (
int l=-1 ; l <=1 ; l++)
if (sol==
false)
426 ip_connexities_list.clear() ;
428 this->mean_gray_level = 0 ;
429 if (connexe(I, (
unsigned int)(u+k*pas),(
unsigned int)(v+l*pas),
430 gray_level_min, gray_level_max,
431 mean_gray_level, u_cog, v_cog, npoint) != vpDot::out)
433 sol = true ; u += k*pas ; v += l*pas ;
441 "Dot has been lost")) ;
446 if (!connexe(I, (
unsigned int)u, (
unsigned int)v, mean_gray_level, u_cog, v_cog, npoint)) {
449 unsigned int right = 1;
450 unsigned int botom = 1;
451 unsigned int left = 2;
453 double u_ = u, v_ = v;
458 for (k = 1; k <= right; k++)
462 ip_connexities_list.clear();
463 ip_edges_list.clear();
465 this->mean_gray_level = 0;
466 if (connexe(I, (
unsigned int)u_ + k, (
unsigned int)(v_), mean_gray_level, u_cog, v_cog, npoint)) {
475 for (k = 1; k <= botom; k++)
479 ip_connexities_list.clear();
480 ip_edges_list.clear();
482 this->mean_gray_level = 0;
484 if (connexe(I, (
unsigned int)(u_), (
unsigned int)(v_ + k), mean_gray_level, u_cog, v_cog, npoint)) {
493 for (k = 1; k <= left; k++)
497 ip_connexities_list.clear();
498 ip_edges_list.clear();
500 this->mean_gray_level = 0;
502 if (connexe(I, (
unsigned int)(u_ - k), (
unsigned int)(v_), mean_gray_level, u_cog, v_cog, npoint)) {
511 for (k = 1; k <= up; k++)
515 ip_connexities_list.clear();
516 ip_edges_list.clear();
518 this->mean_gray_level = 0;
520 if (connexe(I, (
unsigned int)(u_), (
unsigned int)(v_ - k), mean_gray_level, u_cog, v_cog, npoint)) {
546 u_cog = u_cog / npoint;
547 v_cog = v_cog / npoint;
553 double Ip = pow((
double)this->mean_gray_level / 255, 1 / gamma);
555 if (Ip - (1 - grayLevelPrecision) < 0) {
558 gray_level_min = (
unsigned int)(255 * pow(Ip - (1 - grayLevelPrecision), gamma));
559 if (gray_level_min > 255)
560 gray_level_min = 255;
562 gray_level_max = (
unsigned int)(255 * pow(Ip + (1 - grayLevelPrecision), gamma));
563 if (gray_level_max > 255)
564 gray_level_max = 255;
574 if (npoint > nbMaxPoint) {
582 "Too many point %lf (%lf%%). Max allowed is " 583 "%lf (%lf%%). This threshold can be modified " 584 "using the setMaxDotSize() method.",
585 npoint, npoint / (I.
getWidth() * I.
getHeight()), nbMaxPoint, maxDotSizePercentage));
603 if (percentage <= 0.0 || percentage > 1.0) {
605 vpTRACE(
"Max dot size percentage is requested to be set to %lf.",
606 "Value should be in ]0:1]. Value will be set to %lf.", percentage, maxDotSizePercentage);
608 maxDotSizePercentage = percentage;
640 unsigned int i = (
unsigned int)cog.
get_i();
641 unsigned int j = (
unsigned int)cog.
get_j();
643 double Ip = pow((
double)I[i][j] / 255, 1 / gamma);
645 if (Ip - (1 - grayLevelPrecision) < 0) {
648 gray_level_min = (
unsigned int)(255 * pow(Ip - (1 - grayLevelPrecision), gamma));
649 if (gray_level_min > 255)
650 gray_level_min = 255;
652 gray_level_max = (
unsigned int)(255 * pow(Ip + (1 - grayLevelPrecision), gamma));
653 if (gray_level_max > 255)
654 gray_level_max = 255;
691 unsigned int i = (
unsigned int)cog.
get_i();
692 unsigned int j = (
unsigned int)cog.
get_j();
694 double Ip = pow((
double)I[i][j] / 255, 1 / gamma);
696 if (Ip - (1 - grayLevelPrecision) < 0) {
699 gray_level_min = (
unsigned int)(255 * pow(Ip - (1 - grayLevelPrecision), gamma));
700 if (gray_level_min > 255)
701 gray_level_min = 255;
703 gray_level_max = (
unsigned int)(255 * pow(Ip + (1 - grayLevelPrecision), gamma));
704 if (gray_level_max > 255)
705 gray_level_max = 255;
741 unsigned int level_max)
746 this->gray_level_min = level_min;
747 this->gray_level_max = level_max;
774 double u = this->cog.
get_u();
775 double v = this->cog.
get_v();
782 if (compute_moment ==
true) {
829 std::list<vpImagePoint>::const_iterator it;
831 for (it = ip_edges_list.begin(); it != ip_edges_list.end(); ++it) {
856 double epsilon = 0.05;
857 if (grayLevelPrecision < epsilon) {
858 this->grayLevelPrecision = epsilon;
859 }
else if (grayLevelPrecision > 1) {
860 this->grayLevelPrecision = 1.0;
862 this->grayLevelPrecision = precision;
881 vpColor color,
unsigned int thickness)
884 std::list<vpImagePoint>::const_iterator it;
886 for (it = edges_list.begin(); it != edges_list.end(); ++it) {
906 vpColor color,
unsigned int thickness)
909 std::list<vpImagePoint>::const_iterator it;
911 for (it = edges_list.begin(); it != edges_list.end(); ++it) {
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, vpDot &d)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setMaxDotSize(double percentage)
void setGrayLevelPrecision(const double &grayLevelPrecision)
Class to define colors available for display functionnalities.
void track(const vpImage< unsigned char > &I)
error that can be emited by ViSP classes.
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static const unsigned int SPIRAL_SEARCH_SIZE
Class that defines what is a feature generic tracker.
vpImagePoint getCog() const
Error that can be emited by the vpTracker class and its derivates.
bool operator==(const vpDot &d) const
vpDot & operator=(const vpDot &d)
Copy operator.
void set_u(const double u)
void set_v(const double v)
bool operator!=(const vpDot &d) const
void display(const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1) const
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
unsigned int getHeight() const
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
void initTracking(const vpImage< unsigned char > &I)
virtual ~vpDot()
Destructor.