39 #include <visp3/tt_mi/vpTemplateTrackerMIInverseCompositional.h>
40 #include <visp3/core/vpTrackingException.h>
45 :
vpTemplateTrackerMI(_warp), minimizationMethod(USE_LMA), CompoInitialised(false), useTemplateSelect(false),
46 evolRMS(0), x_pos(NULL), y_pos(NULL), threshold_RMS(1e-20), p_prec(), G_prec(), KQuasiNewton()
55 unsigned int index = 0;
58 double (*ptBspFct)(double);
59 double (*ptdBspFct)(double);
60 double (*ptd2BspFct)(double);
63 ptBspFct = &vpTemplateTrackerMIBSpline::Bspline3;
64 ptdBspFct = &vpTemplateTrackerMIBSpline::dBspline3;
65 ptd2BspFct = &vpTemplateTrackerMIBSpline::d2Bspline3;
68 ptBspFct = &vpTemplateTrackerBSpline::Bspline4;
69 ptdBspFct = &vpTemplateTrackerMIBSpline::dBspline4;
70 ptd2BspFct = &vpTemplateTrackerMIBSpline::d2Bspline4;
74 for(
int it=-1; it<=endIndex; it++)
76 ptTemplateSupp[ptIndex].BtInit[index++] = (*ptBspFct)((double)(-it)+et);
78 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)
83 ptTemplateSupp[ptIndex].BtInit[index++] = (*ptd2BspFct)((double)(-it)+et) *
ptTemplate[ptIndex].
dW[ip] *
ptTemplate[ptIndex].
dW[ip2];
91 ptTemplateSupp=
new vpTemplateTrackerPointSuppMIInv[
templateSize];
103 Warp->computeCoeff(
p);
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;
131 CompoInitialised=
true;
153 Warp->computeCoeff(
p);
183 ct=ptTemplateSupp[point].ct;
184 et=ptTemplateSupp[point].et;
185 cr=(int)((IW*(
Nc-1))/255.);
186 er=((double)IW*(
Nc-1))/255.-cr;
239 if(!CompoInitialised)
240 std::cout<<
"Compositionnal tracking no initialised\nUse InitCompInverse(vpImage<unsigned char> &I) function"<<std::endl;
247 double MI=0,MIprec=-1000;
261 unsigned int iteration=0;
276 Warp->computeCoeff(
p);
287 Warp->computeDenom(x1,
p);
304 int ct=ptTemplateSupp[point].ct;
305 double et=ptTemplateSupp[point].et;
306 double tmp = IW*(((double)
Nc)-1.f)/255.f;
308 double er=tmp-(double)cr;
344 unsigned int indd, indd2;
346 unsigned int Ncb_ = (
unsigned int)
Ncb;
347 for(
unsigned int i=0;i<Ncb_*Ncb_;i++){
349 for(
unsigned int j=0;j<
nbParam;j++){
352 for(
unsigned int k=0;k<
nbParam;k++){
394 switch(minimizationMethod)
402 dp_test_LMA=-100000.1*
dp;
409 double MI_LMA=-
getCost(I,p_test_LMA);
432 double s_scal_y=s_quasi.
t()*y_quasi;
437 if(std::fabs(s_scal_y) > std::numeric_limits<double>::epsilon())
439 KQuasiNewton=KQuasiNewton+0.0001*(s_quasi*s_quasi.
t()/s_scal_y-KQuasiNewton*y_quasi*y_quasi.
t()*KQuasiNewton/(y_quasi.
t()*KQuasiNewton*y_quasi));
476 while( (!
diverge) && (std::fabs(MI-MIprec) > std::fabs(MI)*std::numeric_limits<double>::epsilon()) &&(iteration<
iterationMax)&&(evolRMS>threshold_RMS) );
501 p=p_avant_estimation;
529 x_pos=
new double[nb_corners];
530 y_pos=
new double[nb_corners];
532 Warp->computeCoeff(pw);
538 for (
unsigned int j=0; j<3; j++) {
541 Warp->computeDenom(
X1,pw);
553 Warp->computeCoeff(pw);
560 for (
unsigned int j=0; j<3; j++) {
563 Warp->computeDenom(
X1,pw);
565 evolRMS+=(x_pos[i*3+j]-
X2[0])*(x_pos[i*3+j]-
X2[0])+(y_pos[i*3+j]-
X2[1])*(y_pos[i*3+j]-
X2[1]);
570 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)
void getTriangle(unsigned int i, vpTemplateTrackerTriangle &T) const
unsigned int getWidth() const
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
void computeOptimalBrentGain(const vpImage< unsigned char > &I, vpColVector &tp, double tMI, vpColVector &direction, double &alpha)
error that can be emited by ViSP classes.
Type getValue(double i, double j) const
vpColVector getCorner(unsigned int i) const
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)
unsigned int getNbTriangle() const
void computeMI(double &MI)
void computeEvalRMS(const vpColVector &p)
unsigned int iterationGlobale
unsigned int getNbParam() const
virtual void getdW0(const int &i, const int &j, const double &dy, const double &dx, double *dIdW)=0
double getNormalizedCost(const vpImage< unsigned char > &I, const vpColVector &tp)
vpTemplateTrackerMIInverseCompositional()
Default constructor.
void initCompInverse(const vpImage< unsigned char > &I)
vpMatrix HLMdesireInverse
Implementation of column vector and the associated operations.
vpMatrix inverseByLU() const
vpTemplateTrackerZone * zoneTracked
unsigned int getHeight() 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)
vpTemplateTrackerWarp * Warp
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
void computeProba(int &nbpoint)
vpHessienType hessianComputation