ViSP  2.9.0
vpTemplateTracker.cpp
1 /****************************************************************************
2  *
3  * $Id: vpTemplateTracker.cpp 4635 2014-02-04 08:16:59Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Description:
34  * Template tracker.
35  *
36  * Authors:
37  * Amaury Dame
38  * Aurelien Yol
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 #include <visp/vpTemplateTracker.h>
43 #include <visp/vpTemplateTrackerBSpline.h>
44 
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_()
58 {
59  nbParam = Warp->getNbParam() ;
60  p.resize(nbParam);
61  dp.resize(nbParam);
62 
63  fgG=new double[(taillef+1)/2] ;
65 
66  fgdG=new double[(taillef+1)/2] ;
68 }
69 
70 void vpTemplateTracker::setGaussianFilterSize(unsigned int new_taill)
71 {
72  taillef=new_taill;
73  if (fgG) delete[] fgG;
74  fgG=new double[taillef] ;
76 
77  if (fgdG) delete[] fgdG;
78  fgdG=new double[taillef] ;
80 }
81 
83 {
84  // std::cout<<"\tInitialise reference..."<<std::endl;
85  zoneTracked=&zone;
86 
87  int largeur_im=(int)I.getWidth();
88  int hauteur_im=(int)I.getHeight();
89 
90  unsigned int NbPointDsZone=0;
91  double xtotal=0,ytotal=0;
92  int mod_fi,mod_fj;
93  mod_fi=mod_i;mod_fj=mod_i;
94 
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)
98  if(zone.inZone(i,j))
99  {
100  NbPointDsZone++;
101  xtotal+=j;
102  ytotal+=i;
103  }
104  //Warp->setCentre((double)xtotal/NbPointDsZone,(double)ytotal/NbPointDsZone);
105 
106  templateSize=NbPointDsZone;
109 
112 
113  //RecupÈration des donnÈes des triangles de la pyramide gaussienne
115  //vpTemplateTrackerZPoint ptZ;
116  vpImage<double> GaussI ;
117  vpImageFilter::filter(I, GaussI,fgG,taillef);
120 
121  unsigned int cpt_point=0;
123  for(int i=0;i<hauteur_im;i++)
124  {
125  //for(int j=minx_t;j<maxx_t;j++)
126  for(int j=0;j<largeur_im;j++)
127  {
128  if(i%mod_i ==0 && j%mod_j ==0)
129  if(zone.inZone(i,j))
130  {
131  pt.x=j;
132  pt.y=i;
133 
134  pt.dx=dIx[i][j];
135  pt.dy=dIy[i][j];
136 
137  if(pt.dx*pt.dx+pt.dy*pt.dy>thresholdGradient)
138  {
139  ptTemplateSelect[cpt_point]=true;
141  }
142  else
143  ptTemplateSelect[cpt_point]=false;
144  //ptTemplate_select[cpt_point]=true;
145 
146  /*if(blur)
147  pt.val=GaussI[i][j];
148  else
149  pt.val=I[i][j];*/
150  pt.val=vpTemplateTrackerBSpline::getSubPixBspline4(GaussI,i,j);
151  //ptZone_pyr[NbLevelPyramid-cpt].push_back(pt);
152 
153  ptTemplate[cpt_point]=pt;
154  cpt_point++;
155  }
156  }
157  }
158 
159  // std::cout<<"\tNb pt template apres scale:"<<cpt_point<<std::endl;
160  // std::cout<<"utilisation de "<<taille_template_select<<"/"<<cpt_point<<" = "<<100.*taille_template_select/cpt_point<<"% pour calcul derivees"<<std::endl;
161 
162  templateSize=cpt_point;
163  GaussI.destroy();
164  // std::cout<<"\tEnd of reference initialisation ..."<<std::endl;
165 }
166 
168 {
169  // vpTRACE("destruction tracker");
170  delete[] fgG;
171  delete[] fgdG;
172 
173  resetTracker();
174 }
175 
180 {
181  // reset the tracker parameters
182  p = 0;
183 
184  // vpTRACE("resetTracking");
185  if(pyrInitialised)
186  {
187  for(unsigned int i=0;i<nbLvlPyr;i++)
188  {
189  for(unsigned int point=0;point<templateSizePyr[i];point++)
190  {
191  delete[] ptTemplatePyr[i][point].dW;
192  delete[] ptTemplatePyr[i][point].HiG;
193  }
194  delete[] ptTemplatePyr[i];
195  }
196  delete[] ptTemplatePyr;
197 
198  if (ptTemplateCompoPyr) {
199  for(unsigned int i=0;i<nbLvlPyr;i++)
200  {
201  if (ptTemplateCompoPyr[i]) {
202  for(unsigned int point=0;point<templateSizePyr[i];point++) {
203  delete[] ptTemplateCompoPyr[i][point].dW;
204  }
205  delete[] ptTemplateCompoPyr[i];
206  }
207  }
208  delete[] ptTemplateCompoPyr;
209  ptTemplateCompoPyr = NULL;
210  }
211 
212  if (ptTemplateSuppPyr) {
213  for(unsigned int i=0;i<nbLvlPyr;i++)
214  {
215  if (ptTemplateSuppPyr[i]) {
216  for(unsigned int point=0;point<templateSizePyr[i];point++) {
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;
223  }
224  delete[] ptTemplateSuppPyr[i];
225  }
226  }
227  delete[] ptTemplateSuppPyr;
228  ptTemplateSuppPyr = NULL;
229  }
230 
231  for(unsigned int i=0;i<nbLvlPyr;i++)
232  delete[] ptTemplateSelectPyr[i];
233  delete[] ptTemplateSelectPyr;
234 
235  delete[] templateSizePyr;
236  delete[] HdesirePyr;
237  delete[] HLMdesirePyr;
238  delete[] HLMdesireInversePyr;
239 
240  delete[] zoneTrackedPyr;
241  delete[] pyr_IDes;
242  }
243  else
244  {
245  if(ptTemplateInit)
246  {
247  for(unsigned int point=0;point<templateSize;point++)
248  {
249  delete[] ptTemplate[point].dW;
250  delete[] ptTemplate[point].HiG;
251  }
252  delete[] ptTemplate;
253  ptTemplate = NULL;
254  ptTemplateInit = false;
255  }
256  if (ptTemplateCompo) {
257  for(unsigned int point=0;point<templateSize;point++)
258  {
259  delete[] ptTemplateCompo[point].dW;
260  }
261  delete[] ptTemplateCompo;
262  ptTemplateCompo = NULL;
263  }
264  if (ptTemplateSupp) {
265  for(unsigned int point=0;point<templateSize;point++)
266  {
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;
273  }
274  delete[] ptTemplateSupp;
275  ptTemplateSupp = NULL;
276  }
278  if (ptTemplateSelect) {
279  delete[] ptTemplateSelect; ptTemplateSelect = NULL;
280  }
281  }
282  }
283 }
284 
318 void vpTemplateTracker::display(const vpImage<unsigned char> &I, const vpColor& col, const unsigned int thickness)
319 {
320  if (I.display) { // Only if a display is associated to the image
321  vpTemplateTrackerZone zoneWarped;
322  Warp->warpZone(*zoneTracked, p, zoneWarped);
323  zoneWarped.display(I, col, thickness);
324  }
325 }
326 
360 void vpTemplateTracker::display(const vpImage<vpRGBa> &I, const vpColor& col, const unsigned int thickness)
361 {
362  if (I.display) { // Only if a display is associated to the image
363  vpTemplateTrackerZone zoneWarped;
364  Warp->warpZone(*zoneTracked, p, zoneWarped);
365  zoneWarped.display(I, col, thickness);
366  }
367 }
368 
369 void vpTemplateTracker::computeOptimalBrentGain(const vpImage<unsigned char> &I,vpColVector &tp,double tMI,vpColVector &direction,double &alpha)
370 {
371  vpColVector **ptp;
372  ptp=new vpColVector*[4];
373  vpColVector p0(nbParam);
374  p0=tp;
375 
376  //valeur necessaire si conditionnel
377  vpColVector dpt(Warp->getNbParam());
378  vpColVector adpt(Warp->getNbParam());
379 
380  vpColVector p1(nbParam);
382  {
383  if(useInverse)
384  Warp->getParamInverse(direction,dpt);
385  else
386  dpt=direction;
387  Warp->pRondp(tp,dpt,p1);
388  }
389  else
390  {
391  p1=tp+direction;
392  }
393 
394  vpColVector p2(nbParam);
396  {
397  adpt=alpha*direction;
398  if(useInverse)
399  Warp->getParamInverse(adpt,dpt);
400  else
401  dpt=adpt;
402  Warp->pRondp(tp,dpt,p2);
403  }
404  else
405  {
406  p2=tp+alpha*direction;
407  }
408  vpColVector p3(nbParam);
409  ptp[0]=&p0;
410  ptp[1]=&p1;
411  ptp[2]=&p2;
412  ptp[3]=&p3;
413 
414 
415  double *Cost=new double[4];
416  //Cost[0]=getCost(I,p0);
417  Cost[0]=tMI;
418  Cost[1]=getCost(I,p1);
419  Cost[2]=getCost(I,p2);
420 
421 
422  double *talpha=new double[4];
423  talpha[0]=0;
424  talpha[1]=1.;
425  talpha[2]=alpha;
426 
427  //for(int i=0;i<3;i++)
428  // std::cout<<"alpha["<<i<<"] = "<<talpha[i]<<" Cost["<<i<<"] = "<<Cost[i]<<std::endl;
429 
430  //Utilise trois estimï¿œes de paraboles succesive ...
431  //A changer pour rendre adaptable
432  for(unsigned int opt=0;opt<nbIterBrent;opt++)
433  {
434  //double a=talpha[0];
435  //double b=talpha[1];
436  //double c=talpha[2];
437  //double Cost0=Cost[0];
438  //double Cost1=Cost[1];
439  //double Cost2=Cost[2];
440 
441  vpMatrix A(3,3);
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.;}
443  //std::cout<<"A="<<A<<std::endl;
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;
446  //vpColVector parabol(3);parabol=A.pseudoInverse()*B;
447 
448  //si convexe
449  if(parabol[0]>0)
450  {
451  talpha[3]=-0.5*parabol[1]/parabol[0];
452  //std::cout<<"parabol = "<<parabol<<std::endl;
453  //std::cout<<"convexe talpha = "<<talpha[3]<<std::endl;
454  }
455  else//si concave
456  {
457  int tindic_x_min=0;
458  int tindic_x_max=0;
459  for(int i=1;i<3;i++)
460  {
461  if(talpha[i]<talpha[tindic_x_min])
462  tindic_x_min=i;
463  if(talpha[i]>talpha[tindic_x_max])
464  tindic_x_max=i;
465  }
466 
467  if(Cost[tindic_x_max]<Cost[tindic_x_min])
468  {
469  //talpha[3]=talpha[tindic_x_max]+1.;
470  talpha[3]=talpha[tindic_x_max]+1.;
471  /*if(talpha[tindic_x_min]>talpha[tindic_x_max])
472  talpha[3]=talpha[tindic_x_min]+1.;
473  else
474  talpha[3]=talpha[tindic_x_min]-1.;*/
475  }
476  else
477  {
478  //talpha[3]=talpha[tindic_x_min]-1.;
479  talpha[3]=talpha[tindic_x_min]-1.;
480  /*if(talpha[tindic_x_min]<talpha[tindic_x_max])
481  talpha[3]=talpha[tindic_x_max]+1.;
482  else
483  talpha[3]=talpha[tindic_x_max]-1.;*/
484  }
485  //std::cout<<"concave talpha="<<talpha[3]<<std::endl;
486  }
487  //std::cout<<"talpha="<<talpha[3]<<std::endl;
488  int indic_x_min=0;
489  int indic_x_max=0;
490  for(int i=1;i<3;i++)
491  {
492  if(talpha[i]<talpha[indic_x_min])
493  indic_x_min=i;
494  if(talpha[i]>talpha[indic_x_max])
495  indic_x_max=i;
496  }
497  //std::cout<<"talpha = "<<talpha[3]<<std::endl;
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.;
502 
503  /*if(((b-a)*(Cost1-Cost2)-(b-c)*(Cost1-Cost0))==0)
504  {Cost[3]=1000;break;}
505 
506  //calcul du gain correspondant au minimum de la parabole estimï¿œe
507  talpha[3]=b-0.5*((b-a)*(b-a)*(Cost1-Cost2)-(b-c)*(b-c)*(Cost1-Cost0))/((b-a)*(Cost1-Cost2)-(b-c)*(Cost1-Cost0));
508  int indic_x_min=0;
509  int indic_x_max=0;
510  for(int i=1;i<3;i++)
511  {
512  if(talpha[i]<talpha[indic_x_min])
513  indic_x_min=i;
514  if(talpha[i]>talpha[indic_x_max])
515  indic_x_max=i;
516  }
517  std::cout<<"talpha = "<<talpha[3]<<std::endl;
518  if(talpha[3]>talpha[indic_x_max])
519  if((talpha[3]-talpha[indic_x_max])>alpha)talpha[3]=talpha[indic_x_max]+alpha;
520  if(talpha[3]<talpha[indic_x_min])
521  if((talpha[indic_x_min]-talpha[3])>alpha)talpha[3]=talpha[indic_x_min]-alpha;*/
522 
523  //p3=tp-talpha[3]*direction;
525  {
526  adpt=talpha[3]*direction;
527  if(useInverse)
528  Warp->getParamInverse(adpt,dpt);
529  else
530  dpt=adpt;
531  Warp->pRondp(tp,dpt,p3);
532  }
533  else
534  {
535  p3=tp+talpha[3]*direction;
536  }
537 
538  Cost[3]=getCost(I,p3);
539  //std::cout<<"new cost="<<Cost[3]<<std::endl;
540 
541  int indice_f_max=0;
542  for(int i=1;i<4;i++)
543  if(Cost[i]>Cost[indice_f_max])
544  indice_f_max=i;
545  if(indice_f_max!=3)
546  {
547  *ptp[indice_f_max]=*ptp[3];
548  Cost[indice_f_max]=Cost[3];
549  talpha[indice_f_max]=talpha[3];
550  }
551  else
552  break;
553  }
554 
555  int indice_f_min=0;
556  for(int i=0;i<4;i++)
557  if(Cost[i]<Cost[indice_f_min])
558  indice_f_min=i;
559 
560  alpha=talpha[indice_f_min];
561 
562  if(alpha<1)alpha=1.;
563 
564  delete[] ptp;
565  delete[] Cost;
566  delete[] talpha;
567 }
568 
569 
574 void vpTemplateTracker::initPyramidal(unsigned int nbLvl, unsigned int l0)
575 {
576  // vpTRACE("init_pyramidal");
577  nbLvlPyr=nbLvl;
578  l0Pyr=l0;
579 
583  ptTemplateSelectPyr=new bool*[nbLvlPyr];
584  ptTemplateSuppPyr=new vpTemplateTrackerPointSuppMIInv*[nbLvlPyr];
586  for(unsigned int i=0; i< nbLvlPyr; i++) {
587  ptTemplatePyr[i] = NULL;
588  ptTemplateSuppPyr[i] = NULL;
589  ptTemplateSelectPyr[i] = NULL;
590  ptTemplateCompoPyr[i] = NULL;
591  }
592  templateSizePyr=new unsigned int[nbLvlPyr];
596 
597  pyrInitialised=true;
598  // vpTRACE("fin init_pyramidal");
599 
600 }
602 {
603  // vpTRACE("initTrackingPyr");
604  zoneTrackedPyr[0].copy(zone);
605  //vpTRACE("fin copy zone");
606 
607  pyr_IDes[0]=I;
612 
613  //creationpyramide de zones et images desiree
614  if(nbLvlPyr>1)
615  {
616  for(unsigned int i=1;i<nbLvlPyr;i++)
617  {
620 
625  //reste probleme avec le Hessien
626  }
627  }
628  /*for(int i=0;i<nbLvlPyr;i++)
629  {
630  vpColVector ptemp(8);ptemp=0;
631  zoneTracked=&zoneTrackedPyr[i];
632  init_pos_evalRMS(ptemp);
633  }*/
635 
636 
637  // vpTRACE("fin initTrackingPyr");
638 
639 }
640 
660 {
661  zoneRef_.initClick(I, delaunay);
662 
663  if (nbLvlPyr > 1) {
667  }
668  else {
671 // trackNoPyr(I);
672  }
673 }
674 
685 void vpTemplateTracker::initFromPoints(const vpImage<unsigned char> &I, const std::vector< vpImagePoint > &v_ip, bool delaunay)
686 {
687  zoneRef_.initFromPoints(I, v_ip, delaunay);
688 
689  if (nbLvlPyr > 1) {
693  }
694  else {
697  //trackNoPyr(I);
698  }
699 }
700 
708 {
709  zoneRef_ = zone;
710 
711  if (nbLvlPyr > 1) {
715  }
716  else {
719 // trackNoPyr(I);
720  }
721 }
722 
724 {
725  vpTRACE("initCompInversePyr");
727  //ptTemplateSupp=ptTemplateSuppPyr[0];
728  //ptTemplateCompo=ptTemplateCompoPyr[0];
732  ptTemplateSuppPyr[0]=ptTemplateSupp;
734 
735 
736  if(nbLvlPyr>1)
737  {
738  vpImage<unsigned char> Itemp=I;
739  for(unsigned int i=1;i<nbLvlPyr;i++)
740  {
742 
746  initCompInversePyr(Itemp);
747  ptTemplateSuppPyr[i]=ptTemplateSupp;
749  }
750  }
751  // vpTRACE("fin initCompInversePyr");
752 
753 }
755 {
756  // vpTRACE("initHessienDesiredPyr");
758  //ptTemplateSupp=ptTemplateSuppPyr[0];
759  //ptTemplateCompo=ptTemplateCompoPyr[0];
763  ptTemplateSuppPyr[0]=ptTemplateSupp;
764 
766  //HdesirePyr[0].resize(NbParam,NbParam);
767  //HLMdesirePyr[0].resize(NbParam,NbParam);
768  HdesirePyr[0]=Hdesire;
771 
772  if(nbLvlPyr>1)
773  {
774  vpImage<unsigned char> Itemp;Itemp=I;
775  for(unsigned int i=1;i<nbLvlPyr;i++)
776  {
778 
782  //ptTemplateSupp=ptTemplateSuppPyr[i];
783  //ptTemplateCompo=ptTemplateCompoPyr[i];
784  initHessienDesired(Itemp);
785  ptTemplateSuppPyr[i]=ptTemplateSupp;
787 
788  /*HdesirePyr[i].resize(NbParam,NbParam);HdesirePyr[i]=H;
789  HLMdesirePyr[i].resize(NbParam,NbParam);HLMdesirePyr[i]=HLM;*/
790  HdesirePyr[i]=Hdesire;
793  }
794  }
795  // vpTRACE("fin initHessienDesiredPyr");
796 }
797 
803 {
804  if (nbLvlPyr > 1)
805  trackPyr(I);
806  else
807  trackNoPyr(I);
808 }
809 
811 {
812  //vpTRACE("trackPyr");
813  vpImage<unsigned char> *pyr_I;
814 // pyr_I=new vpImage<unsigned char>[nbLvlPyr+1]; // Why +1 ?
815  pyr_I=new vpImage<unsigned char>[nbLvlPyr]; // Why +1 ?
816  pyr_I[0]=I;
817 
818  vpColVector ptemp(nbParam);
819  if(nbLvlPyr>1)
820  {
821 // vpColVector *p_sauv=new vpColVector[nbLvlPyr];
822 // for(unsigned int i=0;i<nbLvlPyr;i++)p_sauv[i].resize(nbParam);
823 
824 // p_sauv[0]=p;
825  for(unsigned int i=1;i<nbLvlPyr;i++)
826  {
827  vpImageFilter::getGaussPyramidal(pyr_I[i-1],pyr_I[i]);
828  //test getParamPyramidDown
829  /*vpColVector vX_test(2);vX_test[0]=15.;vX_test[1]=30.;
830  vpColVector vX_test2(2);
831  Warp->computeCoeff(p);
832  Warp->computeDenom(vX_test,p);
833  Warp->warpX(vX_test,vX_test2,p);
834  std::cout<<"p = "<<p.t()<<std::endl;*/
835  //std::cout<<"get p down"<<std::endl;
836  Warp->getParamPyramidDown(p,ptemp);
837  p=ptemp;
839 
840 // p_sauv[i]=p;
841  /*std::cout<<"p_down = "<<p.t()<<std::endl;
842 
843  vpColVector vX_testd(2);vX_testd[0]=15./2.;vX_testd[1]=30./2.;
844  vpColVector vX_testd2(2);
845  Warp->computeCoeff(p);
846  Warp->computeDenom(vX_testd,p);
847  Warp->warpX(vX_testd,vX_testd2,p);
848  std::cout<<2.*vX_testd2[0]<<","<<2.*vX_testd2[1]<<" <=> "<<vX_test2[0]<<","<<vX_test2[1]<<std::endl;*/
849 
850  }
851 
852  for(int i=(int)nbLvlPyr-1;i>=0;i--)
853  {
854  if(i>=(int)l0Pyr)
855  {
859  ptTemplateSupp=ptTemplateSuppPyr[i];
861  H=HdesirePyr[i];
862  HLM=HLMdesirePyr[i];
864 // zoneTracked=&zoneTrackedPyr[i];
865  trackRobust(pyr_I[i]);
866  }
867  //std::cout<<"get p up"<<std::endl;
868 // ptemp=p_sauv[i-1];
869  if (i > 0) {
870  Warp->getParamPyramidUp(p,ptemp);
871  p=ptemp;
873  }
874  }
875 #if 0
876  if(l0Pyr==0)
877  {
881  ptTemplateSupp=ptTemplateSuppPyr[0];
883  H=HdesirePyr[0];
884  HLM=HLMdesirePyr[0];
887  trackRobust(pyr_I[0]);
888  }
889 
890  if (l0Pyr > 0) {
891 // for (int l=(int)l0Pyr; l >=0; l--) {
892 // Warp->getParamPyramidUp(p,ptemp);
893 // p=ptemp;
894 // }
896  }
897 #endif
898  // delete [] p_sauv;
899  }
900  else
901  {
902  //std::cout<<"reviens a tracker de base"<<std::endl;
903  trackRobust(I);
904  }
905  delete[] pyr_I;
906 }
907 
909 {
911  {
912  vpColVector p_pre_estimation;p_pre_estimation=p;
914  double pre_fcost=getCost(I,p);
915 
916  trackNoPyr(I);
917 
918  //std::cout<<"fct avant : "<<pre_fcost<<std::endl;
919  double post_fcost=getCost(I,p);
920  //std::cout<<"fct apres : "<<post_fcost<<std::endl<<std::endl;
921  if(pre_fcost<post_fcost)
922  p=p_pre_estimation;
923  }
924  else
925  trackNoPyr(I);
926 
927 }
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
vpDisplay * display
Definition: vpImage.h:121
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Definition: vpMatrix.cpp:183
virtual void getParamPyramidDown(const vpColVector &p, vpColVector &pdown)=0
virtual void trackPyr(const vpImage< unsigned char > &I)
unsigned int templateSelectSize
unsigned int getWidth() const
Definition: vpImage.h:159
void getGaussianBluredImage(const vpImage< unsigned char > &I)
vpTemplateTrackerPoint * ptTemplate
vpTemplateTrackerPoint ** ptTemplatePyr
#define vpTRACE
Definition: vpDebug.h:418
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
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 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_
vpImage< double > dIx
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)
vpImage< double > dIy
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 destroy()
destructor
Definition: vpImage.h:553
void initFromPoints(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &v_ip, bool delaunay=false)
unsigned int * templateSizePyr
unsigned int nbLvlPyr
virtual void initPyramidal(unsigned int nbLvl, unsigned int l0)
bool inZone(const int &i, const int &j) const
vpTemplateTracker(vpTemplateTrackerWarp *_warp)
vpMatrix t() const
Definition: vpMatrix.cpp:1225
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...
Definition: vpColVector.h:72
void track(const vpImage< unsigned char > &I)
virtual void trackNoPyr(const vpImage< unsigned char > &I)=0
vpTemplateTrackerZone * zoneTracked
unsigned int getHeight() const
Definition: vpImage.h:150
void trackRobust(const vpImage< unsigned char > &I)
vpImage< unsigned char > * pyr_IDes
vpTemplateTrackerWarp * Warp
unsigned int nbIterBrent
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)
Definition: vpColVector.h:94
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, const unsigned int thickness=3)