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() ;
138 ip_edges_list = d.ip_edges_list;
139 ip_connexities_list = d.ip_connexities_list;
140 connexityType = d.connexityType;
148 graphics = d.graphics ;
149 thickness = d.thickness;
150 maxDotSizePercentage = d.maxDotSizePercentage;
151 gray_level_out = d.gray_level_out;
152 mean_gray_level = d.mean_gray_level ;
153 gray_level_min = d.gray_level_min ;
154 gray_level_max = d.gray_level_max ;
155 grayLevelPrecision = d.grayLevelPrecision;
157 compute_moment = d.compute_moment ;
158 nbMaxPoint = d.nbMaxPoint;
177 return ( cog != d.
getCog() );
183 return ( cog == d.
getCog() );
198 vpDot::setGrayLevelOut()
200 if (gray_level_min == 0) {
201 if (gray_level_max == 255) {
205 "Unable to choose a good \"out\" level")) ;
207 gray_level_out =
static_cast<unsigned char>(gray_level_max + 1u);
229 double &mean_value,
double &u_cog,
double &v_cog,
double &n)
232 return connexe(I,u,v,mean_value,u_cog,v_cog,n,checkTab);
252 double &mean_value,
double &u_cog,
double &v_cog,
double &n,std::vector<bool> &checkTab)
259 if ( (u >= width) || (v >= height) )
272 if (I[v][u] >= gray_level_min && I[v][u] <= gray_level_max)
274 checkTab[v*I.
getWidth() + u] =
true;
276 ip_connexities_list.push_back(ip);
282 if (n > nbMaxPoint) {
284 "This threshold can be modified using the setMaxDotSize() "
287 nbMaxPoint, maxDotSizePercentage) ;
294 if (u < this->u_min) this->u_min = u;
295 if (u > this->u_max) this->u_max = u;
296 if (v < this->v_min) this->v_min = v;
297 if (v > this->v_max) this->v_max = v;
300 mean_value = (mean_value *(n-1) + I[v][u]) / n;
301 if (compute_moment==
true)
322 if(!connexe(I,u-1,v, mean_value,u_cog,v_cog, n, checkTab))
327 if(!connexe(I,u+1,v,mean_value,u_cog, v_cog, n, checkTab))
332 if(!connexe(I,u, v-1,mean_value,u_cog, v_cog, n, checkTab))
337 if(!connexe(I,u,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))
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))
363 ip_edges_list.push_back(ip);
367 for(
unsigned int t=0; t<thickness; t++) {
368 ip_.set_u(ip.
get_u() + t);
412 this->mean_gray_level = 0 ;
414 ip_connexities_list.clear() ;
415 ip_edges_list.clear();
425 if ( connexe(I, (
unsigned int)u, (
unsigned int)v,
426 gray_level_min, gray_level_max,
427 mean_gray_level, u_cog, v_cog, npoint) == vpDot::out)
431 for (pas = 2 ; pas <= 25 ; pas ++ )
if (sol==
false)
433 for (
int k=-1 ; k <=1 ; k++)
if (sol==
false)
434 for (
int l=-1 ; l <=1 ; l++)
if (sol==
false)
438 ip_connexities_list.clear() ;
440 this->mean_gray_level = 0 ;
441 if (connexe(I, (
unsigned int)(u+k*pas),(
unsigned int)(v+l*pas),
442 gray_level_min, gray_level_max,
443 mean_gray_level, u_cog, v_cog, npoint) != vpDot::out)
445 sol = true ; u += k*pas ; v += l*pas ;
453 "Dot has been lost")) ;
458 if ( !connexe(I,(
unsigned int)u,(
unsigned int)v, mean_gray_level, u_cog, v_cog, npoint) )
462 unsigned int right = 1;
463 unsigned int botom = 1;
464 unsigned int left = 2;
466 double u_ = u, v_ = v;
471 for (k=1; k <= right; k++)
if(sol==
false) {
474 ip_connexities_list.clear() ;
475 ip_edges_list.clear();
477 this->mean_gray_level = 0 ;
478 if ( connexe(I, (
unsigned int)u_+k, (
unsigned int)(v_),mean_gray_level, u_cog, v_cog, npoint) ) {
479 sol =
true; u = u_+k; v = v_;
485 for (k=1; k <= botom; k++)
if (sol==
false) {
488 ip_connexities_list.clear() ;
489 ip_edges_list.clear();
491 this->mean_gray_level = 0 ;
493 if ( connexe(I, (
unsigned int)(u_), (
unsigned int)(v_+k),mean_gray_level, u_cog, v_cog, npoint) ) {
494 sol =
true; u = u_; v = v_+k;
500 for (k=1; k <= left; k++)
if (sol==
false) {
503 ip_connexities_list.clear() ;
504 ip_edges_list.clear();
506 this->mean_gray_level = 0 ;
508 if ( connexe(I, (
unsigned int)(u_-k), (
unsigned int)(v_),mean_gray_level,u_cog, v_cog, npoint) ) {
509 sol = true ; u = u_-k; v = v_;
515 for (k=1; k <= up; k++)
if(sol==
false) {
518 ip_connexities_list.clear() ;
519 ip_edges_list.clear();
521 this->mean_gray_level = 0 ;
523 if ( connexe(I, (
unsigned int)(u_), (
unsigned int)(v_-k),mean_gray_level,u_cog, v_cog, npoint) ) {
524 sol = true ; u = u_; v = v_-k;
534 "Dot has been lost")) ;
550 u_cog = u_cog/npoint ;
551 v_cog = v_cog/npoint ;
557 double Ip = pow((
double)this->mean_gray_level/255,1/gamma);
559 if(Ip - (1 - grayLevelPrecision)<0){
563 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
564 if (gray_level_min > 255)
565 gray_level_min = 255;
567 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
568 if (gray_level_max > 255)
569 gray_level_max = 255;
581 if (npoint > nbMaxPoint)
583 vpERROR_TRACE(
"Too many point %lf (%lf%%). Max allowed is %lf (%lf%%). This threshold can be modified using the setMaxDotSize() method.",
585 nbMaxPoint, maxDotSizePercentage) ;
607 if (percentage <= 0.0 || percentage > 1.0) {
609 vpTRACE(
"Max dot size percentage is requested to be set to %lf.",
610 "Value should be in ]0:1]. Value will be set to %lf.",
611 percentage, maxDotSizePercentage);
614 maxDotSizePercentage = percentage;
646 unsigned int i = (
unsigned int)cog.
get_i();
647 unsigned int j = (
unsigned int)cog.
get_j();
649 double Ip = pow((
double)I[i][j]/255, 1/gamma);
651 if(Ip - (1 - grayLevelPrecision)<0){
655 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
656 if (gray_level_min > 255)
657 gray_level_min = 255;
659 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
660 if (gray_level_max > 255)
661 gray_level_max = 255;
702 unsigned int i = (
unsigned int)cog.
get_i();
703 unsigned int j = (
unsigned int)cog.
get_j();
705 double Ip = pow((
double)I[i][j]/255, 1/gamma);
707 if(Ip - (1 - grayLevelPrecision)<0){
711 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
712 if (gray_level_min > 255)
713 gray_level_min = 255;
715 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
716 if (gray_level_max > 255)
717 gray_level_max = 255;
757 unsigned int gray_level_min,
unsigned int gray_level_max)
762 this->gray_level_min = gray_level_min;
763 this->gray_level_max = gray_level_max;
795 double u = this->cog.
get_u();
796 double v = this->cog.
get_v();
800 this->cog.
set_u( u );
801 this->cog.
set_v( v );
803 if (compute_moment==
true)
853 unsigned int thickness)
856 std::list<vpImagePoint>::const_iterator it;
858 for (it = ip_edges_list.begin(); it != ip_edges_list.end(); ++it)
883 double epsilon = 0.05;
884 if( grayLevelPrecision<epsilon )
886 this->grayLevelPrecision = epsilon;
888 else if( grayLevelPrecision>1 )
890 this->grayLevelPrecision = 1.0;
894 this->grayLevelPrecision = grayLevelPrecision;
913 const std::list<vpImagePoint> &edges_list,
vpColor color,
914 unsigned int thickness)
917 std::list<vpImagePoint>::const_iterator it;
919 for (it = edges_list.begin(); it != edges_list.end(); ++it)
940 const std::list<vpImagePoint> &edges_list,
vpColor color,
941 unsigned int thickness)
944 std::list<vpImagePoint>::const_iterator it;
946 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 (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.