42 #include <visp3/core/vpImageFilter.h> 43 #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));
145 moyIref = moyIref / Nbpoint;
147 moyd2Iref = moyd2Iref / Nbpoint;
148 moyIc = moyIc / Nbpoint;
150 double covarIref = 0, covarIc = 0;
158 for (
unsigned int point = 0; point <
templateSize; point++) {
171 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
184 for (
unsigned int it = 0; it <
nbParam; it++) {
185 tempt[it] =
dW[0][it] * dIcx +
dW[1][it] * dIcy;
188 double prodIc = (Ic - moyIc);
190 double d_Ixx = dIxx.
getValue(i2, j2);
191 double d_Iyy = dIyy.
getValue(i2, j2);
192 double d_Ixy = dIxy.
getValue(i2, j2);
194 for (
unsigned int it = 0; it <
nbParam; it++) {
195 for (
unsigned int jt = 0; jt <
nbParam; jt++) {
196 sIcd2Iref[it][jt] += prodIc * (
dW[0][it] * (
dW[0][jt] * d_Ixx +
dW[1][jt] * d_Ixy) +
197 dW[1][it] * (
dW[0][jt] * d_Ixy +
dW[1][jt] * d_Iyy) - moyd2Iref[it][jt]);
198 sdIrefdIref[it][jt] +=
204 for (
unsigned int it = 0; it <
nbParam; it++)
207 covarIref += (Iref - moyIref) * (Iref - moyIref);
208 covarIc += (Ic - moyIc) * (Ic - moyIc);
209 sIcIref += (Iref - moyIref) * (Ic - moyIc);
214 covarIref = sqrt(covarIref);
215 covarIc = sqrt(covarIc);
217 denom = covarIref * covarIc;
219 double NCC = sIcIref / denom;
221 dcovarIref = -sIcdIref / covarIref;
224 dNCC = (sIcdIref / denom - NCC * dcovarIref / covarIref);
226 d2covarIref = -(sIcd2Iref - sdIrefdIref + dcovarIref * dcovarIref.
t()) / covarIref;
230 Hdesire = (sIcd2Iref - sdIrefdIref + dcovarIref * dcovarIref.
t()) / denom;
244 unsigned int iteration = 0;
249 double evolRMS_init = 0;
250 double evolRMS_prec = 0;
251 double evolRMS_delta;
254 unsigned int Nbpoint = 0;
256 Warp->computeCoeff(
p);
259 for (
unsigned int point = 0; point <
templateSize; point++) {
270 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
284 moyIref = moyIref / Nbpoint;
285 moyIc = moyIc / Nbpoint;
287 double covarIref = 0, covarIc = 0;
293 for (
unsigned int point = 0; point <
templateSize; point++) {
304 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
312 double prod = (Ic - moyIc);
313 for (
unsigned int it = 0; it <
nbParam; it++)
315 for (
unsigned int it = 0; it <
nbParam; it++)
318 covarIref += (Iref - moyIref) * (Iref - moyIref);
319 covarIc += (Ic - moyIc) * (Ic - moyIc);
320 sIcIref += (Iref - moyIref) * (Ic - moyIc);
323 covarIref = sqrt(covarIref);
324 covarIc = sqrt(covarIc);
325 double denom = covarIref * covarIc;
327 if (std::fabs(denom) <= std::numeric_limits<double>::epsilon()) {
330 double NCC = sIcIref / denom;
332 dcovarIref = sIrefdIref / covarIref;
333 G = (sIcdIref / denom - NCC * dcovarIref / covarIref);
350 if (iteration == 0) {
355 evolRMS_delta = std::fabs(
evolRMS - evolRMS_prec);
virtual void warpX(const int &v1, const int &u1, double &v2, double &u2, const vpColVector &p)=0
virtual void getParamInverse(const vpColVector &p, vpColVector &p_inv) const =0
Implementation of a matrix and operations on matrices.
void initCompInverse(const vpImage< unsigned char > &I)
unsigned int getWidth() 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)
void initHessienDesired(const vpImage< unsigned char > &I)
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)
unsigned int templateSize
unsigned int iterationMax
void trackNoPyr(const vpImage< unsigned char > &I)
Type getValue(unsigned int i, unsigned int j) const
vpTemplateTrackerZNCCInverseCompositional(vpTemplateTrackerWarp *warp)
virtual void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &p12) const =0
virtual void getdW0(const int &v, const int &u, const double &dv, const double &du, double *dIdW)=0
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M, bool convolve=false)
vpMatrix HLMdesireInverse
void resize(unsigned int i, bool flagNullify=true)
Implementation of column vector and the associated operations.
vpMatrix inverseByLU() const
unsigned int getHeight() const
virtual void dWarp(const vpColVector &X1, const vpColVector &X2, const vpColVector &p, vpMatrix &dM)=0
vpTemplateTrackerWarp * Warp
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)