40 #include <visp3/core/vpTrackingException.h> 41 #include <visp3/tt_mi/vpTemplateTrackerMIInverseCompositional.h> 46 :
vpTemplateTrackerMI(_warp), minimizationMethod(USE_LMA), CompoInitialised(false), useTemplateSelect(false),
47 evolRMS(0), x_pos(NULL), y_pos(NULL), threshold_RMS(1e-20), p_prec(), G_prec(), KQuasiNewton()
56 unsigned int index = 0;
59 double (*ptBspFct)(double);
60 double (*ptdBspFct)(double);
61 double (*ptd2BspFct)(double);
66 ptBspFct = &vpTemplateTrackerMIBSpline::Bspline3;
67 ptdBspFct = &vpTemplateTrackerMIBSpline::dBspline3;
68 ptd2BspFct = &vpTemplateTrackerMIBSpline::d2Bspline3;
70 ptBspFct = &vpTemplateTrackerBSpline::Bspline4;
71 ptdBspFct = &vpTemplateTrackerMIBSpline::dBspline4;
72 ptd2BspFct = &vpTemplateTrackerMIBSpline::d2Bspline4;
76 for (
int it = -1; it <= endIndex; it++) {
77 ptTemplateSupp[ptIndex].BtInit[index++] = (*ptBspFct)((double)(-it) + et);
79 for (
unsigned int ip = 0; ip <
nbParam; ++ip) {
80 ptTemplateSupp[ptIndex].BtInit[index++] = (*ptdBspFct)((double)(-it) + et) *
ptTemplate[ptIndex].
dW[ip] * (-1.0);
81 for (
unsigned int ip2 = 0; ip2 <
nbParam; ++ip2) {
82 ptTemplateSupp[ptIndex].BtInit[index++] =
91 ptTemplateSupp =
new vpTemplateTrackerPointSuppMIInv[
templateSize];
103 Warp->computeCoeff(
p);
104 for (
unsigned int point = 0; point <
templateSize; point++) {
119 int ct = (int)((Tij * (
Nc - 1)) / 255.);
120 double et = (Tij * (
Nc - 1)) / 255. - ct;
122 ptTemplateSupp[point].et = et;
123 ptTemplateSupp[point].ct = ct;
133 CompoInitialised =
true;
154 Warp->computeCoeff(
p);
161 for (
unsigned int point = 0; point <
templateSize; point++) {
173 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
182 ct = ptTemplateSupp[point].ct;
183 et = ptTemplateSupp[point].et;
184 cr = (int)((IW * (
Nc - 1)) / 255.);
185 er = ((double)IW * (
Nc - 1)) / 255. - cr;
237 if (!CompoInitialised)
238 std::cout <<
"Compositionnal tracking no initialised\nUse " 239 "InitCompInverse(vpImage<unsigned char> &I) function" 247 double MI = 0, MIprec = -1000;
250 p_avant_estimation =
p;
262 unsigned int iteration = 0;
277 Warp->computeCoeff(
p);
280 for (
int point = 0; point < (int)
templateSize; point++) {
287 Warp->computeDenom(x1,
p);
295 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
307 int ct = ptTemplateSupp[point].ct;
308 double et = ptTemplateSupp[point].et;
309 double tmp = IW * (((double)
Nc) - 1.f) / 255.f;
311 double er = tmp - (double)cr;
319 vpTemplateTrackerMIBSpline::PutTotPVBspline3(
Prt,
dPrt,
d2Prt, cr, er, ct, et,
Ncb,
322 vpTemplateTrackerMIBSpline::PutTotPVBspline4(
Prt,
dPrt,
d2Prt, cr, er, ct, et,
Ncb,
342 unsigned int indd, indd2;
344 unsigned int Ncb_ = (
unsigned int)
Ncb;
345 for (
unsigned int i = 0; i < Ncb_ * Ncb_; i++) {
346 Prt[i] =
Prt[i] / Nbpoint;
347 for (
unsigned int j = 0; j <
nbParam; j++) {
350 for (
unsigned int k = 0; k <
nbParam; k++) {
388 switch (minimizationMethod) {
394 dp_test_LMA = -100000.1 *
dp;
396 dp_test_LMA = 1. *
dp;
401 double MI_LMA = -
getCost(I, p_test_LMA);
418 double s_scal_y = s_quasi.
t() * y_quasi;
423 if (std::fabs(s_scal_y) > std::numeric_limits<double>::epsilon())
425 KQuasiNewton = KQuasiNewton + 0.0001 * (s_quasi * s_quasi.
t() / s_scal_y -
426 KQuasiNewton * y_quasi * y_quasi.
t() * KQuasiNewton /
427 (y_quasi.
t() * KQuasiNewton * y_quasi));
460 }
while ((!
diverge) && (std::fabs(MI - MIprec) > std::fabs(MI) * std::numeric_limits<double>::epsilon()) &&
461 (iteration <
iterationMax) && (evolRMS > threshold_RMS));
484 p = p_avant_estimation;
511 x_pos =
new double[nb_corners];
512 y_pos =
new double[nb_corners];
514 Warp->computeCoeff(pw);
519 for (
unsigned int j = 0; j < 3; j++) {
522 Warp->computeDenom(
X1, pw);
524 x_pos[i * 3 + j] =
X2[0];
525 y_pos[i * 3 + j] =
X2[1];
534 Warp->computeCoeff(pw);
540 for (
unsigned int j = 0; j < 3; j++) {
543 Warp->computeDenom(
X1, pw);
545 evolRMS += (x_pos[i * 3 + j] -
X2[0]) * (x_pos[i * 3 + j] -
X2[0]) +
546 (y_pos[i * 3 + j] -
X2[1]) * (y_pos[i * 3 + j] -
X2[1]);
547 x_pos[i * 3 + j] =
X2[0];
548 y_pos[i * 3 + j] =
X2[1];
551 evolRMS = evolRMS / nb_corners;
Implementation of a matrix and operations on matrices.
void initTemplateRefBspline(unsigned int ptIndex, double &et)
double NMI_postEstimation
void computeHessien(vpMatrix &H)
vpMatrix covarianceMatrix
static void getGradX(const vpImage< unsigned char > &I, vpImage< double > &dIx)
vpTemplateTrackerPoint * ptTemplate
static void getGradY(const vpImage< unsigned char > &I, vpImage< double > &dIy)
virtual void warpX(const int &i, const int &j, double &i2, double &j2, const vpColVector &ParamM)=0
unsigned int getNbParam() const
vpMatrix inverseByLU() const
void computeOptimalBrentGain(const vpImage< unsigned char > &I, vpColVector &tp, double tMI, vpColVector &direction, double &alpha)
error that can be emited by ViSP classes.
static void getGradYGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIy, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
static void getGradXGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIx, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
vpHessienApproximationType ApproxHessian
void trackNoPyr(const vpImage< unsigned char > &I)
virtual void getParamInverse(const vpColVector &ParamM, vpColVector &ParamMinv) const =0
void initPosEvalRMS(const vpColVector &p)
unsigned int templateSize
unsigned int iterationMax
virtual void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &pres) const =0
void initHessienDesired(const vpImage< unsigned char > &I)
Error that can be emited by the vpTracker class and its derivates.
double getCost(const vpImage< unsigned char > &I, const vpColVector &tp)
void computeMI(double &MI)
void computeEvalRMS(const vpColVector &p)
unsigned int iterationGlobale
virtual void getdW0(const int &i, const int &j, const double &dy, const double &dx, double *dIdW)=0
Type getValue(double i, double j) const
double getNormalizedCost(const vpImage< unsigned char > &I, const vpColVector &tp)
vpTemplateTrackerMIInverseCompositional()
Default constructor.
vpColVector getCorner(unsigned int i) const
void initCompInverse(const vpImage< unsigned char > &I)
vpMatrix HLMdesireInverse
unsigned int getHeight() const
Implementation of column vector and the associated operations.
vpTemplateTrackerZone * zoneTracked
unsigned int getNbTriangle() const
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M, const bool convolve=false)
void computeHessienNormalized(vpMatrix &H)
void getTriangle(unsigned int i, vpTemplateTrackerTriangle &T) const
vpTemplateTrackerWarp * Warp
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
unsigned int getWidth() const
void computeProba(int &nbpoint)
vpHessienType hessianComputation