45 #include <visp3/blob/vpDot.h>
46 #include <visp3/core/vpDisplay.h>
47 #include <visp3/core/vpColor.h>
48 #include <visp3/core/vpTrackingException.h>
71 compute_moment = false ;
74 maxDotSizePercentage = 0.25 ;
79 grayLevelPrecision = 0.85;
86 u_min = u_max = v_min = v_max = 0;
93 : m00(0.), m01(0.), m10(0.), m11(0.), m20(0.), m02(0.),
94 mu11(0.), mu20(0.), mu02(0.), ip_connexities_list(), ip_edges_list(), connexityType(CONNEXITY_4),
95 cog(), u_min(0), u_max(0), v_min(0), v_max(0), graphics(false), thickness(1), maxDotSizePercentage(0.25),
96 gray_level_out(0), mean_gray_level(0), gray_level_min(128), gray_level_max(255), grayLevelPrecision(0.85),
97 gamma(1.5), compute_moment(false), nbMaxPoint(0)
107 : m00(0.), m01(0.), m10(0.), m11(0.), m20(0.), m02(0.),
108 mu11(0.), mu20(0.), mu02(0.), ip_connexities_list(), ip_edges_list(), connexityType(CONNEXITY_4),
109 cog(), u_min(0), u_max(0), v_min(0), v_max(0), graphics(false), thickness(1), maxDotSizePercentage(0.25),
110 gray_level_out(0), mean_gray_level(0), gray_level_min(128), gray_level_max(255), grayLevelPrecision(0.85),
111 gamma(1.5), compute_moment(false), nbMaxPoint(0)
121 m00(0.), m01(0.), m10(0.), m11(0.), m20(0.), m02(0.),
122 mu11(0.), mu20(0.), mu02(0.), ip_connexities_list(), ip_edges_list(), connexityType(CONNEXITY_4),
123 cog(), u_min(0), u_max(0), v_min(0), v_max(0), graphics(false), thickness(1), maxDotSizePercentage(0.25),
124 gray_level_out(0), mean_gray_level(0), gray_level_min(128), gray_level_max(255), grayLevelPrecision(0.85),
125 gamma(1.5), compute_moment(false), nbMaxPoint(0)
135 ip_connexities_list.clear() ;
144 ip_edges_list = d.ip_edges_list;
145 ip_connexities_list = d.ip_connexities_list;
146 connexityType = d.connexityType;
154 graphics = d.graphics ;
155 thickness = d.thickness;
156 maxDotSizePercentage = d.maxDotSizePercentage;
157 gray_level_out = d.gray_level_out;
158 mean_gray_level = d.mean_gray_level ;
159 gray_level_min = d.gray_level_min ;
160 gray_level_max = d.gray_level_max ;
161 grayLevelPrecision = d.grayLevelPrecision;
163 compute_moment = d.compute_moment ;
164 nbMaxPoint = d.nbMaxPoint;
183 return ( cog != d.
getCog() );
189 return ( cog == d.
getCog() );
204 vpDot::setGrayLevelOut()
206 if (gray_level_min == 0) {
207 if (gray_level_max == 255) {
211 "Unable to choose a good \"out\" level")) ;
213 gray_level_out =
static_cast<unsigned char>(gray_level_max + 1u);
235 double &mean_value,
double &u_cog,
double &v_cog,
double &n)
238 return connexe(I,u,v,mean_value,u_cog,v_cog,n,checkTab);
258 double &mean_value,
double &u_cog,
double &v_cog,
double &n,std::vector<bool> &checkTab)
265 if ( (u >= width) || (v >= height) )
278 if (I[v][u] >= gray_level_min && I[v][u] <= gray_level_max)
280 checkTab[v*I.
getWidth() + u] =
true;
282 ip_connexities_list.push_back(ip);
288 if (n > nbMaxPoint) {
296 "Too many point %lf (%lf%% of image size). "
297 "This threshold can be modified using the setMaxDotSize() "
300 nbMaxPoint, maxDotSizePercentage)) ;
304 if (u < this->u_min) this->u_min = u;
305 if (u > this->u_max) this->u_max = u;
306 if (v < this->v_min) this->v_min = v;
307 if (v > this->v_max) this->v_max = v;
310 mean_value = (mean_value *(n-1) + I[v][u]) / n;
311 if (compute_moment==
true)
332 if(!connexe(I,u-1,v, mean_value,u_cog,v_cog, n, checkTab))
337 if(!connexe(I,u+1,v,mean_value,u_cog, v_cog, n, checkTab))
342 if(!connexe(I,u, v-1,mean_value,u_cog, v_cog, n, checkTab))
347 if(!connexe(I,u,v+1,mean_value,u_cog, v_cog, n, checkTab))
352 if(!checkTab[u-1+(v-1)*I.
getWidth()])
353 if(!connexe(I,u-1,v-1,mean_value,u_cog, v_cog, n, checkTab))
357 if(!checkTab[u+1+(v-1)*I.
getWidth()])
358 if(!connexe(I,u+1,v-1,mean_value,u_cog, v_cog, n, checkTab))
362 if(!checkTab[u-1+(v+1)*I.
getWidth()])
363 if(!connexe(I,u-1,v+1,mean_value, u_cog, v_cog, n, checkTab))
367 if(!checkTab[u+1+(v+1)*I.
getWidth()])
368 if(!connexe(I,u+1,v+1,mean_value,u_cog, v_cog, n, checkTab))
373 ip_edges_list.push_back(ip);
377 for(
unsigned int t=0; t<thickness; t++) {
378 ip_.set_u(ip.
get_u() + t);
422 this->mean_gray_level = 0 ;
424 ip_connexities_list.clear() ;
425 ip_edges_list.clear();
435 if ( connexe(I, (
unsigned int)u, (
unsigned int)v,
436 gray_level_min, gray_level_max,
437 mean_gray_level, u_cog, v_cog, npoint) == vpDot::out)
441 for (pas = 2 ; pas <= 25 ; pas ++ )
if (sol==
false)
443 for (
int k=-1 ; k <=1 ; k++)
if (sol==
false)
444 for (
int l=-1 ; l <=1 ; l++)
if (sol==
false)
448 ip_connexities_list.clear() ;
450 this->mean_gray_level = 0 ;
451 if (connexe(I, (
unsigned int)(u+k*pas),(
unsigned int)(v+l*pas),
452 gray_level_min, gray_level_max,
453 mean_gray_level, u_cog, v_cog, npoint) != vpDot::out)
455 sol = true ; u += k*pas ; v += l*pas ;
463 "Dot has been lost")) ;
468 if ( !connexe(I,(
unsigned int)u,(
unsigned int)v, mean_gray_level, u_cog, v_cog, npoint) )
472 unsigned int right = 1;
473 unsigned int botom = 1;
474 unsigned int left = 2;
476 double u_ = u, v_ = v;
481 for (k=1; k <= right; k++)
if(sol==
false) {
484 ip_connexities_list.clear() ;
485 ip_edges_list.clear();
487 this->mean_gray_level = 0 ;
488 if ( connexe(I, (
unsigned int)u_+k, (
unsigned int)(v_),mean_gray_level, u_cog, v_cog, npoint) ) {
489 sol =
true; u = u_+k; v = v_;
495 for (k=1; k <= botom; k++)
if (sol==
false) {
498 ip_connexities_list.clear() ;
499 ip_edges_list.clear();
501 this->mean_gray_level = 0 ;
503 if ( connexe(I, (
unsigned int)(u_), (
unsigned int)(v_+k),mean_gray_level, u_cog, v_cog, npoint) ) {
504 sol =
true; u = u_; v = v_+k;
510 for (k=1; k <= left; k++)
if (sol==
false) {
513 ip_connexities_list.clear() ;
514 ip_edges_list.clear();
516 this->mean_gray_level = 0 ;
518 if ( connexe(I, (
unsigned int)(u_-k), (
unsigned int)(v_),mean_gray_level,u_cog, v_cog, npoint) ) {
519 sol = true ; u = u_-k; v = v_;
525 for (k=1; k <= up; k++)
if(sol==
false) {
528 ip_connexities_list.clear() ;
529 ip_edges_list.clear();
531 this->mean_gray_level = 0 ;
533 if ( connexe(I, (
unsigned int)(u_), (
unsigned int)(v_-k),mean_gray_level,u_cog, v_cog, npoint) ) {
534 sol = true ; u = u_; v = v_-k;
544 "Dot has been lost")) ;
560 u_cog = u_cog/npoint ;
561 v_cog = v_cog/npoint ;
567 double Ip = pow((
double)this->mean_gray_level/255,1/gamma);
569 if(Ip - (1 - grayLevelPrecision)<0){
573 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
574 if (gray_level_min > 255)
575 gray_level_min = 255;
577 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
578 if (gray_level_max > 255)
579 gray_level_max = 255;
591 if (npoint > nbMaxPoint)
598 "Too many point %lf (%lf%%). Max allowed is %lf (%lf%%). This threshold can be modified using the setMaxDotSize() method.",
600 nbMaxPoint, maxDotSizePercentage)) ;
619 if (percentage <= 0.0 || percentage > 1.0) {
621 vpTRACE(
"Max dot size percentage is requested to be set to %lf.",
622 "Value should be in ]0:1]. Value will be set to %lf.",
623 percentage, maxDotSizePercentage);
626 maxDotSizePercentage = percentage;
658 unsigned int i = (
unsigned int)cog.
get_i();
659 unsigned int j = (
unsigned int)cog.
get_j();
661 double Ip = pow((
double)I[i][j]/255, 1/gamma);
663 if(Ip - (1 - grayLevelPrecision)<0){
667 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
668 if (gray_level_min > 255)
669 gray_level_min = 255;
671 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
672 if (gray_level_max > 255)
673 gray_level_max = 255;
713 unsigned int i = (
unsigned int)cog.
get_i();
714 unsigned int j = (
unsigned int)cog.
get_j();
716 double Ip = pow((
double)I[i][j]/255, 1/gamma);
718 if(Ip - (1 - grayLevelPrecision)<0){
722 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
723 if (gray_level_min > 255)
724 gray_level_min = 255;
726 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
727 if (gray_level_max > 255)
728 gray_level_max = 255;
767 unsigned int level_min,
unsigned int level_max)
772 this->gray_level_min = level_min;
773 this->gray_level_max = level_max;
804 double u = this->cog.
get_u();
805 double v = this->cog.
get_v();
809 this->cog.
set_u( u );
810 this->cog.
set_v( v );
812 if (compute_moment==
true)
863 std::list<vpImagePoint>::const_iterator it;
865 for (it = ip_edges_list.begin(); it != ip_edges_list.end(); ++it)
890 double epsilon = 0.05;
891 if( grayLevelPrecision<epsilon )
893 this->grayLevelPrecision = epsilon;
895 else if( grayLevelPrecision>1 )
897 this->grayLevelPrecision = 1.0;
901 this->grayLevelPrecision = precision;
920 const std::list<vpImagePoint> &edges_list,
vpColor color,
921 unsigned int thickness)
924 std::list<vpImagePoint>::const_iterator it;
926 for (it = edges_list.begin(); it != edges_list.end(); ++it)
947 const std::list<vpImagePoint> &edges_list,
vpColor color,
948 unsigned int thickness)
951 std::list<vpImagePoint>::const_iterator it;
953 for (it = edges_list.begin(); it != edges_list.end(); ++it)
965 return (os <<
"(" << d.
getCog() <<
")" ) ;
bool operator!=(const vpDot &d)
void setMaxDotSize(double percentage)
unsigned int getWidth() const
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 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.
vpDot & operator=(const vpDot &d)
Copy operator.
void set_u(const double u)
void display(const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1) const
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
void set_v(const double v)
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
unsigned int getHeight() const
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
bool operator==(const vpDot &d)
void initTracking(const vpImage< unsigned char > &I)
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0
virtual ~vpDot()
Destructor.