39 #include <visp3/me/vpMeEllipse.h> 41 #include <visp3/core/vpDebug.h> 42 #include <visp3/core/vpException.h> 43 #include <visp3/core/vpImagePoint.h> 44 #include <visp3/core/vpRobust.h> 45 #include <visp3/me/vpMe.h> 63 double i = iP.
get_i();
64 double j = iP.
get_j();
66 double A = 2 * i + 2 * K[1] * j + 2 * K[2];
67 double B = 2 * K[0] * j + 2 * K[1] * i + 2 * K[3];
71 while (theta > M_PI) {
83 : K(), iPc(), a(0.), b(0.), e(0.), iP1(), iP2(), alpha1(0), alpha2(2 * M_PI), ce(0.), se(0.), angle(), m00(0.),
84 mu11(0.), mu20(0.), mu02(0.), m10(0.), m01(0.), m11(0.), m02(0.), m20(0.), thresholdWeight(0.2), expecteddensity(0.)
159 if (std::fabs(
me->
getSampleStep()) <= std::numeric_limits<double>::epsilon()) {
160 std::cout <<
"In vpMeEllipse::sample: ";
161 std::cout <<
"function called with sample step = 0";
179 double j =
a * sin(k);
180 double i =
b * cos(k);
191 computeTheta(theta, K, iP11);
249 void vpMeEllipse::getParameters()
252 for (
unsigned int i = 0; i < 5; i++)
256 double d = k[2] * k[2] - k[0] * k[1];
258 iPc.
set_i((k[1] * k[3] - k[2] * k[4]) / d);
259 iPc.
set_j((k[0] * k[4] - k[2] * k[3]) / d);
263 if (std::fabs(k[2]) <= std::numeric_limits<double>::epsilon()) {
266 e = (k[1] - k[0] + sq) / (2.0 * k[2]);
280 double a2 = num / (k[0] + k[1] + sq);
281 double b2 = num / (k[0] + k[1] - sq);
293 std::cout <<
"K" << std::endl;
295 std::cout <<
iPc << std::endl;
311 int number_of_points = 2000;
312 double incr = 2 * M_PI / number_of_points;
318 while (k < 2 * M_PI) {
320 double j1 =
a * sin(k);
321 double i1 =
b * cos(k);
346 else if (std::fabs(
alpha2 -
alpha1) < std::fabs(
alpha1) * std::numeric_limits<double>::epsilon())
355 void vpMeEllipse::updateTheta()
359 for (std::list<vpMeSite>::iterator it =
list.begin(); it !=
list.end(); ++it) {
364 computeTheta(theta, K, iP);
374 void vpMeEllipse::suppressPoints()
377 std::list<vpMeSite>::iterator itList =
list.begin();
378 for (std::list<double>::iterator it =
angle.begin(); it !=
angle.end();) {
381 itList =
list.erase(itList);
382 it =
angle.erase(it);
428 for (
unsigned int i = 0; i < 3; i++) {
463 for (
unsigned int i = 0; i < 3; i++) {
508 void vpMeEllipse::setExtremities()
510 double alphamin = +1e6;
511 double alphamax = -1e6;
518 std::list<double>::const_iterator itAngle =
angle.begin();
520 for (std::list<vpMeSite>::const_iterator itList =
list.begin(); itList !=
list.end(); ++itList) {
522 double alpha = *itAngle;
523 if (alpha < alphamin) {
529 if (alpha > alphamax) {
548 void vpMeEllipse::leastSquare()
557 unsigned int iter = 0;
570 if (
list.size() < 3) {
578 for (std::list<vpMeSite>::const_iterator it =
list.begin(); it !=
list.end(); ++it) {
583 A[k][2] = 2 * p_me.
ifloat;
584 A[k][3] = 2 * p_me.
jfloat;
604 for (i = 0; i < nos_1; i++) {
612 for (std::list<vpMeSite>::iterator it =
list.begin(); it !=
list.end(); ++it) {
623 for (i = 0; i < 5; i++)
653 const unsigned int n = 5;
656 for (
unsigned int k = 0; k < n; k++) {
657 std::cout <<
"Click points " << k + 1 <<
"/" << n;
658 std::cout <<
" on the ellipse in the trigonometric order" << std::endl;
662 std::cout << iP[k] << std::endl;
693 for (
unsigned int k = 0; k < n; k++) {
696 A[k][2] = 2 * iP[k].
get_i();
697 A[k][3] = 2 * iP[k].
get_j();
739 unsigned int n = (
unsigned int)(iP.size());
748 for (
unsigned int k = 0; k < n; k++) {
750 A[k][1] = 2 * iP[k].get_i() * iP[k].get_j();
751 A[k][2] = 2 * iP[k].get_i();
752 A[k][3] = 2 * iP[k].get_j();
781 double e_p,
double low_alpha,
double high_alpha)
853 void vpMeEllipse::computeMoments()
855 double tane = tan(-1 /
e);
867 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS 872 void vpMeEllipse::computeAngle(
int ip1,
int jp1,
double &_alpha1,
int ip2,
int jp2,
double &_alpha2)
876 int number_of_points = 2000;
877 double incr = 2 * M_PI / number_of_points;
885 double j1 =
a * cos(k);
886 double i1 =
b * sin(k);
918 void vpMeEllipse::computeAngle(
int ip1,
int jp1,
int ip2,
int jp2)
922 computeAngle(ip1, jp1, a1, ip2, jp2, a2);
935 for (
unsigned int k = 0; k < n; k++) {
937 A[k][1] = 2 * i[k] * j[k];
995 const double &E,
const double &smallalpha,
const double &highalpha,
const vpColor &color,
996 unsigned int thickness)
1002 j1 = j2 = i1 = i2 = 0;
1008 double k = smallalpha;
1009 while (k + incr < highalpha) {
1013 j2 = A * cos(k + incr);
1014 i2 = B * sin(k + incr);
1019 iP11.
set_j(center.
get_j() + cos(E) * j1 - sin(E) * i1);
1020 iP11.
set_i(center.
get_i() - (sin(E) * j1 + cos(E) * i1));
1022 iP22.
set_j(center.
get_j() + cos(E) * j2 - sin(E) * i2);
1023 iP22.
set_i(center.
get_i() - (sin(E) * j2 + cos(E) * i2));
1030 j1 = A * cos(smallalpha);
1031 i1 = B * sin(smallalpha);
1033 j2 = A * cos(highalpha);
1034 i2 = B * sin(highalpha);
1039 iP11.
set_j(center.
get_j() + cos(E) * j1 - sin(E) * i1);
1040 iP11.
set_i(center.
get_i() - (sin(E) * j1 + cos(E) * i1));
1042 iP22.
set_j(center.
get_j() + cos(E) * j2 - sin(E) * i2);
1043 iP22.
set_i(center.
get_i() - (sin(E) * j2 + cos(E) * i2));
1073 const double &E,
const double &smallalpha,
const double &highalpha,
const vpColor &color,
1074 unsigned int thickness)
1080 j1 = j2 = i1 = i2 = 0;
1086 double k = smallalpha;
1087 while (k + incr < highalpha) {
1091 j2 = A * cos(k + incr);
1092 i2 = B * sin(k + incr);
1097 iP11.
set_j(center.
get_j() + cos(E) * j1 - sin(E) * i1);
1098 iP11.
set_i(center.
get_i() - (sin(E) * j1 + cos(E) * i1));
1100 iP22.
set_j(center.
get_j() + cos(E) * j2 - sin(E) * i2);
1101 iP22.
set_i(center.
get_i() - (sin(E) * j2 + cos(E) * i2));
1108 j1 = A * cos(smallalpha);
1109 i1 = B * sin(smallalpha);
1111 j2 = A * cos(highalpha);
1112 i2 = B * sin(highalpha);
1117 iP11.
set_j(center.
get_j() + cos(E) * j1 - sin(E) * i1);
1118 iP11.
set_i(center.
get_i() - (sin(E) * j1 + cos(E) * i1));
1120 iP22.
set_j(center.
get_j() + cos(E) * j2 - sin(E) * i2);
1121 iP22.
set_i(center.
get_i() - (sin(E) * j2 + cos(E) * i2));
double a
is the semiminor axis of the ellipse.
Implementation of a matrix and operations on matrices.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
double expecteddensity
Expected number of me to track along the ellipse.
vpMeSiteState getState() const
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void initTracking(const vpImage< unsigned char > &I)
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Compute the weights according a residue vector and a PsiFunction.
#define vpDEBUG_ENABLE(level)
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.
error that can be emited by ViSP classes.
Class that tracks an ellipse moving edges.
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)
void set_i(const double ii)
void track(const vpImage< unsigned char > &Im)
std::list< vpMeSite > list
double getSampleStep() const
int outOfImage(int i, int j, int half, int row, int cols)
vpImagePoint iPc
The coordinates of the ellipse center.
double m11
Second order raw moments.
double alpha1
The smallest angle.
static double sqr(double x)
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)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
void setMu2(const double &mu_2)
unsigned int getHeight() const
Implementation of column vector and the associated operations.
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)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
double alpha2
The highest angle.
void setRange(const unsigned int &r)
void setThreshold(const double noise_threshold)
vpMeSite::vpMeSiteDisplayType selectDisplay
unsigned int getWidth() const
void setIteration(const unsigned int iter)
Set iteration.
unsigned int getRange() const
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