43 #include <visp/vpConfig.h>
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
53 #include <visp/vpMbtMeLine.h>
54 #include <visp/vpTrackingException.h>
55 #include <visp/vpRobust.h>
59 normalizeAngle(
double &delta)
61 while (delta > M_PI) { delta -= M_PI ; }
62 while (delta < -M_PI) { delta += M_PI ; }
69 vpMbtMeLine::vpMbtMeLine()
70 : rho(0.), theta(0.), theta_1(M_PI/2), delta(0.), delta_1(0), sign(1),
71 a(0.), b(0.), c(0.), imin(0), imax(0), jmin(0), jmax(0),
79 vpMbtMeLine::~vpMbtMeLine()
98 double rho_,
double theta_)
100 vpCDEBUG(1) <<
" begin vpMeLine::initTracking()"<<std::endl ;
106 PExt[0].ifloat = (float)ip1.
get_i() ;
107 PExt[0].jfloat = (float)ip1.
get_j() ;
108 PExt[1].ifloat = (float)ip2.
get_i() ;
109 PExt[1].jfloat = (float)ip2.
get_j() ;
112 this->theta = theta_;
119 delta = - theta + M_PI/2.0;
120 normalizeAngle(delta);
124 expecteddensity = (double)list.size();
132 vpCDEBUG(1) <<
" end vpMeLine::initTracking()"<<std::endl ;
150 if (std::fabs(me->getSampleStep()) <= std::numeric_limits<double>::epsilon())
153 "Function vpMbtMeLine::sample() called with moving-edges sample step = 0")) ;
157 double diffsi = PExt[0].ifloat-PExt[1].ifloat;
158 double diffsj = PExt[0].jfloat-PExt[1].jfloat;
163 n_sample = length_p/(double)me->getSampleStep();
165 double stepi = diffsi/(double)n_sample;
166 double stepj = diffsj/(double)n_sample;
169 double is = PExt[1].ifloat;
170 double js = PExt[1].jfloat;
185 pix.
init((
int)is, (
int)js, delta, 0, sign) ;
187 pix.
track(I, me,
false);
205 vpCDEBUG(1) <<
"end vpMeLine::sample() : ";
206 vpCDEBUG(1) << list.size() <<
" point inserted in the list " << std::endl ;
218 for(std::list<vpMeSite>::iterator it=list.begin(); it!=list.end(); ){
221 if (fabs(sin(theta)) > 0.9)
223 if ((s.
i < imin) ||(s.
i > imax))
229 else if (fabs(cos(theta)) > 0.9)
231 if ((s.
j < jmin) || (s.
j > jmax))
239 if ((s.
i < imin) ||(s.
i > imax) || (s.
j < jmin) || (s.
j > jmax) )
246 if (outOfImage(s.
i, s.
j, (
int)(me->getRange()+me->getMaskSize()+1), (
int)I.
getHeight(), (int)I.
getWidth()))
267 vpCDEBUG(1) <<
"begin vpMeLine::sample() : "<<std::endl ;
274 if (std::fabs(me->getSampleStep()) <= std::numeric_limits<double>::epsilon())
277 "Function called with sample step = 0")) ;
281 double diffsi = PExt[0].ifloat-PExt[1].ifloat;
282 double diffsj = PExt[0].jfloat-PExt[1].jfloat;
286 double di = diffsi/sqrt(s) ;
287 double dj = diffsj/sqrt(s) ;
289 double length_p = sqrt(s);
292 n_sample = length_p/(double)me->getSampleStep();
293 double sample_step = (double)me->getSampleStep();
296 P.
init((
int) PExt[0].ifloat, (
int)PExt[0].jfloat, delta_1, 0, sign) ;
299 unsigned int memory_range = me->getRange() ;
302 for (
int i=0 ; i < 3 ; i++)
307 if ((P.
i < imin) ||(P.
i > imax) || (P.
j < jmin) || (P.
j > jmax) )
312 if(!outOfImage(P.
i, P.
j, (
int)(me->getRange()+me->getMaskSize()+1), (
int)rows, (int)cols))
314 P.
track(I,me,
false) ;
326 P.
init((
int) PExt[1].ifloat, (
int)PExt[1].jfloat, delta_1, 0, sign) ;
328 for (
int i=0 ; i < 3 ; i++)
333 if ((P.
i < imin) ||(P.
i > imax) || (P.
j < jmin) || (P.
j > jmax) )
339 if(!outOfImage(P.
i, P.
j, (
int)(me->getRange()+me->getMaskSize()+1), (
int)rows, (int)cols))
341 P.
track(I,me,
false) ;
353 me->setRange(memory_range);
355 vpCDEBUG(1) <<
"end vpMeLine::sample() : " ;
356 vpCDEBUG(1) << n_sample <<
" point inserted in the list " << std::endl ;
372 unsigned int n = numberOfSignal() ;
374 if ((
double)n<0.5*expecteddensity && n > 0)
376 double delta_new = delta;
379 expecteddensity = (double)list.size();
404 size_t n = list.size();
406 if ((
double)n<0.5*expecteddensity /*&& n > 0*/)
408 double delta_new = delta;
410 PExt[0].ifloat = (float)ip1.
get_i() ;
411 PExt[0].jfloat = (float)ip1.
get_j() ;
412 PExt[1].ifloat = (float)ip2.
get_i() ;
413 PExt[1].jfloat = (float)ip2.
get_j() ;
415 expecteddensity = (double)list.size();
425 vpMbtMeLine::updateDelta()
432 if(std::fabs(std::fabs(theta) - M_PI) <=
vpMath::maximum(std::fabs(theta), (
double)M_PI)*std::numeric_limits<double>::epsilon() )
437 diff = fabs(theta - theta_1);
443 delta = - theta + M_PI/2.0;
444 normalizeAngle(delta);
446 for(std::list<vpMeSite>::iterator it=list.begin(); it!=list.end(); ++it){
490 this->theta = theta_;
519 double rho_,
double theta_)
522 this->theta = theta_;
544 vpMbtMeLine::setExtremities()
546 double i_min = +1e6 ;
552 for(std::list<vpMeSite>::const_iterator it=list.begin(); it!=list.end(); ++it){
567 if ( ! list.empty() )
569 PExt[0].ifloat = i_min ;
570 PExt[0].jfloat = j_min ;
571 PExt[1].ifloat = i_max ;
572 PExt[1].jfloat = j_max ;
575 if (fabs(i_min-i_max) < 25)
577 for(std::list<vpMeSite>::const_iterator it=list.begin(); it!=list.end(); ++it){
594 PExt[0].ifloat = i_min ;
595 PExt[0].jfloat = j_min ;
596 PExt[1].ifloat = i_max ;
597 PExt[1].jfloat = j_max ;
612 vpMbtMeLine::bubbleSortI()
615 unsigned int nbElmt = list.size();
616 for (
unsigned int pass = 1; pass < nbElmt; pass++)
619 for (
unsigned int i=0; i < nbElmt-pass; i++)
639 vpMbtMeLine::bubbleSortJ()
642 unsigned int nbElmt = list.size();
643 for(
unsigned int pass=1; pass < nbElmt; pass++)
646 for (
unsigned int i=0; i < nbElmt-pass; i++)
664 vpImagePoint itest(PExt[0].ifloat+(PExt[1].ifloat-PExt[0].ifloat)/2, PExt[0].jfloat+(PExt[1].jfloat-PExt[0].jfloat)/2);
667 pix.
init(itest.get_i(), itest.get_j(), delta, 0, sign);
671 unsigned int range = p_me->
getRange();
679 for(
unsigned int n = 0 ; n < 2 * range + 1 ; n++)
681 conv[n] = list_query_pixels[n].
convolution(I, p_me);
683 delete [] list_query_pixels;
unsigned int getRange() const
unsigned int getWidth() const
double convolution(const vpImage< unsigned char > &ima, const vpMe *me)
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
error that can be emited by ViSP classes.
Contains predetermined masks for sites and holds moving edges tracking parameters.
#define vpDEBUG_ENABLE(level)
static const vpColor green
static int round(const double x)
vpMeSiteState getState() const
static Type maximum(const Type &a, const Type &b)
static const vpColor orange
void set_i(const double ii)
Error that can be emited by the vpTracker class and its derivates.
static const vpColor cyan
static double sqr(double x)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
void setDisplay(vpMeSiteDisplayType select)
void track(const vpImage< unsigned char > &I)
Track sampled pixels.
vpMeSite * getQueryList(const vpImage< unsigned char > &I, const int range)
void setState(const vpMeSiteState &flag)
void set_j(const double jj)
void track(const vpImage< unsigned char > &im, const vpMe *me, const bool test_contraste=true)
void initTracking(const vpImage< unsigned char > &I)
unsigned int getHeight() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
static const vpColor blue