44 #include <visp/vpMeEllipse.h>
46 #include <visp/vpMe.h>
47 #include <visp/vpRobust.h>
48 #include <visp/vpTrackingException.h>
49 #include <visp/vpDebug.h>
50 #include <visp/vpImagePoint.h>
67 double i = iP.
get_i();
68 double j = iP.
get_j();
70 double A = 2*i+2*K[1]*j + 2*K[2] ;
71 double B = 2*K[0]*j + 2*K[1]*i + 2*K[3];
75 while (theta > M_PI) { theta -= M_PI ; }
76 while (theta < 0) { theta += M_PI ; }
84 : K(), iPc(), a(0.), b(0.), e(0.), iP1(), iP2(), alpha1(0), alpha2(2*M_PI),
85 ce(0.), se(0.), angle(), m00(0.), mu11(0.), mu20(0.), mu02(0.),
86 m10(0.), m01(0.), m11(0.), m02(0.), m20(0.),
87 thresholdWeight(0.2), expecteddensity(0.), circle(false)
89 vpCDEBUG(1) <<
"begin vpMeEllipse::vpMeEllipse() " << std::endl ;
102 vpCDEBUG(1) <<
"end vpMeEllipse::vpMeEllipse() " << std::endl ;
109 :
vpMeTracker(meellipse), K(), iPc(), a(0.), b(0.), e(0.), iP1(), iP2(), alpha1(0), alpha2(2*M_PI),
110 ce(0.), se(0.), angle(), m00(0.), mu11(0.), mu20(0.), mu02(0.),
111 m10(0.), m01(0.), m11(0.), m02(0.), m20(0.),
112 thresholdWeight(0.2), expecteddensity(0.), circle(false)
140 circle = meellipse.circle;
149 vpCDEBUG(1) <<
"begin vpMeEllipse::~vpMeEllipse() " << std::endl ;
154 vpCDEBUG(1) <<
"end vpMeEllipse::~vpMeEllipse() " << std::endl ;
171 vpCDEBUG(1) <<
"begin vpMeEllipse::sample() : "<<std::endl ;
174 vpDERROR_TRACE(2,
"Tracking error: Moving edges not initialized");
176 "Moving edges not initialized")) ;
185 if (std::fabs(
me->
getSampleStep()) <= std::numeric_limits<double>::epsilon())
187 std::cout <<
"In vpMeEllipse::sample: " ;
188 std::cout <<
"function called with sample step = 0" ;
227 computeTheta(theta, K, iP11) ;
249 n_sample = (
unsigned int)
list.size() ;
251 vpCDEBUG(1) <<
"end vpMeEllipse::sample() : " ;
252 vpCDEBUG(1) << n_sample <<
" point inserted in the list " << std::endl ;
274 vpDERROR_TRACE(2,
"Tracking error: Moving edges not initialized");
276 "Moving edges not initialized")) ;
294 vpMeEllipse::getParameters()
298 for (
unsigned int i=0 ; i < 5 ; i++)
302 double d = k[2]*k[2] - k[0]*k[1];
304 iPc.
set_i( (k[1] * k[3] - k[2] * k[4]) / d );
305 iPc.
set_j( (k[0] * k[4] - k[2] * k[3]) / d );
314 e = (k[1] - k[0] + sq) / (2.0*k[2]);
320 if(
e < 0.0)
e += M_PI ;
326 double a2 = num / (k[0] + k[1] + sq ) ;
327 double b2 = num / (k[0] + k[1] - sq ) ;
340 std::cout <<
"K" << std::endl ;
342 std::cout <<
iPc << std::endl ;
358 double j1, i1, j11, i11;
361 int number_of_points = 2000 ;
362 double incr = 2 * M_PI / number_of_points ;
404 else if (std::fabs(
alpha2 -
alpha1) < std::fabs(
alpha1) * std::numeric_limits<double>::epsilon())
419 vpMeEllipse::updateTheta()
423 for(std::list<vpMeSite>::iterator it=
list.begin(); it!=
list.end(); ++it){
428 computeTheta(theta, K, iP) ;
438 vpMeEllipse::suppressPoints()
441 std::list<vpMeSite>::iterator itList =
list.begin();
442 for(std::list<double>::iterator it=
angle.begin(); it!=
angle.end(); ){
446 itList =
list.erase(itList) ;
447 it =
angle.erase(it);
471 vpDERROR_TRACE(2,
"Tracking error: Moving edges not initialized");
473 "Moving edges not initialized")) ;
498 for (
unsigned int i=0 ; i < 3 ; i++)
535 for (
unsigned int i=0 ; i < 3 ; i++)
583 vpMeEllipse::setExtremities()
585 double alphamin = +1e6;
586 double alphamax = -1e6;
593 std::list<double>::const_iterator itAngle =
angle.begin();
595 for(std::list<vpMeSite>::const_iterator itList=
list.begin(); itList!=
list.end(); ++itList){
597 double alpha = *itAngle;
598 if (alpha < alphamin)
605 if (alpha > alphamax)
627 vpMeEllipse::leastSquare()
636 unsigned int iter =0 ;
653 "not enough point")) ;
662 for(std::list<vpMeSite>::const_iterator it=
list.begin(); it!=
list.end(); ++it){
668 A[k][2] = 2 * p_me.
ifloat ;
669 A[k][3] = 2 * p_me.
jfloat ;
686 r.setIteration(iter) ;
690 for (i=0 ; i < nos_1 ; i++)
699 for(std::list<vpMeSite>::iterator it=
list.begin(); it!=
list.end(); ++it){
712 for(i = 0; i < 5; i ++)
722 for(std::list<vpMeSite>::const_iterator it=
list.begin(); it!=
list.end(); ++it){
726 A[k][0] = 2* p_me.
ifloat ;
727 A[k][1] = 2 * p_me.
jfloat ;
744 r.setIteration(iter) ;
748 for (i=0 ; i < nos_1 ; i++)
757 for(std::list<vpMeSite>::iterator it=
list.begin(); it!=
list.end(); ++it){
770 for(i = 0; i < 3; i ++)
802 vpCDEBUG(1) <<
" begin vpMeEllipse::initTracking()"<<std::endl ;
804 const unsigned int n=5 ;
807 for (
unsigned int k =0 ; k < n ; k++)
809 std::cout <<
"Click points "<< k+1 <<
"/" << n ;
810 std::cout <<
" on the ellipse in the trigonometric order" <<std::endl ;
814 std::cout << iP[k] << std::endl;
838 vpCDEBUG(1) <<
" begin vpMeEllipse::initTracking()"<<std::endl ;
850 for (
unsigned int k =0 ; k < n ; k++)
854 A[k][2] = 2* iP[k].
get_i() ;
855 A[k][3] = 2* iP[k].
get_j() ;
862 std::cout << K << std::endl;
871 for (
unsigned int k =0 ; k < n ; k++)
873 A[k][0] = 2* iP[k].
get_i() ;
874 A[k][1] = 2* iP[k].
get_j() ;
887 std::cout << K << std::endl;
894 std::cout <<
"vpMeEllipse::initTracking() ellipse avant: " <<
iPc <<
" " <<
a <<
" " <<
b <<
" " <<
vpMath::deg(
e) <<
" alpha: " <<
alpha1 <<
" " <<
alpha2 << std::endl;
897 std::cout <<
"vpMeEllipse::initTracking() ellipse apres: " <<
iPc <<
" " <<
a <<
" " <<
b <<
" " <<
vpMath::deg(
e) <<
" alpha: " <<
alpha1 <<
" " <<
alpha2 << std::endl;
924 double low_alpha,
double high_alpha)
971 vpCDEBUG(1) <<
"begin vpMeEllipse::track()"<<std::endl ;
1008 seekExtremities(I) ;
1069 vpCDEBUG(1) <<
"end vpMeEllipse::track()"<<std::endl ;
1080 vpMeEllipse::computeMoments()
1082 double tane = tan(-1/
e);
1101 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
1107 vpMeEllipse::computeAngle(
int ip1,
int jp1,
double &_alpha1,
1108 int ip2,
int jp2,
double &_alpha2)
1112 double j1, i1, j11, i11;
1115 int number_of_points = 2000 ;
1116 double incr = 2 * M_PI / number_of_points ;
1118 double dmin1 = 1e6 ;
1119 double dmin2 = 1e6 ;
1161 vpMeEllipse::computeAngle(
int ip1,
int jp1,
int ip2,
int jp2)
1165 computeAngle(ip1,jp1,a1, ip2, jp2,a2) ;
1171 unsigned *i,
unsigned *j)
1173 vpCDEBUG(1) <<
" begin vpMeEllipse::initTracking()"<<std::endl ;
1185 for (
unsigned int k =0 ; k < n ; k++)
1188 A[k][1] = 2* i[k] * j[k] ;
1197 std::cout << K << std::endl;
1206 for (
unsigned int k =0 ; k < n ; k++)
1222 std::cout << K << std::endl;
1252 #endif // Deprecated
1277 const double &A,
const double &B,
const double &E,
1278 const double & smallalpha,
const double &highalpha,
1279 const vpColor &color,
unsigned int thickness)
1285 j1 = j2 = i1 = i2 = 0 ;
1291 double k = smallalpha ;
1292 while (k+incr<highalpha)
1297 j2 = A *cos(k+incr) ;
1298 i2 = B *sin(k+incr) ;
1303 iP11.
set_j ( center.
get_j() + cos(E) *j1 - sin(E) *i1 );
1304 iP11.
set_i ( center.
get_i() -( sin(E) *j1 + cos(E) *i1) );
1306 iP22.
set_j ( center.
get_j() + cos(E) *j2 - sin(E) *i2 );
1307 iP22.
set_i ( center.
get_i() -( sin(E) *j2 + cos(E) *i2) );
1314 j1 = A *cos(smallalpha) ;
1315 i1 = B *sin(smallalpha) ;
1317 j2 = A *cos(highalpha) ;
1318 i2 = B *sin(highalpha) ;
1323 iP11.
set_j ( center.
get_j() + cos(E) *j1 - sin(E) *i1 );
1324 iP11.
set_i ( center.
get_i() -( sin(E) *j1 + cos(E) *i1) );
1326 iP22.
set_j ( center.
get_j() + cos(E) *j2 - sin(E) *i2 );
1327 iP22.
set_i ( center.
get_i() -( sin(E) *j2 + cos(E) *i2) );
1356 const double &A,
const double &B,
const double &E,
1357 const double & smallalpha,
const double &highalpha,
1358 const vpColor &color,
unsigned int thickness)
1364 j1 = j2 = i1 = i2 = 0 ;
1370 double k = smallalpha ;
1371 while (k+incr<highalpha)
1376 j2 = A *cos(k+incr) ;
1377 i2 = B *sin(k+incr) ;
1382 iP11.
set_j ( center.
get_j() + cos(E) *j1 - sin(E) *i1 );
1383 iP11.
set_i ( center.
get_i() -( sin(E) *j1 + cos(E) *i1) );
1385 iP22.
set_j ( center.
get_j() + cos(E) *j2 - sin(E) *i2 );
1386 iP22.
set_i ( center.
get_i() -( sin(E) *j2 + cos(E) *i2) );
1393 j1 = A *cos(smallalpha) ;
1394 i1 = B *sin(smallalpha) ;
1396 j2 = A *cos(highalpha) ;
1397 i2 = B *sin(highalpha) ;
1402 iP11.
set_j ( center.
get_j() + cos(E) *j1 - sin(E) *i1 );
1403 iP11.
set_i ( center.
get_i() -( sin(E) *j1 + cos(E) *i1) );
1405 iP22.
set_j ( center.
get_j() + cos(E) *j2 - sin(E) *i2 );
1406 iP22.
set_i ( center.
get_i() -( sin(E) *j2 + cos(E) *i2) );
double a
is the semiminor axis of the ellipse.
unsigned int getRange() const
Definition of the vpMatrix class.
double expecteddensity
Expected number of me to track along the ellipse.
double e
is the angle made by the major axis and the i axis of the image frame .
void initTracking(const vpImage< unsigned char > &I)
unsigned int getWidth() const
unsigned int numberOfSignal()
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
double thresholdWeight
Threshold for the robust least square.
Class to define colors available for display functionnalities.
int outOfImage(int i, int j, int half, int rows, int cols)
vpImagePoint iP1
The coordinates of the point corresponding to the smallest angle. More things about the are given a...
Class that tracks an ellipse moving edges.
#define vpDEBUG_ENABLE(level)
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static int round(const double x)
double b
is the semimajor axis of the ellipse.
double se
Value of sin(e).
void setMu1(const double &mu_1)
vpMeSiteState getState() const
void set_i(const double ii)
void track(const vpImage< unsigned char > &Im)
std::list< vpMeSite > list
Error that can be emited by the vpTracker class and its derivates.
vpImagePoint iP2
The coordinates of the point corresponding to the highest angle. More things about the are given at...
vpImagePoint iPc
The coordinates of the ellipse center.
double m11
Second order raw moments.
double alpha1
The smallest angle.
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 display(const vpImage< unsigned char > &I, vpColor col)
void track(const vpImage< unsigned char > &I)
Track sampled pixels.
double mu11
Second order central moments.
double m10
First order raw moments.
Contains abstract elements for a Distance to Feature type feature.
void setState(const vpMeSiteState &flag)
static double rad(double deg)
std::list< double > angle
Stores the value of the angle for each vpMeSite.
void set_j(const double jj)
void setMu2(const double &mu_2)
static double deg(double rad)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
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)
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
double alpha2
The highest angle.
void setRange(const unsigned int &r)
double getSampleStep() const
vpMeSite::vpMeSiteDisplayType selectDisplay
virtual void display(const vpImage< unsigned char > &I, vpColor col)=0
double ce
Value of cos(e).
void set_ij(const double ii, const double jj)
static const vpColor blue