42 #include <visp3/core/vpImageFilter.h> 43 #include <visp3/tt/vpTemplateTrackerZNCCInverseCompositional.h> 46 :
vpTemplateTrackerZNCC(warp), compoInitialised(false), evolRMS(0), x_pos(), y_pos(), threshold_RMS(1e-8),
59 for (
unsigned int point = 0; point <
templateSize; point++) {
94 Warp->computeCoeff(
p);
95 double Ic, dIcx = 0., dIcy = 0.;
109 for (
unsigned int point = 0; point <
templateSize; point++) {
122 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
134 for (
unsigned int it = 0; it <
nbParam; it++)
138 double *tempt =
new double[
nbParam];
139 for (
unsigned int it = 0; it <
nbParam; it++)
140 tempt[it] =
dW[0][it] * dIcx +
dW[1][it] * dIcy;
141 double d_Ixx = dIxx.
getValue(i2, j2);
142 double d_Iyy = dIyy.
getValue(i2, j2);
143 double d_Ixy = dIxy.
getValue(i2, j2);
145 for (
unsigned int it = 0; it <
nbParam; it++)
146 for (
unsigned int jt = 0; jt <
nbParam; jt++) {
147 moyd2Iref[it][jt] += (
dW[0][it] * (
dW[0][jt] * d_Ixx +
dW[1][jt] * d_Ixy) +
148 dW[1][it] * (
dW[0][jt] * d_Ixy +
dW[1][jt] * d_Iyy));
155 moyIref = moyIref / Nbpoint;
157 moyd2Iref = moyd2Iref / Nbpoint;
158 moyIc = moyIc / Nbpoint;
160 double covarIref = 0, covarIc = 0;
168 for (
unsigned int point = 0; point <
templateSize; point++) {
181 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
194 double *tempt =
new double[
nbParam];
195 for (
unsigned int it = 0; it <
nbParam; it++)
196 tempt[it] =
dW[0][it] * dIcx +
dW[1][it] * dIcy;
198 double prodIc = (Ic - moyIc);
200 double d_Ixx = dIxx.
getValue(i2, j2);
201 double d_Iyy = dIyy.
getValue(i2, j2);
202 double d_Ixy = dIxy.
getValue(i2, j2);
204 for (
unsigned int it = 0; it <
nbParam; it++)
205 for (
unsigned int jt = 0; jt <
nbParam; jt++) {
206 sIcd2Iref[it][jt] += prodIc * (
dW[0][it] * (
dW[0][jt] * d_Ixx +
dW[1][jt] * d_Ixy) +
207 dW[1][it] * (
dW[0][jt] * d_Ixy +
dW[1][jt] * d_Iyy) - moyd2Iref[it][jt]);
208 sdIrefdIref[it][jt] +=
214 for (
unsigned int it = 0; it <
nbParam; it++)
217 covarIref += (Iref - moyIref) * (Iref - moyIref);
218 covarIc += (Ic - moyIc) * (Ic - moyIc);
219 sIcIref += (Iref - moyIref) * (Ic - moyIc);
222 covarIref = sqrt(covarIref);
223 covarIc = sqrt(covarIc);
225 denom = covarIref * covarIc;
227 double NCC = sIcIref / denom;
230 dcovarIref = -sIcdIref / covarIref;
233 dNCC = (sIcdIref / denom - NCC * dcovarIref / covarIref);
235 d2covarIref = -(sIcd2Iref - sdIrefdIref + dcovarIref * dcovarIref.
t()) / covarIref;
239 Hdesire = (sIcd2Iref - sdIrefdIref + dcovarIref * dcovarIref.
t()) / denom;
255 unsigned int iteration = 0;
260 unsigned int Nbpoint = 0;
263 Warp->computeCoeff(
p);
266 for (
unsigned int point = 0; point <
templateSize; point++) {
277 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
291 moyIref = moyIref / Nbpoint;
292 moyIc = moyIc / Nbpoint;
294 double covarIref = 0, covarIc = 0;
300 for (
unsigned int point = 0; point <
templateSize; point++) {
311 if ((i2 >= 0) && (j2 >= 0) && (i2 < I.
getHeight() - 1) && (j2 < I.
getWidth() - 1)) {
319 double prod = (Ic - moyIc);
320 for (
unsigned int it = 0; it <
nbParam; it++)
322 for (
unsigned int it = 0; it <
nbParam; it++)
328 covarIref += (Iref - moyIref) * (Iref - moyIref);
329 covarIc += (Ic - moyIc) * (Ic - moyIc);
330 sIcIref += (Iref - moyIref) * (Ic - moyIc);
333 covarIref = sqrt(covarIref);
334 covarIc = sqrt(covarIc);
335 double denom = covarIref * covarIc;
338 if (std::fabs(denom) <= std::numeric_limits<double>::epsilon()) {
341 double NCC = sIcIref / denom;
343 dcovarIref = sIrefdIref / covarIref;
344 G = 1. * (sIcdIref / denom - NCC * dcovarIref / covarIref);
349 std::cout <<
"probleme inversion" << std::endl;
373 x_pos.resize(nb_corners);
374 y_pos.resize(nb_corners);
376 Warp->computeCoeff(
p);
381 for (
unsigned int j = 0; j < 3; j++) {
384 Warp->computeDenom(
X1, p_);
396 Warp->computeCoeff(p_);
402 for (
unsigned int j = 0; j < 3; j++) {
405 Warp->computeDenom(
X1, p_);
Implementation of a matrix and operations on matrices.
void initPosEvalRMS(const vpColVector &p)
void initCompInverse(const vpImage< unsigned char > &I)
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
void initHessienDesired(const vpImage< unsigned char > &I)
std::vector< double > x_pos
vpMatrix inverseByLU() const
static void getGradYGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIy, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
static void getGradXGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIx, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
virtual void getParamInverse(const vpColVector &ParamM, vpColVector &ParamMinv) const =0
unsigned int templateSize
unsigned int iterationMax
void trackNoPyr(const vpImage< unsigned char > &I)
virtual void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &pres) const =0
vpTemplateTrackerZNCCInverseCompositional(vpTemplateTrackerWarp *warp)
virtual void getdW0(const int &i, const int &j, const double &dy, const double &dx, double *dIdW)=0
Type getValue(double i, double j) const
vpColVector getCorner(unsigned int i) const
vpMatrix HLMdesireInverse
std::vector< double > y_pos
unsigned int getHeight() const
Implementation of column vector and the associated operations.
vpTemplateTrackerZone * zoneTracked
unsigned int getNbTriangle() const
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M, const bool convolve=false)
void getTriangle(unsigned int i, vpTemplateTrackerTriangle &T) const
void computeEvalRMS(const vpColVector &p)
vpTemplateTrackerWarp * Warp
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
unsigned int getWidth() const
virtual void dWarp(const vpColVector &X1, const vpColVector &X2, const vpColVector &ParamM, vpMatrix &dW)=0
void resize(const unsigned int i, const bool flagNullify=true)