50 #include <visp/vpMeTracker.h>
51 #include <visp/vpMe.h>
52 #include <visp/vpMeSite.h>
53 #include <visp/vpMeLine.h>
54 #include <visp/vpRobust.h>
55 #include <visp/vpTrackingException.h>
56 #include <visp/vpImagePoint.h>
57 #include <visp/vpMath.h>
64 normalizeAngle(
double &delta)
66 while (delta > M_PI) { delta -= M_PI ; }
67 while (delta < -M_PI) { delta += M_PI ; }
71 computeDelta(
double &delta,
int i1,
int j1,
int i2,
int j2)
74 double B = double(i1-i2) ;
75 double A = double(j1-j2) ;
79 normalizeAngle(delta) ;
84 project(
double a,
double b,
double c,
85 double i,
double j,
double &ip,
double &jp)
119 delta = meline.
delta;
157 if (std::fabs(
me->
getSampleStep()) <= std::numeric_limits<double>::epsilon())
161 "sample step = 0")) ;
169 if(std::fabs(length_p)<=std::numeric_limits<double>::epsilon())
174 double stepi = diffsi/(double)n_sample;
175 double stepj = diffsj/(double)n_sample;
194 pix.
init((
int)is, (
int)js, delta, 0,
sign) ;
211 vpCDEBUG(1) <<
"end vpMeLine::sample() : ";
212 vpCDEBUG(1) << n_sample <<
" point inserted in the list " << std::endl ;
247 std::cout <<
"Click on the line first point..." <<std::endl ;
249 std::cout <<
"Click on the line second point..." <<std::endl ;
291 unsigned int iter =0 ;
292 unsigned int nos_1 = 0 ;
293 double distance = 100;
300 "not enough point")) ;
309 for(std::list<vpMeSite>::const_iterator it=
list.begin(); it!=
list.end(); ++it){
320 while (iter < 4 && distance > 0.05)
331 for (i=0 ; i < nos_1 ; i++)
337 distance = fabs(x[0]-x_1[0])+fabs(x[1]-x_1[1]);
342 for(std::list<vpMeSite>::iterator it=
list.begin(); it!=
list.end(); ++it){
374 for(std::list<vpMeSite>::const_iterator it=
list.begin(); it!=
list.end(); ++it){
385 while (iter < 4 && distance > 0.05)
396 for (i=0 ; i < nos_1 ; i++)
402 distance = fabs(x[0]-x_1[0])+fabs(x[1]-x_1[1]);
408 for(std::list<vpMeSite>::iterator it=
list.begin(); it!=
list.end(); ++it){
434 normalizeAngle(delta) ;
453 vpCDEBUG(1) <<
" begin vpMeLine::initTracking()"<<std::endl ;
455 int i1s, j1s, i2s, j2s;
472 double angle = atan2((
double)(i1s-i2s),(
double)(j1s-j2s)) ;
479 computeDelta(delta,i1s,j1s,i2s,j2s) ;
499 vpCDEBUG(1) <<
" end vpMeLine::initTracking()"<<std::endl ;
510 for(std::list<vpMeSite>::iterator it=
list.begin(); it!=
list.end(); ){
534 for(std::list<vpMeSite>::const_iterator it=
list.begin(); it!=
list.end(); ++it){
554 if (fabs(imin-imax) < 25)
556 for(std::list<vpMeSite>::const_iterator it=
list.begin(); it!=
list.end(); ++it){
588 vpCDEBUG(1) <<
"begin vpMeLine::sample() : "<<std::endl ;
595 if (std::fabs(
me->
getSampleStep()) <= std::numeric_limits<double>::epsilon())
600 "sample step = 0")) ;
609 double di = diffsi/sqrt(s) ;
610 double dj = diffsj/sqrt(s) ;
627 for (
int i=0 ; i < 3 ; i++)
658 for (
int i=0 ; i < 3 ; i++)
688 vpCDEBUG(1) <<
"end vpMeLine::sample() : " ;
689 vpCDEBUG(1) << n_sample <<
" point inserted in the list " << std::endl ;
710 project(a,b,c,
PExt[0].ifloat,
PExt[0].jfloat,i1,j1) ;
711 project(a,b,c,
PExt[1].ifloat,
PExt[1].jfloat,i2,j2) ;
724 if ((
double)n<0.9*expecteddensity)
726 double delta_new =
delta;
746 double angle = delta + M_PI/2;
749 while (angle<0) angle += M_PI;
750 while (angle>M_PI) angle -= M_PI;
755 if(std::fabs(std::fabs(angle) - 180) <= std::numeric_limits<double>::epsilon())
767 for(std::list<vpMeSite>::iterator it=
list.begin(); it!=
list.end(); ++it){
786 vpCDEBUG(1) <<
"begin vpMeLine::track()"<<std::endl ;
854 vpCDEBUG(1) <<
"end vpMeLine::track()"<<std::endl ;
857 void vpMeLine::update_indices(
double theta,
int i,
int j,
int incr,
int& i1,
int& i2,
int& j1,
int& j2){
858 i1 = (int)(i + cos(theta) *incr) ;
859 j1 = (int)(j + sin(theta) *incr) ;
861 i2 = (int)(i - cos(theta) *incr) ;
862 j2 = (int)(j - sin(theta) *incr) ;
879 while (theta >= M_PI) theta -=M_PI ;
880 while (theta < 0) theta +=M_PI ;
911 int i1=0,i2=0,j1=0,j2=0 ;
912 unsigned char v1=0,v2=0 ;
916 update_indices(theta,i,j,incr,i1,i2,j1,j2);
918 if(i1<0 || i1>=height_ || i2<0 || i2>=height_ ||
919 j1<0 || j1>=width_ || j2<0 || j2>=width_){
920 double rho_lim1 = fabs((
double)i/cos(theta));
921 double rho_lim2 = fabs((
double)j/sin(theta));
923 double co_rho_lim1 = fabs(((
double)(height_-i))/cos(theta));
924 double co_rho_lim2 = fabs(((
double)(width_-j))/sin(theta));
926 double rho_lim = std::min(rho_lim1,rho_lim2);
927 double co_rho_lim = std::min(co_rho_lim1,co_rho_lim2);
928 incr = (int)std::floor(std::min(rho_lim,co_rho_lim));
932 "increment is too small")) ;
934 update_indices(theta,i,j,incr,i1,i2,j1,j2);
940 unsigned int i1_ =
static_cast<unsigned int>(i1);
941 unsigned int j1_ =
static_cast<unsigned int>(j1);
942 unsigned int i2_ =
static_cast<unsigned int>(i2);
943 unsigned int j2_ =
static_cast<unsigned int>(j2);
953 std::cout <<
"In CStraightLine::GetParameters() " ;
954 std::cout <<
" Error Tracking " << abs(v1-v2) << std::endl ;
957 update_indices(theta,i,j,incr,i1,i2,j1,j2);
960 if (theta >=0 && theta <= M_PI/2)
1069 double a1 = line1.
a;
1070 double b1 = line1.
b;
1071 double c1 = line1.
c;
1072 double a2 = line2.
a;
1073 double b2 = line2.
b;
1074 double c2 = line2.
c;
1081 denom = (-(a2/a1) * b1 + b2);
1084 if (std::fabs(denom) <= std::numeric_limits<double>::epsilon())
1086 std::cout <<
"!!!!!!!!!!!!! Problem : Lines are parallel !!!!!!!!!!!!!" << std::endl;
1091 if (std::fabs(denom) > std::numeric_limits<double>::epsilon())
1093 j = ( (a2/a1)*c1 - c2 ) / denom;
1094 i = (-b1*j - c1) / a1;
1100 denom = (-(b2/b1) * a1 + a2);
1103 if (std::fabs(denom) <= std::numeric_limits<double>::epsilon())
1105 std::cout <<
"!!!!!!!!!!!!! Problem : Lines are parallel !!!!!!!!!!!!!" << std::endl;
1110 if (std::fabs(denom) > std::numeric_limits<double>::epsilon())
1112 i = ( (b2/b1)*c1 - c2 ) / denom;
1113 j = (-a1*i - c1) / b1;
1147 const double &A,
const double &B,
const double &C,
1148 vpColor color,
unsigned int thickness)
1152 if (fabs(A) < fabs(B)) {
1153 double i1, j1, i2, j2;
1155 j1 = (-A*i1 -C) / B;
1157 j2 = (-A*i2 -C) / B;
1168 double i1, j1, i2, j2;
1170 i1 = -(B * j1 + C) / A;
1172 i2 = -(B * j2 + C) / A;
1213 const std::list<vpMeSite> &site_list,
1214 const double &A,
const double &B,
const double &C,
1215 vpColor color,
unsigned int thickness)
1219 for(std::list<vpMeSite>::const_iterator it=site_list.begin(); it!=site_list.end(); ++it){
1235 if (fabs(A) < fabs(B)) {
1236 double i1, j1, i2, j2;
1238 j1 = (-A*i1 -C) / B;
1240 j2 = (-A*i2 -C) / B;
1251 double i1, j1, i2, j2;
1253 i1 = -(B * j1 + C) / A;
1255 i2 = -(B * j2 + C) / A;
void reSample(const vpImage< unsigned char > &I)
void set_j(const double j)
unsigned int getRange() const
Definition of the vpMatrix class.
double c
Parameter c of the line equation a*i + b*j + c = 0.
virtual void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)=0
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Compute the weights according a residue vector and a PsiFunction.
unsigned int getWidth() const
unsigned int numberOfSignal()
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
Class to define colors available for display functionnalities.
int outOfImage(int i, int j, int half, int rows, int cols)
void set_i(const double i)
bool _useIntensityForRho
Flag to specify wether the intensity of the image at the middle point is used to compute the sign of ...
void track(const vpImage< unsigned char > &Im)
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static int round(const double x)
#define vpDEBUG_ENABLE(niv)
vpMeSiteState getState() const
void display(const vpImage< unsigned char > &I, vpColor col)
void computeRhoTheta(const vpImage< unsigned char > &I)
void setIdentity(const double &val=1.0)
std::list< vpMeSite > list
Error that can be emited by the vpTracker class and its derivates.
void getExtremities(vpImagePoint &ip1, vpImagePoint &ip2)
static double sqr(double x)
void sample(const vpImage< unsigned char > &image)
Class that tracks in an image a line moving edges.
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.
Contains abstract elements for a Distance to Feature type feature.
void initTracking(const vpImage< unsigned char > &I)
double a
Parameter a of the line equation a*i + b*j + c = 0.
void setState(const vpMeSiteState &flag)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
double b
Parameter b of the line equation a*i + b*j + c = 0.
void track(const vpImage< unsigned char > &im, const vpMe *me, const bool test_contraste=true)
vpMe * me
Moving edges initialisation parameters.
Contains an M-Estimator and various influence function.
void initTracking(const vpImage< unsigned char > &I)
static bool intersection(const vpMeLine &line1, const vpMeLine &line2, vpImagePoint &ip)
unsigned int getHeight() const
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
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 ...
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
void setRange(const unsigned int &r)
void setThreshold(const double noise_threshold)
double getSampleStep() const
vpMeSite::vpMeSiteDisplayType selectDisplay
void setIteration(const unsigned int iter)
Set iteration.
void seekExtremities(const vpImage< unsigned char > &I)
virtual void display(const vpImage< unsigned char > &I, vpColor col)=0
static const vpColor blue