49 #include <visp/vpDot.h>
50 #include <visp/vpDisplay.h>
51 #include <visp/vpColor.h>
52 #include <visp/vpTrackingException.h>
75 compute_moment = false ;
78 maxDotSizePercentage = 0.25 ;
83 grayLevelPrecision = 0.85;
90 u_min = u_max = v_min = v_max = 0;
97 : m00(0.), m01(0.), m10(0.), m11(0.), m20(0.), m02(0.),
98 mu11(0.), mu20(0.), mu02(0.), ip_connexities_list(), ip_edges_list(), connexityType(CONNEXITY_4),
99 cog(), u_min(0), u_max(0), v_min(0), v_max(0), graphics(false), thickness(1), maxDotSizePercentage(0.25),
100 gray_level_out(0), mean_gray_level(0), gray_level_min(128), gray_level_max(255), grayLevelPrecision(0.85),
101 gamma(1.5), compute_moment(false), nbMaxPoint(0)
111 : m00(0.), m01(0.), m10(0.), m11(0.), m20(0.), m02(0.),
112 mu11(0.), mu20(0.), mu02(0.), ip_connexities_list(), ip_edges_list(), connexityType(CONNEXITY_4),
113 cog(), u_min(0), u_max(0), v_min(0), v_max(0), graphics(false), thickness(1), maxDotSizePercentage(0.25),
114 gray_level_out(0), mean_gray_level(0), gray_level_min(128), gray_level_max(255), grayLevelPrecision(0.85),
115 gamma(1.5), compute_moment(false), nbMaxPoint(0)
125 m00(0.), m01(0.), m10(0.), m11(0.), m20(0.), m02(0.),
126 mu11(0.), mu20(0.), mu02(0.), ip_connexities_list(), ip_edges_list(), connexityType(CONNEXITY_4),
127 cog(), u_min(0), u_max(0), v_min(0), v_max(0), graphics(false), thickness(1), maxDotSizePercentage(0.25),
128 gray_level_out(0), mean_gray_level(0), gray_level_min(128), gray_level_max(255), grayLevelPrecision(0.85),
129 gamma(1.5), compute_moment(false), nbMaxPoint(0)
139 ip_connexities_list.clear() ;
148 ip_edges_list = d.ip_edges_list;
149 ip_connexities_list = d.ip_connexities_list;
150 connexityType = d.connexityType;
158 graphics = d.graphics ;
159 thickness = d.thickness;
160 maxDotSizePercentage = d.maxDotSizePercentage;
161 gray_level_out = d.gray_level_out;
162 mean_gray_level = d.mean_gray_level ;
163 gray_level_min = d.gray_level_min ;
164 gray_level_max = d.gray_level_max ;
165 grayLevelPrecision = d.grayLevelPrecision;
167 compute_moment = d.compute_moment ;
168 nbMaxPoint = d.nbMaxPoint;
187 return ( cog != d.
getCog() );
193 return ( cog == d.
getCog() );
208 vpDot::setGrayLevelOut()
210 if (gray_level_min == 0) {
211 if (gray_level_max == 255) {
215 "Unable to choose a good \"out\" level")) ;
217 gray_level_out =
static_cast<unsigned char>(gray_level_max + 1u);
239 double &mean_value,
double &u_cog,
double &v_cog,
double &n)
242 return connexe(I,u,v,mean_value,u_cog,v_cog,n,checkTab);
262 double &mean_value,
double &u_cog,
double &v_cog,
double &n,std::vector<bool> &checkTab)
269 if ( (u >= width) || (v >= height) )
282 if (I[v][u] >= gray_level_min && I[v][u] <= gray_level_max)
284 checkTab[v*I.
getWidth() + u] =
true;
286 ip_connexities_list.push_back(ip);
292 if (n > nbMaxPoint) {
300 "Too many point %lf (%lf%% of image size). "
301 "This threshold can be modified using the setMaxDotSize() "
304 nbMaxPoint, maxDotSizePercentage)) ;
308 if (u < this->u_min) this->u_min = u;
309 if (u > this->u_max) this->u_max = u;
310 if (v < this->v_min) this->v_min = v;
311 if (v > this->v_max) this->v_max = v;
314 mean_value = (mean_value *(n-1) + I[v][u]) / n;
315 if (compute_moment==
true)
336 if(!connexe(I,u-1,v, mean_value,u_cog,v_cog, n, checkTab))
341 if(!connexe(I,u+1,v,mean_value,u_cog, v_cog, n, checkTab))
346 if(!connexe(I,u, v-1,mean_value,u_cog, v_cog, n, checkTab))
351 if(!connexe(I,u,v+1,mean_value,u_cog, v_cog, n, checkTab))
356 if(!checkTab[u-1+(v-1)*I.
getWidth()])
357 if(!connexe(I,u-1,v-1,mean_value,u_cog, v_cog, n, checkTab))
361 if(!checkTab[u+1+(v-1)*I.
getWidth()])
362 if(!connexe(I,u+1,v-1,mean_value,u_cog, v_cog, n, checkTab))
366 if(!checkTab[u-1+(v+1)*I.
getWidth()])
367 if(!connexe(I,u-1,v+1,mean_value, u_cog, v_cog, n, checkTab))
371 if(!checkTab[u+1+(v+1)*I.
getWidth()])
372 if(!connexe(I,u+1,v+1,mean_value,u_cog, v_cog, n, checkTab))
377 ip_edges_list.push_back(ip);
381 for(
unsigned int t=0; t<thickness; t++) {
382 ip_.set_u(ip.
get_u() + t);
426 this->mean_gray_level = 0 ;
428 ip_connexities_list.clear() ;
429 ip_edges_list.clear();
439 if ( connexe(I, (
unsigned int)u, (
unsigned int)v,
440 gray_level_min, gray_level_max,
441 mean_gray_level, u_cog, v_cog, npoint) == vpDot::out)
445 for (pas = 2 ; pas <= 25 ; pas ++ )
if (sol==
false)
447 for (
int k=-1 ; k <=1 ; k++)
if (sol==
false)
448 for (
int l=-1 ; l <=1 ; l++)
if (sol==
false)
452 ip_connexities_list.clear() ;
454 this->mean_gray_level = 0 ;
455 if (connexe(I, (
unsigned int)(u+k*pas),(
unsigned int)(v+l*pas),
456 gray_level_min, gray_level_max,
457 mean_gray_level, u_cog, v_cog, npoint) != vpDot::out)
459 sol = true ; u += k*pas ; v += l*pas ;
467 "Dot has been lost")) ;
472 if ( !connexe(I,(
unsigned int)u,(
unsigned int)v, mean_gray_level, u_cog, v_cog, npoint) )
476 unsigned int right = 1;
477 unsigned int botom = 1;
478 unsigned int left = 2;
480 double u_ = u, v_ = v;
485 for (k=1; k <= right; k++)
if(sol==
false) {
488 ip_connexities_list.clear() ;
489 ip_edges_list.clear();
491 this->mean_gray_level = 0 ;
492 if ( connexe(I, (
unsigned int)u_+k, (
unsigned int)(v_),mean_gray_level, u_cog, v_cog, npoint) ) {
493 sol =
true; u = u_+k; v = v_;
499 for (k=1; k <= botom; k++)
if (sol==
false) {
502 ip_connexities_list.clear() ;
503 ip_edges_list.clear();
505 this->mean_gray_level = 0 ;
507 if ( connexe(I, (
unsigned int)(u_), (
unsigned int)(v_+k),mean_gray_level, u_cog, v_cog, npoint) ) {
508 sol =
true; u = u_; v = v_+k;
514 for (k=1; k <= left; k++)
if (sol==
false) {
517 ip_connexities_list.clear() ;
518 ip_edges_list.clear();
520 this->mean_gray_level = 0 ;
522 if ( connexe(I, (
unsigned int)(u_-k), (
unsigned int)(v_),mean_gray_level,u_cog, v_cog, npoint) ) {
523 sol = true ; u = u_-k; v = v_;
529 for (k=1; k <= up; k++)
if(sol==
false) {
532 ip_connexities_list.clear() ;
533 ip_edges_list.clear();
535 this->mean_gray_level = 0 ;
537 if ( connexe(I, (
unsigned int)(u_), (
unsigned int)(v_-k),mean_gray_level,u_cog, v_cog, npoint) ) {
538 sol = true ; u = u_; v = v_-k;
548 "Dot has been lost")) ;
564 u_cog = u_cog/npoint ;
565 v_cog = v_cog/npoint ;
571 double Ip = pow((
double)this->mean_gray_level/255,1/gamma);
573 if(Ip - (1 - grayLevelPrecision)<0){
577 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
578 if (gray_level_min > 255)
579 gray_level_min = 255;
581 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
582 if (gray_level_max > 255)
583 gray_level_max = 255;
595 if (npoint > nbMaxPoint)
602 "Too many point %lf (%lf%%). Max allowed is %lf (%lf%%). This threshold can be modified using the setMaxDotSize() method.",
604 nbMaxPoint, maxDotSizePercentage)) ;
623 if (percentage <= 0.0 || percentage > 1.0) {
625 vpTRACE(
"Max dot size percentage is requested to be set to %lf.",
626 "Value should be in ]0:1]. Value will be set to %lf.",
627 percentage, maxDotSizePercentage);
630 maxDotSizePercentage = percentage;
662 unsigned int i = (
unsigned int)cog.
get_i();
663 unsigned int j = (
unsigned int)cog.
get_j();
665 double Ip = pow((
double)I[i][j]/255, 1/gamma);
667 if(Ip - (1 - grayLevelPrecision)<0){
671 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
672 if (gray_level_min > 255)
673 gray_level_min = 255;
675 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
676 if (gray_level_max > 255)
677 gray_level_max = 255;
717 unsigned int i = (
unsigned int)cog.
get_i();
718 unsigned int j = (
unsigned int)cog.
get_j();
720 double Ip = pow((
double)I[i][j]/255, 1/gamma);
722 if(Ip - (1 - grayLevelPrecision)<0){
726 gray_level_min = (
unsigned int) (255*pow(Ip - (1 - grayLevelPrecision),gamma));
727 if (gray_level_min > 255)
728 gray_level_min = 255;
730 gray_level_max = (
unsigned int) (255*pow(Ip + (1 - grayLevelPrecision),gamma));
731 if (gray_level_max > 255)
732 gray_level_max = 255;
771 unsigned int level_min,
unsigned int level_max)
776 this->gray_level_min = level_min;
777 this->gray_level_max = level_max;
808 double u = this->cog.
get_u();
809 double v = this->cog.
get_v();
813 this->cog.
set_u( u );
814 this->cog.
set_v( v );
816 if (compute_moment==
true)
867 std::list<vpImagePoint>::const_iterator it;
869 for (it = ip_edges_list.begin(); it != ip_edges_list.end(); ++it)
894 double epsilon = 0.05;
895 if( grayLevelPrecision<epsilon )
897 this->grayLevelPrecision = epsilon;
899 else if( grayLevelPrecision>1 )
901 this->grayLevelPrecision = 1.0;
905 this->grayLevelPrecision = precision;
924 const std::list<vpImagePoint> &edges_list,
vpColor color,
925 unsigned int thickness)
928 std::list<vpImagePoint>::const_iterator it;
930 for (it = edges_list.begin(); it != edges_list.end(); ++it)
951 const std::list<vpImagePoint> &edges_list,
vpColor color,
952 unsigned int thickness)
955 std::list<vpImagePoint>::const_iterator it;
957 for (it = edges_list.begin(); it != edges_list.end(); ++it)
968 VISP_EXPORT std::ostream& operator<< (std::ostream& os,
vpDot& d) {
969 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)
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.