41 #include <visp3/core/vpImageFilter.h>
42 #include <visp3/tt/vpTemplateTrackerZNCCInverseCompositional.h>
56 for (
unsigned int point = 0; point <
templateSize; point++) {
86 Warp->computeCoeff(
p);
87 double Ic, dIcx = 0., dIcy = 0.;
96 double *tempt =
new double[
nbParam];
103 for (
unsigned int point = 0; point <
templateSize; point++) {
114 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
126 for (
unsigned int it = 0; it <
nbParam; it++)
130 for (
unsigned int it = 0; it <
nbParam; it++)
131 tempt[it] =
dW[0][it] * dIcx +
dW[1][it] * dIcy;
132 double d_Ixx = dIxx.
getValue(i2, j2);
133 double d_Iyy = dIyy.
getValue(i2, j2);
134 double d_Ixy = dIxy.
getValue(i2, j2);
136 for (
unsigned int it = 0; it <
nbParam; it++)
137 for (
unsigned int jt = 0; jt <
nbParam; jt++) {
138 moyd2Iref[it][jt] += (
dW[0][it] * (
dW[0][jt] * d_Ixx +
dW[1][jt] * d_Ixy) +
139 dW[1][it] * (
dW[0][jt] * d_Ixy +
dW[1][jt] * d_Iyy));
144 moyIref = moyIref / Nbpoint;
146 moyd2Iref = moyd2Iref / Nbpoint;
147 moyIc = moyIc / Nbpoint;
149 double covarIref = 0, covarIc = 0;
157 for (
unsigned int point = 0; point <
templateSize; point++) {
170 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
183 for (
unsigned int it = 0; it <
nbParam; it++) {
184 tempt[it] =
dW[0][it] * dIcx +
dW[1][it] * dIcy;
187 double prodIc = (Ic - moyIc);
189 double d_Ixx = dIxx.
getValue(i2, j2);
190 double d_Iyy = dIyy.
getValue(i2, j2);
191 double d_Ixy = dIxy.
getValue(i2, j2);
193 for (
unsigned int it = 0; it <
nbParam; it++) {
194 for (
unsigned int jt = 0; jt <
nbParam; jt++) {
195 sIcd2Iref[it][jt] += prodIc * (
dW[0][it] * (
dW[0][jt] * d_Ixx +
dW[1][jt] * d_Ixy) +
196 dW[1][it] * (
dW[0][jt] * d_Ixy +
dW[1][jt] * d_Iyy) - moyd2Iref[it][jt]);
197 sdIrefdIref[it][jt] +=
202 for (
unsigned int it = 0; it <
nbParam; it++)
205 covarIref += (Iref - moyIref) * (Iref - moyIref);
206 covarIc += (Ic - moyIc) * (Ic - moyIc);
207 sIcIref += (Iref - moyIref) * (Ic - moyIc);
212 covarIref = sqrt(covarIref);
213 covarIc = sqrt(covarIc);
215 denom = covarIref * covarIc;
217 double NCC = sIcIref / denom;
219 dcovarIref = -sIcdIref / covarIref;
222 dNCC = (sIcdIref / denom - NCC * dcovarIref / covarIref);
224 d2covarIref = -(sIcd2Iref - sdIrefdIref + dcovarIref * dcovarIref.
t()) / covarIref;
228 Hdesire = (sIcd2Iref - sdIrefdIref + dcovarIref * dcovarIref.
t()) / denom;
242 unsigned int iteration = 0;
247 double evolRMS_init = 0;
248 double evolRMS_prec = 0;
249 double evolRMS_delta;
252 unsigned int Nbpoint = 0;
254 Warp->computeCoeff(
p);
257 for (
unsigned int point = 0; point <
templateSize; point++) {
268 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
282 moyIref = moyIref / Nbpoint;
283 moyIc = moyIc / Nbpoint;
285 double covarIref = 0, covarIc = 0;
291 for (
unsigned int point = 0; point <
templateSize; point++) {
302 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
310 double prod = (Ic - moyIc);
311 for (
unsigned int it = 0; it <
nbParam; it++)
313 for (
unsigned int it = 0; it <
nbParam; it++)
316 covarIref += (Iref - moyIref) * (Iref - moyIref);
317 covarIc += (Ic - moyIc) * (Ic - moyIc);
318 sIcIref += (Iref - moyIref) * (Ic - moyIc);
321 covarIref = sqrt(covarIref);
322 covarIc = sqrt(covarIc);
323 double denom = covarIref * covarIc;
325 if (std::fabs(denom) <= std::numeric_limits<double>::epsilon()) {
329 double NCC = sIcIref / denom;
331 dcovarIref = sIrefdIref / covarIref;
332 G = (sIcdIref / denom - NCC * dcovarIref / covarIref);
350 if (iteration == 0) {
355 evolRMS_delta = std::fabs(
evolRMS - evolRMS_prec);
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
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.
vpMatrix inverseByLU() const
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
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 dWarp(const vpColVector &X1, const vpColVector &X2, const vpColVector &p, vpMatrix &dM)=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
void initHessienDesired(const vpImage< unsigned char > &I)
VP_EXPLICIT vpTemplateTrackerZNCCInverseCompositional(vpTemplateTrackerWarp *warp)
void trackNoPyr(const vpImage< unsigned char > &I)
void initCompInverse(const vpImage< unsigned char > &I)
vpMatrix HLMdesireInverse
void computeEvalRMS(const vpColVector &p)
unsigned int iterationMax
void initPosEvalRMS(const vpColVector &p)
vpTemplateTrackerPoint * ptTemplate
vpTemplateTrackerWarp * Warp
unsigned int templateSize