40 #include <visp3/tt/vpTemplateTracker.h>
41 #include <visp3/tt/vpTemplateTrackerBSpline.h>
44 : nbLvlPyr(1), l0Pyr(0), pyrInitialised(false), ptTemplate(NULL), ptTemplatePyr(NULL),
45 ptTemplateInit(false), templateSize(0), templateSizePyr(NULL),
46 ptTemplateSelect(NULL), ptTemplateSelectPyr(NULL), ptTemplateSelectInit(false),
47 templateSelectSize(0), ptTemplateSupp(NULL), ptTemplateSuppPyr(NULL),
48 ptTemplateCompo(NULL), ptTemplateCompoPyr(NULL), zoneTracked(NULL), zoneTrackedPyr(NULL),
49 pyr_IDes(NULL), H(), Hdesire(), HdesirePyr(), HLM(), HLMdesire(), HLMdesirePyr(),
50 HLMdesireInverse(), HLMdesireInversePyr(), G(), gain(1.), thresholdGradient(40),
51 costFunctionVerification(false), blur(true), useBrent(false), nbIterBrent(3),
52 taillef(7), fgG(NULL), fgdG(NULL), ratioPixelIn(0), mod_i(1), mod_j(1), nbParam(0),
53 lambdaDep(0.001), iterationMax(30), iterationGlobale(0), diverge(false), nbIteration(0),
54 useCompositionnal(true), useInverse(false), Warp(_warp), p(0), dp(), X1(), X2(),
55 dW(), BI(), dIx(), dIy(), zoneRef_()
88 unsigned int NbPointDsZone=0;
93 for(
int i=0;i<hauteur_im;i+=mod_fi) {
94 for(
int j=0;j<largeur_im;j+=mod_fj) {
119 unsigned int cpt_point=0;
121 for(
int i=0;i<hauteur_im;i+=
mod_i)
124 for(
int j=0;j<largeur_im;j+=
mod_j)
148 pt.
val=vpTemplateTrackerBSpline::getSubPixBspline4(GaussI,i,j);
186 for(
unsigned int i=0;i<
nbLvlPyr;i++)
202 for(
unsigned int i=0;i<
nbLvlPyr;i++)
215 if (ptTemplateSuppPyr) {
216 for(
unsigned int i=0;i<
nbLvlPyr;i++)
218 if (ptTemplateSuppPyr[i]) {
220 delete[] ptTemplateSuppPyr[i][point].Bt;
221 delete[] ptTemplateSuppPyr[i][point].BtInit;
222 delete[] ptTemplateSuppPyr[i][point].dBt;
223 delete[] ptTemplateSuppPyr[i][point].d2W;
224 delete[] ptTemplateSuppPyr[i][point].d2Wx;
225 delete[] ptTemplateSuppPyr[i][point].d2Wy;
227 delete[] ptTemplateSuppPyr[i];
230 delete[] ptTemplateSuppPyr;
231 ptTemplateSuppPyr = NULL;
235 for(
unsigned int i=0;i<
nbLvlPyr;i++){
294 if (ptTemplateSupp) {
297 delete[] ptTemplateSupp[point].Bt;
298 delete[] ptTemplateSupp[point].BtInit;
299 delete[] ptTemplateSupp[point].dBt;
300 delete[] ptTemplateSupp[point].d2W;
301 delete[] ptTemplateSupp[point].d2Wx;
302 delete[] ptTemplateSupp[point].d2Wy;
304 delete[] ptTemplateSupp;
305 ptTemplateSupp = NULL;
353 zoneWarped.
display(I, col, thickness);
395 zoneWarped.
display(I, col, thickness);
427 adpt=alpha*direction;
436 p2=tp+alpha*direction;
445 double *Cost=
new double[4];
452 double *talpha=
new double[4];
472 for(
unsigned int i=0;i<3;i++){A[i][0]=talpha[i]*talpha[i];A[i][1]=talpha[i];A[i][2]=1.;}
474 vpColVector B(3);
for(
unsigned int i=0;i<3;i++)B[i]=Cost[i];
475 vpColVector parabol(3);parabol=(A.
t()*A).inverseByLU()*A.
t()*B;
481 talpha[3]=-0.5*parabol[1]/parabol[0];
491 if(talpha[i]<talpha[tindic_x_min])
493 if(talpha[i]>talpha[tindic_x_max])
497 if(Cost[tindic_x_max]<Cost[tindic_x_min])
500 talpha[3]=talpha[tindic_x_max]+1.;
509 talpha[3]=talpha[tindic_x_min]-1.;
522 if(talpha[i]<talpha[indic_x_min])
524 if(talpha[i]>talpha[indic_x_max])
528 if(talpha[3]>talpha[indic_x_max])
529 if((talpha[3]-talpha[indic_x_max])>alpha)talpha[3]=talpha[indic_x_max]+4.;
530 if(talpha[3]<talpha[indic_x_min])
531 if((talpha[indic_x_min]-talpha[3])>alpha)talpha[3]=talpha[indic_x_min]-4.;
556 adpt=talpha[3]*direction;
565 p3=tp+talpha[3]*direction;
573 if(Cost[i]>Cost[indice_f_max])
577 *ptp[indice_f_max]=*ptp[3];
578 Cost[indice_f_max]=Cost[3];
579 talpha[indice_f_max]=talpha[3];
587 if(Cost[i]<Cost[indice_f_min])
590 alpha=talpha[indice_f_min];
614 ptTemplateSuppPyr=
new vpTemplateTrackerPointSuppMIInv*[
nbLvlPyr];
616 for(
unsigned int i=0; i<
nbLvlPyr; i++) {
618 ptTemplateSuppPyr[i] = NULL;
646 for(
unsigned int i=1;i<
nbLvlPyr;i++)
764 ptTemplateSuppPyr[0]=ptTemplateSupp;
771 ptTemplateSuppPyr[0]=ptTemplateSupp;
782 for(
unsigned int i=1;i<
nbLvlPyr;i++)
793 ptTemplateSuppPyr[i]=ptTemplateSupp;
800 ptTemplateSuppPyr[i]=ptTemplateSupp;
841 for(
unsigned int i=1;i<
nbLvlPyr;i++)
868 for(
int i=(
int)nbLvlPyr-1;i>=0;i--)
875 ptTemplateSupp=ptTemplateSuppPyr[i];
897 ptTemplateSupp=ptTemplateSuppPyr[0];
942 if(pre_fcost<post_fcost)
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
bool ptTemplateSelectInit
Implementation of a matrix and operations on matrices.
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 resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
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)
error that can be emited by ViSP classes.
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
vpTemplateTracker()
Default constructor.
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)
Error that can be emited by the vpTracker class and its derivates.
vpTemplateTrackerZone * zoneTrackedPyr
virtual ~vpTemplateTracker()
virtual void initHessienDesired(const vpImage< unsigned char > &I)=0
vpTemplateTrackerZone zoneRef_
void setGaussianFilterSize(unsigned int new_taill)
void initFromZone(const vpImage< unsigned char > &I, const vpTemplateTrackerZone &zone)
virtual double getCost(const vpImage< unsigned char > &I, const vpColVector &tp)=0
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
const char * getMessage(void) const
unsigned int getNbParam() const
void initFromPoints(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &ip, bool delaunay=false)
void destroy()
Destructor : Memory de-allocation.
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
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
Implementation of column vector and the associated operations.
void track(const vpImage< unsigned char > &I)
virtual void trackNoPyr(const vpImage< unsigned char > &I)=0
vpTemplateTrackerZone * zoneTracked
bool ** ptTemplateSelectPyr
unsigned int getHeight() const
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M, const bool convolve=false)
void trackRobust(const vpImage< unsigned char > &I)
vpImage< unsigned char > * pyr_IDes
vpTemplateTrackerWarp * Warp
vpTemplateTrackerPointCompo ** ptTemplateCompoPyr
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)