42 #include <visp/vpTemplateTracker.h>
43 #include <visp/vpTemplateTrackerBSpline.h>
46 : nbLvlPyr(1), l0Pyr(0), pyrInitialised(false), ptTemplate(NULL), ptTemplatePyr(NULL),
47 ptTemplateInit(false), templateSize(0), templateSizePyr(NULL),
48 ptTemplateSelect(NULL), ptTemplateSelectPyr(NULL), ptTemplateSelectInit(NULL),
49 templateSelectSize(0), ptTemplateSupp(NULL), ptTemplateSuppPyr(NULL),
50 ptTemplateCompo(NULL), ptTemplateCompoPyr(NULL), zoneTracked(NULL), zoneTrackedPyr(NULL),
51 pyr_IDes(NULL), H(), Hdesire(), HdesirePyr(), HLM(), HLMdesire(), HLMdesirePyr(),
52 HLMdesireInverse(), HLMdesireInversePyr(), G(), gain(1.), thresholdGradient(40),
53 costFunctionVerification(false), blur(true), useBrent(false), nbIterBrent(3),
54 taillef(7), fgG(NULL), fgdG(NULL), ratioPixelIn(0), mod_i(1), mod_j(1), nbParam(0),
55 lambdaDep(0.001), iterationMax(30), iterationGlobale(0), diverge(false), nbIteration(0),
56 useCompositionnal(true), useInverse(false), Warp(_warp), p(0), dp(), X1(), X2(),
57 dW(), BI(), dIx(), dIy(), zoneRef_()
90 unsigned int NbPointDsZone=0;
91 double xtotal=0,ytotal=0;
95 for(
int j=0;j<largeur_im;j++)
96 for(
int i=0;i<hauteur_im;i++)
97 if(i%mod_fi ==0 && j%mod_fj ==0)
121 unsigned int cpt_point=0;
123 for(
int i=0;i<hauteur_im;i++)
126 for(
int j=0;j<largeur_im;j++)
150 pt.
val=vpTemplateTrackerBSpline::getSubPixBspline4(GaussI,i,j);
187 for(
unsigned int i=0;i<
nbLvlPyr;i++)
199 for(
unsigned int i=0;i<
nbLvlPyr;i++)
212 if (ptTemplateSuppPyr) {
213 for(
unsigned int i=0;i<
nbLvlPyr;i++)
215 if (ptTemplateSuppPyr[i]) {
217 delete[] ptTemplateSuppPyr[i][point].Bt;
218 delete[] ptTemplateSuppPyr[i][point].BtInit;
219 delete[] ptTemplateSuppPyr[i][point].dBt;
220 delete[] ptTemplateSuppPyr[i][point].d2W;
221 delete[] ptTemplateSuppPyr[i][point].d2Wx;
222 delete[] ptTemplateSuppPyr[i][point].d2Wy;
224 delete[] ptTemplateSuppPyr[i];
227 delete[] ptTemplateSuppPyr;
228 ptTemplateSuppPyr = NULL;
231 for(
unsigned int i=0;i<
nbLvlPyr;i++)
264 if (ptTemplateSupp) {
267 delete[] ptTemplateSupp[point].Bt;
268 delete[] ptTemplateSupp[point].BtInit;
269 delete[] ptTemplateSupp[point].dBt;
270 delete[] ptTemplateSupp[point].d2W;
271 delete[] ptTemplateSupp[point].d2Wx;
272 delete[] ptTemplateSupp[point].d2Wy;
274 delete[] ptTemplateSupp;
275 ptTemplateSupp = NULL;
323 zoneWarped.
display(I, col, thickness);
365 zoneWarped.
display(I, col, thickness);
397 adpt=alpha*direction;
406 p2=tp+alpha*direction;
415 double *Cost=
new double[4];
422 double *talpha=
new double[4];
442 for(
unsigned int i=0;i<3;i++){A[i][0]=talpha[i]*talpha[i];A[i][1]=talpha[i];A[i][2]=1.;}
444 vpColVector B(3);
for(
unsigned int i=0;i<3;i++)B[i]=Cost[i];
445 vpColVector parabol(3);parabol=(A.
t()*A).inverseByLU()*A.
t()*B;
451 talpha[3]=-0.5*parabol[1]/parabol[0];
461 if(talpha[i]<talpha[tindic_x_min])
463 if(talpha[i]>talpha[tindic_x_max])
467 if(Cost[tindic_x_max]<Cost[tindic_x_min])
470 talpha[3]=talpha[tindic_x_max]+1.;
479 talpha[3]=talpha[tindic_x_min]-1.;
492 if(talpha[i]<talpha[indic_x_min])
494 if(talpha[i]>talpha[indic_x_max])
498 if(talpha[3]>talpha[indic_x_max])
499 if((talpha[3]-talpha[indic_x_max])>alpha)talpha[3]=talpha[indic_x_max]+4.;
500 if(talpha[3]<talpha[indic_x_min])
501 if((talpha[indic_x_min]-talpha[3])>alpha)talpha[3]=talpha[indic_x_min]-4.;
526 adpt=talpha[3]*direction;
535 p3=tp+talpha[3]*direction;
543 if(Cost[i]>Cost[indice_f_max])
547 *ptp[indice_f_max]=*ptp[3];
548 Cost[indice_f_max]=Cost[3];
549 talpha[indice_f_max]=talpha[3];
557 if(Cost[i]<Cost[indice_f_min])
560 alpha=talpha[indice_f_min];
584 ptTemplateSuppPyr=
new vpTemplateTrackerPointSuppMIInv*[
nbLvlPyr];
586 for(
unsigned int i=0; i<
nbLvlPyr; i++) {
588 ptTemplateSuppPyr[i] = NULL;
616 for(
unsigned int i=1;i<
nbLvlPyr;i++)
732 ptTemplateSuppPyr[0]=ptTemplateSupp;
739 for(
unsigned int i=1;i<
nbLvlPyr;i++)
747 ptTemplateSuppPyr[i]=ptTemplateSupp;
763 ptTemplateSuppPyr[0]=ptTemplateSupp;
775 for(
unsigned int i=1;i<
nbLvlPyr;i++)
785 ptTemplateSuppPyr[i]=ptTemplateSupp;
825 for(
unsigned int i=1;i<
nbLvlPyr;i++)
852 for(
int i=(
int)nbLvlPyr-1;i>=0;i--)
859 ptTemplateSupp=ptTemplateSuppPyr[i];
881 ptTemplateSupp=ptTemplateSuppPyr[0];
921 if(pre_fcost<post_fcost)
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
bool ptTemplateSelectInit
Definition of the vpMatrix class.
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
virtual void getParamPyramidDown(const vpColVector &p, vpColVector &pdown)=0
virtual void trackPyr(const vpImage< unsigned char > &I)
bool costFunctionVerification
unsigned int templateSelectSize
unsigned int getWidth() const
void getGaussianBluredImage(const vpImage< unsigned char > &I)
vpTemplateTrackerPoint * ptTemplate
vpTemplateTrackerPoint ** ptTemplatePyr
Class to define colors available for display functionnalities.
static void getGaussianKernel(double *filter, unsigned int size, double sigma=0., bool normalize=true)
virtual void initTrackingPyr(const vpImage< unsigned char > &I, vpTemplateTrackerZone &zone)
void computeOptimalBrentGain(const vpImage< unsigned char > &I, vpColVector &tp, double tMI, vpColVector &direction, double &alpha)
void initClick(const vpImage< unsigned char > &I, bool delaunay=false)
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, const unsigned int thickness=3)
static void getGradYGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIy, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
vpMatrix * HLMdesireInversePyr
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
void copy(const vpTemplateTrackerZone &z)
unsigned int templateSize
virtual void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &pres) const =0
void initTracking(const vpImage< unsigned char > &I, vpTemplateTrackerZone &zone)
vpTemplateTrackerZone * zoneTrackedPyr
virtual ~vpTemplateTracker()
virtual void initHessienDesired(const vpImage< unsigned char > &I)=0
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M)
vpTemplateTrackerZone zoneRef_
void setGaussianFilterSize(unsigned int new_taill)
void initFromZone(const vpImage< unsigned char > &I, const vpTemplateTrackerZone &zone)
virtual void initHessienDesiredPyr(const vpImage< unsigned char > &I)
void initClick(const vpImage< unsigned char > &I, bool delaunay=false)
virtual void getParamPyramidUp(const vpColVector &p, vpColVector &pup)=0
unsigned int getNbParam() const
void initFromPoints(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &ip, bool delaunay=false)
void initFromPoints(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &v_ip, bool delaunay=false)
unsigned int * templateSizePyr
vpMatrix HLMdesireInverse
virtual void initPyramidal(unsigned int nbLvl, unsigned int l0)
bool inZone(const int &i, const int &j) const
vpTemplateTracker(vpTemplateTrackerWarp *_warp)
vpTemplateTrackerZone getPyramidDown() const
void warpZone(const vpTemplateTrackerZone &in, const vpColVector &p, vpTemplateTrackerZone &out)
static void getGaussianDerivativeKernel(double *filter, unsigned int size, double sigma=0., bool normalize=true)
vpTemplateTrackerPointCompo * ptTemplateCompo
Class that provides a data structure for the column vectors as well as a set of operations on these v...
void track(const vpImage< unsigned char > &I)
virtual void trackNoPyr(const vpImage< unsigned char > &I)=0
vpTemplateTrackerZone * zoneTracked
bool ** ptTemplateSelectPyr
unsigned int getHeight() const
void trackRobust(const vpImage< unsigned char > &I)
vpImage< unsigned char > * pyr_IDes
vpTemplateTrackerWarp * Warp
virtual void initCompInversePyr(const vpImage< unsigned char > &I)
vpTemplateTrackerPointCompo ** ptTemplateCompoPyr
virtual double getCost(const vpImage< unsigned char > &I, vpColVector &tp)=0
void resize(const unsigned int i, const bool flagNullify=true)
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, const unsigned int thickness=3)