40 #include <visp3/core/vpTrackingException.h> 41 #include <visp3/tt_mi/vpTemplateTrackerMIInverseCompositional.h> 46 :
vpTemplateTrackerMI(_warp), minimizationMethod(USE_LMA), CompoInitialised(false), useTemplateSelect(false),
47 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)(
static_cast<double>(-it) + et);
79 for (
unsigned int ip = 0; ip <
nbParam; ++ip) {
80 ptTemplateSupp[ptIndex].BtInit[index++] = (*ptdBspFct)(
static_cast<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];
102 double Nc_255_ = (
Nc - 1) / 255.;
103 Warp->computeCoeff(
p);
104 for (
unsigned int point = 0; point <
templateSize; point++) {
115 int ct =
static_cast<int>(Tij * Nc_255_);
116 double et = (Tij * Nc_255_) - ct;
117 ptTemplateSupp[point].et = et;
118 ptTemplateSupp[point].ct = ct;
120 CompoInitialised =
true;
139 Warp->computeCoeff(
p);
141 for (
unsigned int point = 0; point <
templateSize; point++) {
153 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
161 ct = ptTemplateSupp[point].ct;
162 et = ptTemplateSupp[point].et;
163 cr =
static_cast<int>((IW * (
Nc - 1)) / 255.);
164 er = (IW * (
Nc - 1)) / 255. - cr;
196 if (!CompoInitialised) {
197 std::cout <<
"Compositionnal tracking not initialised.\nUse initCompInverse() function." << std::endl;
206 double MI = 0, MIprec = -1000;
209 p_avant_estimation =
p;
218 unsigned int iteration = 0;
221 double evolRMS_init = 0;
222 double evolRMS_prec = 0;
223 double evolRMS_delta;
236 Warp->computeCoeff(
p);
238 for (
int point = 0; point < static_cast<int>(
templateSize); point++) {
248 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
253 IW =
static_cast<double>(I.
getValue(i2, j2));
257 int ct = ptTemplateSupp[point].ct;
258 double et = ptTemplateSupp[point].et;
259 double tmp = IW * (
static_cast<double>(
Nc) - 1.) / 255.;
260 int cr =
static_cast<int>(tmp);
261 double er = tmp -
static_cast<double>(cr);
269 vpTemplateTrackerMIBSpline::PutTotPVBspline3(
Prt,
dPrt,
d2Prt, cr, er, ct, et,
Ncb,
272 vpTemplateTrackerMIBSpline::PutTotPVBspline4(
Prt,
dPrt,
d2Prt, cr, er, ct, et,
Ncb,
287 unsigned int indd, indd2;
289 unsigned int Ncb_ =
static_cast<unsigned int>(
Ncb);
290 for (
unsigned int i = 0; i < Ncb_ * Ncb_; i++) {
292 for (
unsigned int j = 0; j <
nbParam; j++) {
293 dPrt[indd] /= Nbpoint;
295 for (
unsigned int k = 0; k <
nbParam; k++) {
296 d2Prt[indd2] /= Nbpoint;
331 switch (minimizationMethod) {
334 dp_test_LMA = -100000.1 *
dp;
341 double MI_LMA = -
getCost(I, p_test_LMA);
358 double s_scal_y = s_quasi.
t() * y_quasi;
359 if (std::fabs(s_scal_y) > std::numeric_limits<double>::epsilon()) {
360 KQuasiNewton = KQuasiNewton + 0.0001 * (s_quasi * s_quasi.
t() / s_scal_y -
361 KQuasiNewton * y_quasi * y_quasi.
t() * KQuasiNewton /
362 (y_quasi.
t() * KQuasiNewton * y_quasi));
387 if (iteration == 0) {
393 evolRMS_delta = std::fabs(
evolRMS - evolRMS_prec);
396 }
while ((!
diverge) && (std::fabs(MI - MIprec) > std::fabs(MI) *std::numeric_limits<double>::epsilon()) &&
413 p = p_avant_estimation;
Implementation of a matrix and operations on matrices.
void initTemplateRefBspline(unsigned int ptIndex, double &et)
double NMI_postEstimation
void computeHessien(vpMatrix &H)
vpMatrix covarianceMatrix
Type getValue(unsigned int i, unsigned int j) const
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.
void initPosEvalRMS(const vpColVector &p)
static void getGradYGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIy, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
void computeEvalRMS(const vpColVector &p)
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
unsigned int templateSize
double cond(double svThreshold=1e-6) const
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)
unsigned int iterationGlobale
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)
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M, bool convolve=false)
vpMatrix HLMdesireInverse
unsigned int getHeight() const
Implementation of column vector and the associated operations.
void computeHessienNormalized(vpMatrix &H)
vpTemplateTrackerWarp * Warp
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
unsigned int getWidth() const
void computeProba(int &nbpoint)
vpHessienType hessianComputation