39 #include <visp3/core/vpTrackingException.h>
40 #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;
71 ptBspFct = &vpTemplateTrackerBSpline::Bspline4;
72 ptdBspFct = &vpTemplateTrackerMIBSpline::dBspline4;
73 ptd2BspFct = &vpTemplateTrackerMIBSpline::d2Bspline4;
77 for (
int it = -1; it <= endIndex; it++) {
78 ptTemplateSupp[ptIndex].BtInit[index++] = (*ptBspFct)(
static_cast<double>(-it) + et);
80 for (
unsigned int ip = 0; ip <
nbParam; ++ip) {
81 ptTemplateSupp[ptIndex].BtInit[index++] =
82 (*ptdBspFct)(
static_cast<double>(-it) + et) *
ptTemplate[ptIndex].
dW[ip] * (-1.0);
83 for (
unsigned int ip2 = 0; ip2 <
nbParam; ++ip2) {
84 ptTemplateSupp[ptIndex].BtInit[index++] =
93 ptTemplateSupp =
new vpTemplateTrackerPointSuppMIInv[
templateSize];
104 double Nc_255_ = (
Nc - 1) / 255.;
105 Warp->computeCoeff(
p);
106 for (
unsigned int point = 0; point <
templateSize; point++) {
117 int ct =
static_cast<int>(Tij * Nc_255_);
118 double et = (Tij * Nc_255_) - ct;
119 ptTemplateSupp[point].et = et;
120 ptTemplateSupp[point].ct = ct;
122 CompoInitialised =
true;
141 Warp->computeCoeff(
p);
143 for (
unsigned int point = 0; point <
templateSize; point++) {
155 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
163 ct = ptTemplateSupp[point].ct;
164 et = ptTemplateSupp[point].et;
165 cr =
static_cast<int>((IW * (
Nc - 1)) / 255.);
166 er = (IW * (
Nc - 1)) / 255. - cr;
201 if (!CompoInitialised) {
202 std::cout <<
"Compositionnal tracking not initialised.\nUse initCompInverse() function." << std::endl;
211 double MI = 0, MIprec = -1000;
214 p_avant_estimation =
p;
223 unsigned int iteration = 0;
226 double evolRMS_init = 0;
227 double evolRMS_prec = 0;
228 double evolRMS_delta;
241 Warp->computeCoeff(
p);
243 for (
int point = 0; point < static_cast<int>(
templateSize); point++) {
253 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
258 IW =
static_cast<double>(I.
getValue(i2, j2));
262 int ct = ptTemplateSupp[point].ct;
263 double et = ptTemplateSupp[point].et;
264 double tmp = IW * (
static_cast<double>(
Nc) - 1.) / 255.;
265 int cr =
static_cast<int>(tmp);
266 double er = tmp -
static_cast<double>(cr);
296 unsigned int indd, indd2;
298 unsigned int Ncb_ =
static_cast<unsigned int>(
Ncb);
299 for (
unsigned int i = 0; i < Ncb_ * Ncb_; i++) {
301 for (
unsigned int j = 0; j <
nbParam; j++) {
302 dPrt[indd] /= Nbpoint;
304 for (
unsigned int k = 0; k <
nbParam; k++) {
305 d2Prt[indd2] /= Nbpoint;
341 switch (minimizationMethod) {
344 dp_test_LMA = -100000.1 *
dp;
351 double MI_LMA = -
getCost(I, p_test_LMA);
369 double s_scal_y = s_quasi.
t() * y_quasi;
370 if (std::fabs(s_scal_y) > std::numeric_limits<double>::epsilon()) {
371 KQuasiNewton = KQuasiNewton + 0.0001 * (s_quasi * s_quasi.
t() / s_scal_y -
372 KQuasiNewton * y_quasi * y_quasi.
t() * KQuasiNewton /
373 (y_quasi.
t() * KQuasiNewton * y_quasi));
398 if (iteration == 0) {
404 evolRMS_delta = std::fabs(
evolRMS - evolRMS_prec);
407 }
while ((!
diverge) && (std::fabs(MI - MIprec) > std::fabs(MI) * std::numeric_limits<double>::epsilon()) &&
425 p = p_avant_estimation;
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
static void getGradX(const vpImage< unsigned char > &I, vpImage< FilterType > &dIx, const vpImage< bool > *p_mask=nullptr)
static void getGradXGauss2D(const vpImage< ImageType > &I, vpImage< FilterType > &dIx, const FilterType *gaussianKernel, const FilterType *gaussianDerivativeKernel, unsigned int size, const vpImage< bool > *p_mask=nullptr)
static void filter(const vpImage< ImageType > &I, vpImage< FilterType > &If, const vpArray2D< FilterType > &M, bool convolve=false, const vpImage< bool > *p_mask=nullptr)
static void getGradYGauss2D(const vpImage< ImageType > &I, vpImage< FilterType > &dIy, const FilterType *gaussianKernel, const FilterType *gaussianDerivativeKernel, unsigned int size, const vpImage< bool > *p_mask=nullptr)
static void getGradY(const vpImage< unsigned char > &I, vpImage< FilterType > &dIy, const vpImage< bool > *p_mask=nullptr)
unsigned int getWidth() const
Type getValue(unsigned int i, unsigned int j) const
unsigned int getHeight() const
Implementation of a matrix and operations on matrices.
double cond(double svThreshold=1e-6) const
vpMatrix inverseByLU() const
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
void initCompInverse(const vpImage< unsigned char > &I)
void initHessienDesired(const vpImage< unsigned char > &I)
vpTemplateTrackerMIInverseCompositional()
Default constructor.
void trackNoPyr(const vpImage< unsigned char > &I)
void initTemplateRefBspline(unsigned int ptIndex, double &et)
vpHessienApproximationType ApproxHessian
void computeHessienNormalized(vpMatrix &H)
vpHessienType hessianComputation
double getCost(const vpImage< unsigned char > &I, const vpColVector &tp) VP_OVERRIDE
void computeMI(double &MI)
void computeProba(int &nbpoint)
void computeHessien(vpMatrix &H)
double getNormalizedCost(const vpImage< unsigned char > &I, const vpColVector &tp)
vpMatrix covarianceMatrix
double NMI_postEstimation
unsigned int getNbParam() const
virtual void getParamInverse(const vpColVector &p, vpColVector &p_inv) const =0
virtual void getdW0(const int &v, const int &u, const double &dv, const double &du, double *dIdW)=0
virtual void warpX(const int &v1, const int &u1, double &v2, double &u2, const vpColVector &p)=0
virtual void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &p12) const =0
vpMatrix HLMdesireInverse
void computeEvalRMS(const vpColVector &p)
void computeOptimalBrentGain(const vpImage< unsigned char > &I, vpColVector &tp, double tMI, vpColVector &direction, double &alpha)
unsigned int iterationMax
void initPosEvalRMS(const vpColVector &p)
vpTemplateTrackerPoint * ptTemplate
vpTemplateTrackerWarp * Warp
unsigned int iterationGlobale
unsigned int templateSize
Error that can be emitted by the vpTracker class and its derivatives.
@ notEnoughPointError
Not enough point to track.