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.), thresholdWeight(0.2), circle(false)
88 vpCDEBUG(1) <<
"begin vpMeEllipse::vpMeEllipse() " << std::endl ;
101 vpCDEBUG(1) <<
"end vpMeEllipse::vpMeEllipse() " << std::endl ;
108 :
vpMeTracker(meellipse), K(), iPc(), a(0.), b(0.), e(0.), iP1(), iP2(), alpha1(0), alpha2(2*M_PI),
109 ce(0.), se(0.), angle(), m00(0.), mu11(0.), mu20(0.), mu02(0.),
110 m10(0.), m01(0.), m11(0.), m02(0.), m20(0.), thresholdWeight(0.2), circle(false)
138 circle = meellipse.circle;
146 vpCDEBUG(1) <<
"begin vpMeEllipse::~vpMeEllipse() " << std::endl ;
151 vpCDEBUG(1) <<
"end vpMeEllipse::~vpMeEllipse() " << std::endl ;
168 vpCDEBUG(1) <<
"begin vpMeEllipse::sample() : "<<std::endl ;
171 vpDERROR_TRACE(2,
"Tracking error: Moving edges not initialized");
173 "Moving edges not initialized")) ;
182 if (std::fabs(
me->
getSampleStep()) <= std::numeric_limits<double>::epsilon())
184 std::cout <<
"In vpMeEllipse::sample: " ;
185 std::cout <<
"function called with sample step = 0" ;
224 computeTheta(theta, K, iP11) ;
246 n_sample = (
unsigned int)
list.size() ;
248 vpCDEBUG(1) <<
"end vpMeEllipse::sample() : " ;
249 vpCDEBUG(1) << n_sample <<
" point inserted in the list " << std::endl ;
271 vpDERROR_TRACE(2,
"Tracking error: Moving edges not initialized");
273 "Moving edges not initialized")) ;
278 if ((
double)n<0.9*expecteddensity){
291 vpMeEllipse::getParameters()
295 for (
unsigned int i=0 ; i < 5 ; i++)
299 double d = k[2]*k[2] - k[0]*k[1];
302 iPc.
set_i( (k[1] * k[3] - k[2] * k[4]) / d );
303 iPc.
set_j( (k[0] * k[4] - k[2] * k[3]) / d );
312 e = (k[1] - k[0] + sq) / (2.0*k[2]);
318 if(
e < 0.0)
e += M_PI ;
324 double a2 = num / (k[0] + k[1] + sq ) ;
325 double b2 = num / (k[0] + k[1] - sq ) ;
338 std::cout <<
"K" << std::endl ;
340 std::cout <<
iPc << std::endl ;
356 double j1, i1, j11, i11;
359 int number_of_points = 2000 ;
360 double incr = 2 * M_PI / number_of_points ;
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;
925 vpCDEBUG(1) <<
"begin vpMeEllipse::track()"<<std::endl ;
1023 vpCDEBUG(1) <<
"end vpMeEllipse::track()"<<std::endl ;
1034 vpMeEllipse::computeMoments()
1036 double tane = tan(-1/
e);
1055 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
1061 vpMeEllipse::computeAngle(
int ip1,
int jp1,
double &_alpha1,
1062 int ip2,
int jp2,
double &_alpha2)
1066 double j1, i1, j11, i11;
1069 int number_of_points = 2000 ;
1070 double incr = 2 * M_PI / number_of_points ;
1072 double dmin1 = 1e6 ;
1073 double dmin2 = 1e6 ;
1115 vpMeEllipse::computeAngle(
int ip1,
int jp1,
int ip2,
int jp2)
1119 computeAngle(ip1,jp1,a1, ip2, jp2,a2) ;
1125 unsigned *i,
unsigned *j)
1127 vpCDEBUG(1) <<
" begin vpMeEllipse::initTracking()"<<std::endl ;
1139 for (
unsigned int k =0 ; k < n ; k++)
1142 A[k][1] = 2* i[k] * j[k] ;
1151 std::cout << K << std::endl;
1160 for (
unsigned int k =0 ; k < n ; k++)
1176 std::cout << K << std::endl;
1206 #endif // Deprecated
1229 const double &A,
const double &B,
const double &E,
1230 const double & smallalpha,
const double &highalpha,
1237 j1 = j2 = i1 = i2 = 0 ;
1243 double k = smallalpha ;
1244 while (k+incr<highalpha)
1249 j2 = A *cos(k+incr) ;
1250 i2 = B *sin(k+incr) ;
1255 iP11.
set_j ( center.
get_j() + cos(E) *j1 - sin(E) *i1 );
1256 iP11.
set_i ( center.
get_i() -( sin(E) *j1 + cos(E) *i1) );
1258 iP22.
set_j ( center.
get_j() + cos(E) *j2 - sin(E) *i2 );
1259 iP22.
set_i ( center.
get_i() -( sin(E) *j2 + cos(E) *i2) );
1266 j1 = A *cos(smallalpha) ;
1267 i1 = B *sin(smallalpha) ;
1269 j2 = A *cos(highalpha) ;
1270 i2 = B *sin(highalpha) ;
1275 iP11.
set_j ( center.
get_j() + cos(E) *j1 - sin(E) *i1 );
1276 iP11.
set_i ( center.
get_i() -( sin(E) *j1 + cos(E) *i1) );
1278 iP22.
set_j ( center.
get_j() + cos(E) *j2 - sin(E) *i2 );
1279 iP22.
set_i ( center.
get_i() -( sin(E) *j2 + cos(E) *i2) );
1306 const double &A,
const double &B,
const double &E,
1307 const double & smallalpha,
const double &highalpha,
1314 j1 = j2 = i1 = i2 = 0 ;
1320 double k = smallalpha ;
1321 while (k+incr<highalpha)
1326 j2 = A *cos(k+incr) ;
1327 i2 = B *sin(k+incr) ;
1332 iP11.
set_j ( center.
get_j() + cos(E) *j1 - sin(E) *i1 );
1333 iP11.
set_i ( center.
get_i() -( sin(E) *j1 + cos(E) *i1) );
1335 iP22.
set_j ( center.
get_j() + cos(E) *j2 - sin(E) *i2 );
1336 iP22.
set_i ( center.
get_i() -( sin(E) *j2 + cos(E) *i2) );
1343 j1 = A *cos(smallalpha) ;
1344 i1 = B *sin(smallalpha) ;
1346 j2 = A *cos(highalpha) ;
1347 i2 = B *sin(highalpha) ;
1352 iP11.
set_j ( center.
get_j() + cos(E) *j1 - sin(E) *i1 );
1353 iP11.
set_i ( center.
get_i() -( sin(E) *j1 + cos(E) *i1) );
1355 iP22.
set_j ( center.
get_j() + cos(E) *j2 - sin(E) *i2 );
1356 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 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)
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