49 #include <visp/vpDot.h>
51 #include <visp/vpDisplay.h>
52 #include <visp/vpColor.h>
55 #include <visp/vpTrackingException.h>
77 compute_moment = false ;
80 maxDotSizePercentage = 0.25 ;
85 grayLevelPrecision = 0.85;
92 u_min = u_max = v_min = v_max = 0;
129 ip_connexities_list.clear() ;
140 graphics = d.graphics ;
141 thickness = d.thickness;
142 mean_gray_level = d.mean_gray_level ;
143 gray_level_min = d.gray_level_min ;
144 gray_level_max = d.gray_level_max ;
145 grayLevelPrecision = d.grayLevelPrecision;
146 compute_moment = d.compute_moment ;
148 maxDotSizePercentage = d.maxDotSizePercentage;
164 gray_level_out = d.gray_level_out;
167 nbMaxPoint = d.nbMaxPoint;
175 return ( cog != d.
getCog() );
181 return ( cog == d.
getCog() );
196 vpDot::setGrayLevelOut()
198 if (gray_level_min == 0) {
199 if (gray_level_max == 255) {
203 "Unable to choose a good \"out\" level")) ;
205 gray_level_out =
static_cast<unsigned char>(gray_level_max + 1u);
227 double &mean_value,
double &u_cog,
double &v_cog,
double &n)
230 return connexe(I,u,v,mean_value,u_cog,v_cog,n,checkTab);
250 double &mean_value,
double &u_cog,
double &v_cog,
double &n,std::vector<bool> &checkTab)
257 if ( (u >= width) || (v >= height) )
270 if (I[v][u] >= gray_level_min && I[v][u] <= gray_level_max)
272 checkTab[v*I.
getWidth() + u] =
true;
274 ip_connexities_list.push_back(ip);
280 if (n > nbMaxPoint) {
282 "This threshold can be modified using the setMaxDotSize() "
285 nbMaxPoint, maxDotSizePercentage) ;
292 if (u < this->u_min) this->u_min = u;
293 if (u > this->u_max) this->u_max = u;
294 if (v < this->v_min) this->v_min = v;
295 if (v > this->v_max) this->v_max = v;
298 mean_value = (mean_value *(n-1) + I[v][u]) / n;
299 if (compute_moment==
true)
320 if(!connexe(I,u-1,v, mean_value,u_cog,v_cog, n, checkTab))
325 if(!connexe(I,u+1,v,mean_value,u_cog, v_cog, n, checkTab))
330 if(!connexe(I,u, v-1,mean_value,u_cog, v_cog, n, checkTab))
335 if(!connexe(I,u,v+1,mean_value,u_cog, v_cog, n, checkTab))
340 if(!checkTab[u-1+(v-1)*I.
getWidth()])
341 if(!connexe(I,u-1,v-1,mean_value,u_cog, v_cog, n, checkTab))
345 if(!checkTab[u+1+(v-1)*I.
getWidth()])
346 if(!connexe(I,u+1,v-1,mean_value,u_cog, v_cog, n, checkTab))
350 if(!checkTab[u-1+(v+1)*I.
getWidth()])
351 if(!connexe(I,u-1,v+1,mean_value, u_cog, v_cog, n, checkTab))
355 if(!checkTab[u+1+(v+1)*I.
getWidth()])
356 if(!connexe(I,u+1,v+1,mean_value,u_cog, v_cog, n, checkTab))
361 ip_edges_list.push_back(ip);
365 for(
unsigned int t=0; t<thickness; t++) {
366 ip_.set_u(ip.
get_u() + t);
410 this->mean_gray_level = 0 ;
412 ip_connexities_list.clear() ;
413 ip_edges_list.clear();
423 if ( connexe(I, (
unsigned int)u, (
unsigned int)v,
424 gray_level_min, gray_level_max,
425 mean_gray_level, u_cog, v_cog, npoint) == vpDot::out)
429 for (pas = 2 ; pas <= 25 ; pas ++ )
if (sol==
false)
431 for (
int k=-1 ; k <=1 ; k++)
if (sol==
false)
432 for (
int l=-1 ; l <=1 ; l++)
if (sol==
false)
436 ip_connexities_list.clear() ;
438 this->mean_gray_level = 0 ;
439 if (connexe(I, (
unsigned int)(u+k*pas),(
unsigned int)(v+l*pas),
440 gray_level_min, gray_level_max,
441 mean_gray_level, u_cog, v_cog, npoint) != vpDot::out)
443 sol = true ; u += k*pas ; v += l*pas ;
451 "Dot has been lost")) ;
456 if ( !connexe(I,(
unsigned int)u,(
unsigned int)v, mean_gray_level, u_cog, v_cog, npoint) )
460 unsigned int right = 1;
461 unsigned int botom = 1;
462 unsigned int left = 2;
464 double u_ = u, v_ = v;
469 for (k=1; k <= right; k++)
if(sol==
false) {
472 ip_connexities_list.clear() ;
473 ip_edges_list.clear();
475 this->mean_gray_level = 0 ;
476 if ( connexe(I, (
unsigned int)u_+k, (
unsigned int)(v_),mean_gray_level, u_cog, v_cog, npoint) ) {
477 sol =
true; u = u_+k; v = v_;
483 for (k=1; k <= botom; k++)
if (sol==
false) {
486 ip_connexities_list.clear() ;
487 ip_edges_list.clear();
489 this->mean_gray_level = 0 ;
491 if ( connexe(I, (
unsigned int)(u_), (
unsigned int)(v_+k),mean_gray_level, u_cog, v_cog, npoint) ) {
492 sol =
true; u = u_; v = v_+k;
498 for (k=1; k <= left; k++)
if (sol==
false) {
501 ip_connexities_list.clear() ;
502 ip_edges_list.clear();
504 this->mean_gray_level = 0 ;
506 if ( connexe(I, (
unsigned int)(u_-k), (
unsigned int)(v_),mean_gray_level,u_cog, v_cog, npoint) ) {
507 sol = true ; u = u_-k; v = v_;
513 for (k=1; k <= up; k++)
if(sol==
false) {
516 ip_connexities_list.clear() ;
517 ip_edges_list.clear();
519 this->mean_gray_level = 0 ;
521 if ( connexe(I, (
unsigned int)(u_), (
unsigned int)(v_-k),mean_gray_level,u_cog, v_cog, npoint) ) {
522 sol = true ; u = u_; v = v_-k;
532 "Dot has been lost")) ;
548 u_cog = u_cog/npoint ;
549 v_cog = v_cog/npoint ;
555 double Ip = pow((
double)this->mean_gray_level/255,1/gamma);
557 if(Ip - (1 - grayLevelPrecision)<0){
561 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
562 if (gray_level_min > 255)
563 gray_level_min = 255;
565 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
566 if (gray_level_max > 255)
567 gray_level_max = 255;
579 if (npoint > nbMaxPoint)
581 vpERROR_TRACE(
"Too many point %lf (%lf%%). Max allowed is %lf (%lf%%). This threshold can be modified using the setMaxDotSize() method.",
583 nbMaxPoint, maxDotSizePercentage) ;
605 if (percentage <= 0.0 || percentage > 1.0) {
607 vpTRACE(
"Max dot size percentage is requested to be set to %lf.",
608 "Value should be in ]0:1]. Value will be set to %lf.",
609 percentage, maxDotSizePercentage);
612 maxDotSizePercentage = percentage;
644 unsigned int i = (
unsigned int)cog.
get_i();
645 unsigned int j = (
unsigned int)cog.
get_j();
647 double Ip = pow((
double)I[i][j]/255, 1/gamma);
649 if(Ip - (1 - grayLevelPrecision)<0){
653 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
654 if (gray_level_min > 255)
655 gray_level_min = 255;
657 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
658 if (gray_level_max > 255)
659 gray_level_max = 255;
700 unsigned int i = (
unsigned int)cog.
get_i();
701 unsigned int j = (
unsigned int)cog.
get_j();
703 double Ip = pow((
double)I[i][j]/255, 1/gamma);
705 if(Ip - (1 - grayLevelPrecision)<0){
709 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
710 if (gray_level_min > 255)
711 gray_level_min = 255;
713 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
714 if (gray_level_max > 255)
715 gray_level_max = 255;
755 unsigned int gray_level_min,
unsigned int gray_level_max)
760 this->gray_level_min = gray_level_min;
761 this->gray_level_max = gray_level_max;
793 double u = this->cog.
get_u();
794 double v = this->cog.
get_v();
798 this->cog.
set_u( u );
799 this->cog.
set_v( v );
801 if (compute_moment==
true)
851 unsigned int thickness)
854 std::list<vpImagePoint>::const_iterator it;
856 for (it = ip_edges_list.begin(); it != ip_edges_list.end(); ++it)
881 double epsilon = 0.05;
882 if( grayLevelPrecision<epsilon )
884 this->grayLevelPrecision = epsilon;
886 else if( grayLevelPrecision>1 )
888 this->grayLevelPrecision = 1.0;
892 this->grayLevelPrecision = grayLevelPrecision;
911 const std::list<vpImagePoint> &edges_list,
vpColor color,
912 unsigned int thickness)
915 std::list<vpImagePoint>::const_iterator it;
917 for (it = edges_list.begin(); it != edges_list.end(); ++it)
938 const std::list<vpImagePoint> &edges_list,
vpColor color,
939 unsigned int thickness)
942 std::list<vpImagePoint>::const_iterator it;
944 for (it = edges_list.begin(); it != edges_list.end(); ++it)
bool operator!=(const vpDot &d)
void display(const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1)
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)
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)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
void set_v(const double v)
This tracker is meant to track a dot (connex 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.