ViSP  2.10.0
vpTemplateTracker.cpp
1 /****************************************************************************
2  *
3  * $Id: vpTemplateTracker.cpp 5062 2014-12-15 13:43:33Z 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 
43 #include <visp/vpTemplateTracker.h>
44 #include <visp/vpTemplateTrackerBSpline.h>
45 
47  : nbLvlPyr(1), l0Pyr(0), pyrInitialised(false), ptTemplate(NULL), ptTemplatePyr(NULL),
48  ptTemplateInit(false), templateSize(0), templateSizePyr(NULL),
49  ptTemplateSelect(NULL), ptTemplateSelectPyr(NULL), ptTemplateSelectInit(false),
50  templateSelectSize(0), ptTemplateSupp(NULL), ptTemplateSuppPyr(NULL),
51  ptTemplateCompo(NULL), ptTemplateCompoPyr(NULL), zoneTracked(NULL), zoneTrackedPyr(NULL),
52  pyr_IDes(NULL), H(), Hdesire(), HdesirePyr(), HLM(), HLMdesire(), HLMdesirePyr(),
53  HLMdesireInverse(), HLMdesireInversePyr(), G(), gain(1.), thresholdGradient(40),
54  costFunctionVerification(false), blur(true), useBrent(false), nbIterBrent(3),
55  taillef(7), fgG(NULL), fgdG(NULL), ratioPixelIn(0), mod_i(1), mod_j(1), nbParam(0),
56  lambdaDep(0.001), iterationMax(30), iterationGlobale(0), diverge(false), nbIteration(0),
57  useCompositionnal(true), useInverse(false), Warp(_warp), p(0), dp(), X1(), X2(),
58  dW(), BI(), dIx(), dIy(), zoneRef_()
59 {
60  nbParam = Warp->getNbParam() ;
61  p.resize(nbParam);
62  dp.resize(nbParam);
63 
64  fgG=new double[(taillef+1)/2] ;
66 
67  fgdG=new double[(taillef+1)/2] ;
69 }
70 
71 void vpTemplateTracker::setGaussianFilterSize(unsigned int new_taill)
72 {
73  taillef=new_taill;
74  if (fgG) delete[] fgG;
75  fgG=new double[taillef] ;
77 
78  if (fgdG) delete[] fgdG;
79  fgdG=new double[taillef] ;
81 }
82 
84 {
85  // std::cout<<"\tInitialise reference..."<<std::endl;
86  zoneTracked=&zone;
87 
88  int largeur_im=(int)I.getWidth();
89  int hauteur_im=(int)I.getHeight();
90 
91  unsigned int NbPointDsZone=0;
92  //double xtotal=0,ytotal=0;
93  int mod_fi,mod_fj;
94  mod_fi=mod_i;mod_fj=mod_i;
95 
96  for(int i=0;i<hauteur_im;i+=mod_fi) {
97  for(int j=0;j<largeur_im;j+=mod_fj) {
98  if(zone.inZone(i,j)) {
99  NbPointDsZone++;
100  //xtotal+=j;
101  //ytotal+=i;
102  }
103  }
104  }
105 
106  //Warp->setCentre((double)xtotal/NbPointDsZone,(double)ytotal/NbPointDsZone);
107 
108  templateSize=NbPointDsZone;
111 
114 
116  //vpTemplateTrackerZPoint ptZ;
117  vpImage<double> GaussI ;
118  vpImageFilter::filter(I, GaussI,fgG,taillef);
121 
122  unsigned int cpt_point=0;
124  for(int i=0;i<hauteur_im;i+=mod_i)
125  {
126  //for(int j=minx_t;j<maxx_t;j++)
127  for(int j=0;j<largeur_im;j+=mod_j)
128  {
129 // if(i%mod_i ==0 && j%mod_j ==0)
130  if(zone.inZone(i,j))
131  {
132  pt.x=j;
133  pt.y=i;
134 
135  pt.dx=dIx[i][j];
136  pt.dy=dIy[i][j];
137 
138  if(pt.dx*pt.dx+pt.dy*pt.dy>thresholdGradient)
139  {
140  ptTemplateSelect[cpt_point]=true;
142  }
143  else
144  ptTemplateSelect[cpt_point]=false;
145  //ptTemplate_select[cpt_point]=true;
146 
147  /*if(blur)
148  pt.val=GaussI[i][j];
149  else
150  pt.val=I[i][j];*/
151  pt.val=vpTemplateTrackerBSpline::getSubPixBspline4(GaussI,i,j);
152  //ptZone_pyr[NbLevelPyramid-cpt].push_back(pt);
153 
154  ptTemplate[cpt_point]=pt;
155  cpt_point++;
156  }
157  }
158  }
159 
160  // std::cout<<"\tNb pt template apres scale:"<<cpt_point<<std::endl;
161  // std::cout<<"utilisation de "<<taille_template_select<<"/"<<cpt_point<<" = "<<100.*taille_template_select/cpt_point<<"% pour calcul derivees"<<std::endl;
162 
163  templateSize=cpt_point;
164  GaussI.destroy();
165  // std::cout<<"\tEnd of reference initialisation ..."<<std::endl;
166 }
167 
169 {
170  // vpTRACE("destruction tracker");
171  delete[] fgG;
172  delete[] fgdG;
173 
174  resetTracker();
175 }
176 
181 {
182  // reset the tracker parameters
183  p = 0;
184 
185  // vpTRACE("resetTracking");
186  if(pyrInitialised)
187  {
188  if(ptTemplatePyr){
189  for(unsigned int i=0;i<nbLvlPyr;i++)
190  {
191  if(ptTemplatePyr[i]){
192  for(unsigned int point=0;point<templateSizePyr[i];point++)
193  {
194  delete[] ptTemplatePyr[i][point].dW;
195  delete[] ptTemplatePyr[i][point].HiG;
196  }
197  delete[] ptTemplatePyr[i];
198  }
199  }
200  delete[] ptTemplatePyr;
201  ptTemplatePyr = NULL;
202  }
203 
204  if (ptTemplateCompoPyr) {
205  for(unsigned int i=0;i<nbLvlPyr;i++)
206  {
207  if (ptTemplateCompoPyr[i]) {
208  for(unsigned int point=0;point<templateSizePyr[i];point++) {
209  delete[] ptTemplateCompoPyr[i][point].dW;
210  }
211  delete[] ptTemplateCompoPyr[i];
212  }
213  }
214  delete[] ptTemplateCompoPyr;
215  ptTemplateCompoPyr = NULL;
216  }
217 
218  if (ptTemplateSuppPyr) {
219  for(unsigned int i=0;i<nbLvlPyr;i++)
220  {
221  if (ptTemplateSuppPyr[i]) {
222  for(unsigned int point=0;point<templateSizePyr[i];point++) {
223  delete[] ptTemplateSuppPyr[i][point].Bt;
224  delete[] ptTemplateSuppPyr[i][point].BtInit;
225  delete[] ptTemplateSuppPyr[i][point].dBt;
226  delete[] ptTemplateSuppPyr[i][point].d2W;
227  delete[] ptTemplateSuppPyr[i][point].d2Wx;
228  delete[] ptTemplateSuppPyr[i][point].d2Wy;
229  }
230  delete[] ptTemplateSuppPyr[i];
231  }
232  }
233  delete[] ptTemplateSuppPyr;
234  ptTemplateSuppPyr = NULL;
235  }
236 
238  for(unsigned int i=0;i<nbLvlPyr;i++){
239  if(ptTemplateSelectPyr[i])
240  delete[] ptTemplateSelectPyr[i];
241  }
242  delete[] ptTemplateSelectPyr;
243  ptTemplateSelectPyr = NULL;
244  }
245 
246  if(templateSizePyr){
247  delete[] templateSizePyr;
248  templateSizePyr = NULL;
249  }
250 
251  if(HdesirePyr) {
252  delete[] HdesirePyr;
253  HdesirePyr = NULL;
254  }
255 
256  if(HLMdesirePyr){
257  delete[] HLMdesirePyr;
258  HLMdesirePyr = NULL;
259  }
260 
262  delete[] HLMdesireInversePyr;
263  HLMdesireInversePyr = NULL;
264  }
265 
266  if(zoneTrackedPyr){
267  delete[] zoneTrackedPyr;
268  zoneTrackedPyr = NULL;
269  }
270 
271  if(pyr_IDes){
272  delete[] pyr_IDes;
273  pyr_IDes = NULL;
274  }
275  }
276  else
277  {
278  if(ptTemplateInit)
279  {
280  for(unsigned int point=0;point<templateSize;point++)
281  {
282  delete[] ptTemplate[point].dW;
283  delete[] ptTemplate[point].HiG;
284  }
285  delete[] ptTemplate;
286  ptTemplate = NULL;
287  ptTemplateInit = false;
288  }
289  if (ptTemplateCompo) {
290  for(unsigned int point=0;point<templateSize;point++)
291  {
292  delete[] ptTemplateCompo[point].dW;
293  }
294  delete[] ptTemplateCompo;
295  ptTemplateCompo = NULL;
296  }
297  if (ptTemplateSupp) {
298  for(unsigned int point=0;point<templateSize;point++)
299  {
300  delete[] ptTemplateSupp[point].Bt;
301  delete[] ptTemplateSupp[point].BtInit;
302  delete[] ptTemplateSupp[point].dBt;
303  delete[] ptTemplateSupp[point].d2W;
304  delete[] ptTemplateSupp[point].d2Wx;
305  delete[] ptTemplateSupp[point].d2Wy;
306  }
307  delete[] ptTemplateSupp;
308  ptTemplateSupp = NULL;
309  }
311  if (ptTemplateSelect) {
312  delete[] ptTemplateSelect; ptTemplateSelect = NULL;
313  }
314  }
315  }
316 }
317 
351 void vpTemplateTracker::display(const vpImage<unsigned char> &I, const vpColor& col, const unsigned int thickness)
352 {
353  if (I.display) { // Only if a display is associated to the image
354  vpTemplateTrackerZone zoneWarped;
355  Warp->warpZone(*zoneTracked, p, zoneWarped);
356  zoneWarped.display(I, col, thickness);
357  }
358 }
359 
393 void vpTemplateTracker::display(const vpImage<vpRGBa> &I, const vpColor& col, const unsigned int thickness)
394 {
395  if (I.display) { // Only if a display is associated to the image
396  vpTemplateTrackerZone zoneWarped;
397  Warp->warpZone(*zoneTracked, p, zoneWarped);
398  zoneWarped.display(I, col, thickness);
399  }
400 }
401 
402 void vpTemplateTracker::computeOptimalBrentGain(const vpImage<unsigned char> &I,vpColVector &tp,double tMI,vpColVector &direction,double &alpha)
403 {
404  vpColVector **ptp;
405  ptp=new vpColVector*[4];
406  vpColVector p0(nbParam);
407  p0=tp;
408 
409  //valeur necessaire si conditionnel
410  vpColVector dpt(Warp->getNbParam());
411  vpColVector adpt(Warp->getNbParam());
412 
413  vpColVector p1(nbParam);
415  {
416  if(useInverse)
417  Warp->getParamInverse(direction,dpt);
418  else
419  dpt=direction;
420  Warp->pRondp(tp,dpt,p1);
421  }
422  else
423  {
424  p1=tp+direction;
425  }
426 
427  vpColVector p2(nbParam);
429  {
430  adpt=alpha*direction;
431  if(useInverse)
432  Warp->getParamInverse(adpt,dpt);
433  else
434  dpt=adpt;
435  Warp->pRondp(tp,dpt,p2);
436  }
437  else
438  {
439  p2=tp+alpha*direction;
440  }
441  vpColVector p3(nbParam);
442  ptp[0]=&p0;
443  ptp[1]=&p1;
444  ptp[2]=&p2;
445  ptp[3]=&p3;
446 
447 
448  double *Cost=new double[4];
449  //Cost[0]=getCost(I,p0);
450  Cost[0]=tMI;
451  Cost[1]=getCost(I,p1);
452  Cost[2]=getCost(I,p2);
453 
454 
455  double *talpha=new double[4];
456  talpha[0]=0;
457  talpha[1]=1.;
458  talpha[2]=alpha;
459 
460  //for(int i=0;i<3;i++)
461  // std::cout<<"alpha["<<i<<"] = "<<talpha[i]<<" Cost["<<i<<"] = "<<Cost[i]<<std::endl;
462 
463  //Utilise trois estimï¿œes de paraboles succesive ...
464  //A changer pour rendre adaptable
465  for(unsigned int opt=0;opt<nbIterBrent;opt++)
466  {
467  //double a=talpha[0];
468  //double b=talpha[1];
469  //double c=talpha[2];
470  //double Cost0=Cost[0];
471  //double Cost1=Cost[1];
472  //double Cost2=Cost[2];
473 
474  vpMatrix A(3,3);
475  for(unsigned int i=0;i<3;i++){A[i][0]=talpha[i]*talpha[i];A[i][1]=talpha[i];A[i][2]=1.;}
476  //std::cout<<"A="<<A<<std::endl;
477  vpColVector B(3);for(unsigned int i=0;i<3;i++)B[i]=Cost[i];
478  vpColVector parabol(3);parabol=(A.t()*A).inverseByLU()*A.t()*B;
479  //vpColVector parabol(3);parabol=A.pseudoInverse()*B;
480 
481  //si convexe
482  if(parabol[0]>0)
483  {
484  talpha[3]=-0.5*parabol[1]/parabol[0];
485  //std::cout<<"parabol = "<<parabol<<std::endl;
486  //std::cout<<"convexe talpha = "<<talpha[3]<<std::endl;
487  }
488  else//si concave
489  {
490  int tindic_x_min=0;
491  int tindic_x_max=0;
492  for(int i=1;i<3;i++)
493  {
494  if(talpha[i]<talpha[tindic_x_min])
495  tindic_x_min=i;
496  if(talpha[i]>talpha[tindic_x_max])
497  tindic_x_max=i;
498  }
499 
500  if(Cost[tindic_x_max]<Cost[tindic_x_min])
501  {
502  //talpha[3]=talpha[tindic_x_max]+1.;
503  talpha[3]=talpha[tindic_x_max]+1.;
504  /*if(talpha[tindic_x_min]>talpha[tindic_x_max])
505  talpha[3]=talpha[tindic_x_min]+1.;
506  else
507  talpha[3]=talpha[tindic_x_min]-1.;*/
508  }
509  else
510  {
511  //talpha[3]=talpha[tindic_x_min]-1.;
512  talpha[3]=talpha[tindic_x_min]-1.;
513  /*if(talpha[tindic_x_min]<talpha[tindic_x_max])
514  talpha[3]=talpha[tindic_x_max]+1.;
515  else
516  talpha[3]=talpha[tindic_x_max]-1.;*/
517  }
518  //std::cout<<"concave talpha="<<talpha[3]<<std::endl;
519  }
520  //std::cout<<"talpha="<<talpha[3]<<std::endl;
521  int indic_x_min=0;
522  int indic_x_max=0;
523  for(int i=1;i<3;i++)
524  {
525  if(talpha[i]<talpha[indic_x_min])
526  indic_x_min=i;
527  if(talpha[i]>talpha[indic_x_max])
528  indic_x_max=i;
529  }
530  //std::cout<<"talpha = "<<talpha[3]<<std::endl;
531  if(talpha[3]>talpha[indic_x_max])
532  if((talpha[3]-talpha[indic_x_max])>alpha)talpha[3]=talpha[indic_x_max]+4.;
533  if(talpha[3]<talpha[indic_x_min])
534  if((talpha[indic_x_min]-talpha[3])>alpha)talpha[3]=talpha[indic_x_min]-4.;
535 
536  /*if(((b-a)*(Cost1-Cost2)-(b-c)*(Cost1-Cost0))==0)
537  {Cost[3]=1000;break;}
538 
539  //calcul du gain correspondant au minimum de la parabole estimï¿œe
540  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));
541  int indic_x_min=0;
542  int indic_x_max=0;
543  for(int i=1;i<3;i++)
544  {
545  if(talpha[i]<talpha[indic_x_min])
546  indic_x_min=i;
547  if(talpha[i]>talpha[indic_x_max])
548  indic_x_max=i;
549  }
550  std::cout<<"talpha = "<<talpha[3]<<std::endl;
551  if(talpha[3]>talpha[indic_x_max])
552  if((talpha[3]-talpha[indic_x_max])>alpha)talpha[3]=talpha[indic_x_max]+alpha;
553  if(talpha[3]<talpha[indic_x_min])
554  if((talpha[indic_x_min]-talpha[3])>alpha)talpha[3]=talpha[indic_x_min]-alpha;*/
555 
556  //p3=tp-talpha[3]*direction;
558  {
559  adpt=talpha[3]*direction;
560  if(useInverse)
561  Warp->getParamInverse(adpt,dpt);
562  else
563  dpt=adpt;
564  Warp->pRondp(tp,dpt,p3);
565  }
566  else
567  {
568  p3=tp+talpha[3]*direction;
569  }
570 
571  Cost[3]=getCost(I,p3);
572  //std::cout<<"new cost="<<Cost[3]<<std::endl;
573 
574  int indice_f_max=0;
575  for(int i=1;i<4;i++)
576  if(Cost[i]>Cost[indice_f_max])
577  indice_f_max=i;
578  if(indice_f_max!=3)
579  {
580  *ptp[indice_f_max]=*ptp[3];
581  Cost[indice_f_max]=Cost[3];
582  talpha[indice_f_max]=talpha[3];
583  }
584  else
585  break;
586  }
587 
588  int indice_f_min=0;
589  for(int i=0;i<4;i++)
590  if(Cost[i]<Cost[indice_f_min])
591  indice_f_min=i;
592 
593  alpha=talpha[indice_f_min];
594 
595  if(alpha<1)alpha=1.;
596 
597  delete[] ptp;
598  delete[] Cost;
599  delete[] talpha;
600 }
601 
602 
607 void vpTemplateTracker::initPyramidal(unsigned int nbLvl, unsigned int l0)
608 {
609  // vpTRACE("init_pyramidal");
610  nbLvlPyr=nbLvl;
611  l0Pyr=l0;
612 
616  ptTemplateSelectPyr=new bool*[nbLvlPyr];
617  ptTemplateSuppPyr=new vpTemplateTrackerPointSuppMIInv*[nbLvlPyr];
619  for(unsigned int i=0; i< nbLvlPyr; i++) {
620  ptTemplatePyr[i] = NULL;
621  ptTemplateSuppPyr[i] = NULL;
622  ptTemplateSelectPyr[i] = NULL;
623  ptTemplateCompoPyr[i] = NULL;
624  }
625  templateSizePyr=new unsigned int[nbLvlPyr];
629 
630  pyrInitialised=true;
631  // vpTRACE("fin init_pyramidal");
632 
633 }
635 {
636  // vpTRACE("initTrackingPyr");
637  zoneTrackedPyr[0].copy(zone);
638  //vpTRACE("fin copy zone");
639 
640  pyr_IDes[0]=I;
645 
646  //creationpyramide de zones et images desiree
647  if(nbLvlPyr>1)
648  {
649  for(unsigned int i=1;i<nbLvlPyr;i++)
650  {
653 
658  //reste probleme avec le Hessien
659  }
660  }
661  /*for(int i=0;i<nbLvlPyr;i++)
662  {
663  vpColVector ptemp(8);ptemp=0;
664  zoneTracked=&zoneTrackedPyr[i];
665  init_pos_evalRMS(ptemp);
666  }*/
668 
669  // vpTRACE("fin initTrackingPyr");
670 
671 }
672 
692 {
693  zoneRef_.initClick(I, delaunay);
694 
695  if (nbLvlPyr > 1) {
699  }
700  else {
703 // trackNoPyr(I);
704  }
705 }
706 
717 void vpTemplateTracker::initFromPoints(const vpImage<unsigned char> &I, const std::vector< vpImagePoint > &v_ip, bool delaunay)
718 {
719  zoneRef_.initFromPoints(I, v_ip, delaunay);
720 
721  if (nbLvlPyr > 1) {
725  }
726  else {
729  //trackNoPyr(I);
730  }
731 }
732 
740 {
741  zoneRef_ = zone;
742 
743  if (nbLvlPyr > 1) {
747  }
748  else {
751 // trackNoPyr(I);
752  }
753 }
754 
756 {
757  vpTRACE("initCompInversePyr");
759  //ptTemplateSupp=ptTemplateSuppPyr[0];
760  //ptTemplateCompo=ptTemplateCompoPyr[0];
764  ptTemplateSuppPyr[0]=ptTemplateSupp;
766 
767 
768  if(nbLvlPyr>1)
769  {
770  vpImage<unsigned char> Itemp=I;
771  for(unsigned int i=1;i<nbLvlPyr;i++)
772  {
774 
778  initCompInversePyr(Itemp);
779  ptTemplateSuppPyr[i]=ptTemplateSupp;
781  }
782  }
783  // vpTRACE("fin initCompInversePyr");
784 
785 }
787 {
788  // vpTRACE("initHessienDesiredPyr");
789 
791  //ptTemplateSupp=ptTemplateSuppPyr[0];
792  //ptTemplateCompo=ptTemplateCompoPyr[0];
795 // ptTemplateSupp=new vpTemplateTrackerPointSuppMIInv[templateSize];
796  try{
798  ptTemplateSuppPyr[0]=ptTemplateSupp;
800  HdesirePyr[0]=Hdesire;
803  }
804  catch(vpException &e){
805  ptTemplateSuppPyr[0]=ptTemplateSupp;
807  HdesirePyr[0]=Hdesire;
810  throw(e);
811  }
812 
813  if(nbLvlPyr>1)
814  {
815  vpImage<unsigned char> Itemp;Itemp=I;
816  for(unsigned int i=1;i<nbLvlPyr;i++)
817  {
819 
823  //ptTemplateSupp=ptTemplateSuppPyr[i];
824  //ptTemplateCompo=ptTemplateCompoPyr[i];
825  try{
826  initHessienDesired(Itemp);
827  ptTemplateSuppPyr[i]=ptTemplateSupp;
829  HdesirePyr[i]=Hdesire;
832  }
833  catch(vpException &e){
834  ptTemplateSuppPyr[i]=ptTemplateSupp;
836  HdesirePyr[i]=Hdesire;
839  throw(e);
840  }
841  }
842  }
843  // vpTRACE("fin initHessienDesiredPyr");
844 }
845 
851 {
852  if (nbLvlPyr > 1)
853  trackPyr(I);
854  else
855  trackNoPyr(I);
856 }
857 
859 {
860  //vpTRACE("trackPyr");
861  vpImage<unsigned char> *pyr_I;
862 // pyr_I=new vpImage<unsigned char>[nbLvlPyr+1]; // Why +1 ?
863  pyr_I=new vpImage<unsigned char>[nbLvlPyr]; // Why +1 ?
864  pyr_I[0]=I;
865 
866  try
867  {
868  vpColVector ptemp(nbParam);
869  if(nbLvlPyr>1)
870  {
871  // vpColVector *p_sauv=new vpColVector[nbLvlPyr];
872  // for(unsigned int i=0;i<nbLvlPyr;i++)p_sauv[i].resize(nbParam);
873 
874  // p_sauv[0]=p;
875  for(unsigned int i=1;i<nbLvlPyr;i++)
876  {
877  vpImageFilter::getGaussPyramidal(pyr_I[i-1],pyr_I[i]);
878  //test getParamPyramidDown
879  /*vpColVector vX_test(2);vX_test[0]=15.;vX_test[1]=30.;
880  vpColVector vX_test2(2);
881  Warp->computeCoeff(p);
882  Warp->computeDenom(vX_test,p);
883  Warp->warpX(vX_test,vX_test2,p);
884  std::cout<<"p = "<<p.t()<<std::endl;*/
885  //std::cout<<"get p down"<<std::endl;
886  Warp->getParamPyramidDown(p,ptemp);
887  p=ptemp;
889 
890  // p_sauv[i]=p;
891  /*std::cout<<"p_down = "<<p.t()<<std::endl;
892 
893  vpColVector vX_testd(2);vX_testd[0]=15./2.;vX_testd[1]=30./2.;
894  vpColVector vX_testd2(2);
895  Warp->computeCoeff(p);
896  Warp->computeDenom(vX_testd,p);
897  Warp->warpX(vX_testd,vX_testd2,p);
898  std::cout<<2.*vX_testd2[0]<<","<<2.*vX_testd2[1]<<" <=> "<<vX_test2[0]<<","<<vX_test2[1]<<std::endl;*/
899 
900  }
901 
902  for(int i=(int)nbLvlPyr-1;i>=0;i--)
903  {
904  if(i>=(int)l0Pyr)
905  {
909  ptTemplateSupp=ptTemplateSuppPyr[i];
911  H=HdesirePyr[i];
912  HLM=HLMdesirePyr[i];
914  // zoneTracked=&zoneTrackedPyr[i];
915  trackRobust(pyr_I[i]);
916  }
917  //std::cout<<"get p up"<<std::endl;
918  // ptemp=p_sauv[i-1];
919  if (i > 0) {
920  Warp->getParamPyramidUp(p,ptemp);
921  p=ptemp;
923  }
924  }
925  #if 0
926  if(l0Pyr==0)
927  {
931  ptTemplateSupp=ptTemplateSuppPyr[0];
933  H=HdesirePyr[0];
934  HLM=HLMdesirePyr[0];
937  trackRobust(pyr_I[0]);
938  }
939 
940  if (l0Pyr > 0) {
941  // for (int l=(int)l0Pyr; l >=0; l--) {
942  // Warp->getParamPyramidUp(p,ptemp);
943  // p=ptemp;
944  // }
946  }
947  #endif
948  // delete [] p_sauv;
949  }
950  else
951  {
952  //std::cout<<"reviens a tracker de base"<<std::endl;
953  trackRobust(I);
954  }
955  delete[] pyr_I;
956  }
957  catch(vpException &e){
958  delete[] pyr_I;
960  }
961 }
962 
964 {
966  {
967  vpColVector p_pre_estimation;p_pre_estimation=p;
969  double pre_fcost=getCost(I,p);
970 
971  trackNoPyr(I);
972 
973  //std::cout<<"fct avant : "<<pre_fcost<<std::endl;
974  double post_fcost=getCost(I,p);
975  //std::cout<<"fct apres : "<<post_fcost<<std::endl<<std::endl;
976  if(pre_fcost<post_fcost)
977  p=p_pre_estimation;
978  }
979  else
980  trackNoPyr(I);
981 }
const char * getMessage(void)
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:199
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:161
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)
error that can be emited by ViSP classes.
Definition: vpException.h:76
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)
Error that can be emited by the vpTracker class and its derivates.
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:592
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:1296
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:152
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:98
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, const unsigned int thickness=3)