37#include <visp3/core/vpTrackingException.h>
38#include <visp3/tt_mi/vpTemplateTrackerMIInverseCompositional.h>
45 p_prec(), G_prec(), KQuasiNewton()
54 unsigned int index = 0;
57 double (*ptBspFct)(double);
58 double (*ptdBspFct)(double);
59 double (*ptd2BspFct)(double);
64 ptBspFct = &vpTemplateTrackerMIBSpline::Bspline3;
65 ptdBspFct = &vpTemplateTrackerMIBSpline::dBspline3;
66 ptd2BspFct = &vpTemplateTrackerMIBSpline::d2Bspline3;
69 ptBspFct = &vpTemplateTrackerBSpline::Bspline4;
70 ptdBspFct = &vpTemplateTrackerMIBSpline::dBspline4;
71 ptd2BspFct = &vpTemplateTrackerMIBSpline::d2Bspline4;
75 for (
int it = -1; it <= endIndex; it++) {
76 ptTemplateSupp[ptIndex].BtInit[index++] = (*ptBspFct)(
static_cast<double>(-it) + et);
78 for (
unsigned int ip = 0; ip <
nbParam; ++ip) {
79 ptTemplateSupp[ptIndex].BtInit[index++] =
80 (*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)) {
157 IW =
BI.getValue(i2, j2);
159 IW = I.getValue(i2, j2);
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;
199 if (!CompoInitialised) {
200 std::cout <<
"Compositionnal tracking not initialised.\nUse initCompInverse() function." << std::endl;
209 double MI = 0, MIprec = -1000;
212 p_avant_estimation =
p;
221 unsigned int iteration = 0;
224 double evolRMS_init = 0;
225 double evolRMS_prec = 0;
226 double evolRMS_delta;
239 Warp->computeCoeff(
p);
241 for (
int point = 0; point < static_cast<int>(
templateSize); point++) {
251 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.getHeight() - 1) && (j2 < I.getWidth() - 1)) {
256 IW =
static_cast<double>(I.getValue(i2, j2));
258 IW =
BI.getValue(i2, j2);
260 int ct = ptTemplateSupp[point].ct;
261 double et = ptTemplateSupp[point].et;
262 double tmp = IW * (
static_cast<double>(
Nc) - 1.) / 255.;
263 int cr =
static_cast<int>(tmp);
264 double er = tmp -
static_cast<double>(cr);
294 unsigned int indd, indd2;
296 unsigned int Ncb_ =
static_cast<unsigned int>(
Ncb);
297 for (
unsigned int i = 0; i < Ncb_ * Ncb_; i++) {
299 for (
unsigned int j = 0; j <
nbParam; j++) {
300 dPrt[indd] /= Nbpoint;
302 for (
unsigned int k = 0; k <
nbParam; k++) {
303 d2Prt[indd2] /= Nbpoint;
339 switch (minimizationMethod) {
342 dp_test_LMA = -100000.1 *
dp;
345 Warp->getParamInverse(dp_test_LMA, dpinv_test_LMA);
346 Warp->pRondp(
p, dpinv_test_LMA, p_test_LMA);
349 double MI_LMA = -
getCost(I, p_test_LMA);
367 double s_scal_y = s_quasi.
t() * y_quasi;
368 if (std::fabs(s_scal_y) > std::numeric_limits<double>::epsilon()) {
369 KQuasiNewton = KQuasiNewton + 0.0001 * (s_quasi * s_quasi.
t() / s_scal_y -
370 KQuasiNewton * y_quasi * y_quasi.
t() * KQuasiNewton /
371 (y_quasi.
t() * KQuasiNewton * y_quasi));
392 Warp->getParamInverse(
dp, dpinv);
393 Warp->pRondp(
p, dpinv,
p);
396 if (iteration == 0) {
402 evolRMS_delta = std::fabs(
evolRMS - evolRMS_prec);
405 }
while ((!
diverge) && (std::fabs(MI - MIprec) > std::fabs(MI) * std::numeric_limits<double>::epsilon()) &&
423 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)
Definition of the vpImage class member functions.
Implementation of a matrix and operations on matrices.
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)
vpTemplateTrackerMI(const vpTemplateTrackerMI &)=delete
vpMatrix covarianceMatrix
double NMI_postEstimation
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.