ViSP  2.9.0
vpMbEdgeKltTracker.cpp
1 /****************************************************************************
2  *
3  * $Id: vpMbEdgeKltTracker.cpp 4649 2014-02-07 14:57:11Z 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  * Hybrid tracker based on edges (vpMbt) and points of interests (KLT)
35  *
36  * Authors:
37  * Romain Tallonneau
38  * Aurelien Yol
39  *
40  *****************************************************************************/
41 
42 #include <visp/vpMbEdgeKltTracker.h>
43 
44 #ifdef VISP_HAVE_OPENCV
45 
47  : compute_interaction(true), lambda(0.8), thresholdKLT(2.), thresholdMBT(2.), maxIter(200)
48 {
49  computeCovariance = false;
50 
52 
53 #ifdef VISP_HAVE_OGRE
55 #endif
56 }
57 
63 {
64 }
65 
72 void
74 {
76 
78 
79  unsigned int n = 0;
80  for(unsigned int i = 0; i < vpMbKltTracker::faces.size() ; i++){
81  if(vpMbKltTracker::faces[i]->isVisible()){
82  vpMbEdgeTracker::faces[i]->isvisible = true;
83  n++;
84  }
85  else
86  vpMbEdgeTracker::faces[i]->isvisible = false;
87  }
89 
90  unsigned int i = (unsigned int)scales.size();
91  do {
92  i--;
93  if(scales[i]){
94  downScale(i);
96  upScale(i);
97  }
98  } while(i != 0);
99 
101 }
102 
112 void
114 {
115  if(firstTrack){
116  vpMbKltTracker::setPose(I, cdMo);
117 
119  lines[scaleLevel].front() ;
120  for(std::list<vpMbtDistanceLine*>::const_iterator it=lines[scaleLevel].begin(); it!=lines[scaleLevel].end(); ++it){
121  l = *it;
122  if(l->meline != NULL){
123  delete l->meline;
124  l->meline = NULL;
125  }
126  }
127 
128  initPyramid(I, Ipyramid);
129 
130  unsigned int n = 0;
131  for(unsigned int i = 0; i < vpMbKltTracker::faces.size() ; i++){
132  if(vpMbKltTracker::faces[i]->isVisible()){
133  vpMbEdgeTracker::faces[i]->isvisible = true;
134  n++;
135  }
136  else
137  vpMbEdgeTracker::faces[i]->isvisible = false;
138  }
140 
141  unsigned int i = (unsigned int)scales.size();
142  do {
143  i--;
144  if(scales[i]){
145  downScale(i);
147  upScale(i);
148  }
149  } while(i != 0);
150 
152  }
153 }
154 
159 void
161 {
164 }
165 
166 unsigned int
167 vpMbEdgeKltTracker::initMbtTracking(const unsigned int lvl)
168 {
169  vpMbtDistanceLine *l ;
171 
172  if(lvl >= scales.size() || !scales[lvl]){
173  throw vpException(vpException::dimensionError, "lvl not used.");
174  }
175 
176  unsigned int nbrow = 0;
177  for(std::list<vpMbtDistanceLine*>::iterator it=lines[lvl].begin(); it!=lines[lvl].end(); ++it){
178  l = *it;
179  nbrow += l->nbFeature ;
181  }
182 
183  for(std::list<vpMbtDistanceCylinder*>::const_iterator it=cylinders[lvl].begin(); it!=cylinders[lvl].end(); ++it){
184  cy = *it;
185  nbrow += cy->nbFeature ;
187  }
188 
189  return nbrow;
190 }
191 
203 void
204 vpMbEdgeKltTracker::loadConfigFile(const std::string& configFile)
205 {
206  vpMbEdgeKltTracker::loadConfigFile(configFile.c_str());
207 }
208 
273 void
274 vpMbEdgeKltTracker::loadConfigFile(const char* configFile)
275 {
276 #ifdef VISP_HAVE_XML2
278 
279  xmlp.setCameraParameters(cam);
282 
283  xmlp.setMovingEdge(me);
284 
285  xmlp.setMaxFeatures(10000);
286  xmlp.setWindowSize(5);
287  xmlp.setQuality(0.01);
288  xmlp.setMinDistance(5);
289  xmlp.setHarrisParam(0.01);
290  xmlp.setBlockSize(3);
291  xmlp.setPyramidLevels(3);
293 
294  try{
295  std::cout << " *********** Parsing XML for Mb Edge Tracker ************ " << std::endl;
296  xmlp.parse(configFile);
297  }
298  catch(...){
299  vpERROR_TRACE("Can't open XML file \"%s\"\n ", configFile);
300  throw vpException(vpException::ioError, "problem to parse configuration file.");
301  }
302 
303  vpCameraParameters camera;
304  xmlp.getCameraParameters(camera);
305  setCameraParameters(camera);
306 
311 
312  if(xmlp.hasNearClippingDistance())
314 
315  if(xmlp.hasFarClippingDistance())
317 
318  if(xmlp.getFovClipping()){
321  }
322 
323  vpMe meParser;
324  xmlp.getMe(meParser);
326 
328  tracker.setWindowSize((int)xmlp.getWindowSize());
329  tracker.setQuality(xmlp.getQuality());
332  tracker.setBlockSize((int)xmlp.getBlockSize());
334  maskBorder = xmlp.getMaskBorder();
335 #else
336  vpTRACE("You need the libXML2 to read the config file %s", configFile);
337 #endif
338 }
339 
350 void
351 vpMbEdgeKltTracker::loadModel(const std::string& modelFile)
352 {
353  vpMbTracker::loadModel(modelFile);
354 }
355 
359 bool
361  const unsigned int lvl)
362 {
363  bool reInit = vpMbKltTracker::postTracking(I, w_klt);
364 
365  postTrackingMbt(w_mbt,lvl);
366 
367  if (displayFeatures)
368  {
369  if(lvl == 0){
371  for(std::list<vpMbtDistanceLine*>::const_iterator it=lines[lvl].begin(); it!=lines[lvl].end(); ++it){
372  l = *it;
373  if (l->isVisible()){
374  l->displayMovingEdges(I);
375  }
376  }
377 
379  for(std::list<vpMbtDistanceCylinder*>::const_iterator it=cylinders[lvl].begin(); it!=cylinders[lvl].end(); ++it){
380  cy = *it;
381  cy->displayMovingEdges(I);
382  }
383  }
384  }
385 
386  if(reInit)
387  return true;
388 
390  unsigned int n = 0;
391  for(unsigned int i = 0; i < vpMbKltTracker::faces.size() ; i++){
392  if(vpMbKltTracker::faces[i]->isVisible()){
393  vpMbEdgeTracker::faces[i]->isvisible = true;
394  n++;
395  }
396  else
397  vpMbEdgeTracker::faces[i]->isvisible = false;
398  }
400 
403 
404  return false;
405 }
406 
417 void
419 {
420 
421  if(lvl >= scales.size() || !scales[lvl]){
422  throw vpException(vpException::dimensionError, "_lvl not used.");
423  }
424  unsigned int n =0 ;
426  for(std::list<vpMbtDistanceLine*>::const_iterator it=lines[lvl].begin(); it!=lines[lvl].end(); ++it){
427  l = *it;
428  {
429  double wmean = 0 ;
430  std::list<vpMeSite>::iterator itListLine;
431  if (l->nbFeature > 0) itListLine = l->meline->getMeList().begin();
432 
433  for (unsigned int i=0 ; i < l->nbFeature ; i++){
434  wmean += w[n+i] ;
435  vpMeSite p = *itListLine;
436  if (w[n+i] < 0.5){
438 
439  *itListLine = p;
440  }
441 
442  ++itListLine;
443  }
444  n+= l->nbFeature ;
445 
446  if (l->nbFeature!=0)
447  wmean /= l->nbFeature ;
448  else
449  wmean = 1;
450 
451  l->setMeanWeight(wmean);
452 
453  if (wmean < 0.8)
454  l->Reinit = true;
455  }
456  }
457 
458  // Same thing with cylinders as with lines
460  for(std::list<vpMbtDistanceCylinder*>::const_iterator it=cylinders[lvl].begin(); it!=cylinders[lvl].end(); ++it){
461  cy = *it;
462  double wmean = 0 ;
463  std::list<vpMeSite>::iterator itListCyl1;
464  std::list<vpMeSite>::iterator itListCyl2;
465  if (cy->nbFeature > 0){
466  itListCyl1 = cy->meline1->getMeList().begin();
467  itListCyl2 = cy->meline2->getMeList().begin();
468  }
469 
470  wmean = 0;
471  for(unsigned int i=0 ; i < cy->nbFeaturel1 ; i++){
472  wmean += w[n+i] ;
473  vpMeSite p = *itListCyl1;
474  if (w[n+i] < 0.5){
476 
477  *itListCyl1 = p;
478  }
479 
480  ++itListCyl1;
481  }
482 
483  if (cy->nbFeaturel1!=0)
484  wmean /= cy->nbFeaturel1 ;
485  else
486  wmean = 1;
487 
488  cy->setMeanWeight1(wmean);
489 
490  if (wmean < 0.8){
491  cy->Reinit = true;
492  }
493 
494  wmean = 0;
495  for(unsigned int i=cy->nbFeaturel1 ; i < cy->nbFeature ; i++){
496  wmean += w[n+i] ;
497  vpMeSite p = *itListCyl2;
498  if (w[n+i] < 0.5){
500 
501  *itListCyl2 = p;
502  }
503 
504  ++itListCyl2;
505  }
506 
507  if (cy->nbFeaturel2!=0)
508  wmean /= cy->nbFeaturel2 ;
509  else
510  wmean = 1;
511 
512  cy->setMeanWeight2(wmean);
513 
514  if (wmean < 0.8){
515  cy->Reinit = true;
516  }
517 
518  n+= cy->nbFeature ;
519  }
520 }
521 
531 void
532 vpMbEdgeKltTracker::computeVVS(const vpImage<unsigned char>& I, const unsigned int &nbInfos, vpColVector &w_mbt, vpColVector &w_klt, const unsigned int lvl)
533 {
534  vpColVector factor;
535  unsigned int nbrow = trackFirstLoop(I, factor, lvl);
536 
537  if(nbrow < 4 && nbInfos < 4){
538  vpERROR_TRACE("\n\t\t Error-> not enough data") ;
539  throw vpTrackingException(vpTrackingException::notEnoughPointError, "\n\t\t Error-> not enough data");
540  }
541  else if(nbrow < 4)
542  nbrow = 0;
543 
544  double residu = 0;
545  double residu_1 = -1;
546  unsigned int iter = 0;
547 
548  vpMatrix *J;
549  vpMatrix J_mbt, J_klt; // interaction matrix
550  vpColVector *R;
551  vpColVector R_mbt, R_klt; // residu
552  vpMatrix J_true;
553  vpColVector R_true;
554  vpColVector w_true;
555 
556  if(nbrow != 0){
557  J_mbt.resize(nbrow,6);
558  R_mbt.resize(nbrow);
559  }
560 
561  if(nbInfos != 0){
562  J_klt.resize(2*nbInfos,6);
563  R_klt.resize(2*nbInfos);
564  }
565 
566  vpColVector w; // weight from MEstimator
567  vpColVector v; // "speed" for VVS
568  vpRobust robust_mbt(0), robust_klt(0);
569  vpHomography H;
570 
571  vpMatrix JTJ, JTR;
572 
573  double factorMBT = 1.0;
574  double factorKLT = 1.0;
575 
576  //More efficient weight repartition for hybrid tracker should come soon...
577 // factorMBT = 1.0 - (double)nbrow / (double)(nbrow + nbInfos);
578 // factorKLT = 1.0 - factorMBT;
579  factorMBT = 0.35;
580  factorKLT = 0.65;
581 
582  double residuMBT = 0;
583  double residuKLT = 0;
584 
585  while( ((int)((residu - residu_1)*1e8) !=0 ) && (iter<maxIter) ){
586  J = new vpMatrix();
587  R = new vpColVector();
588 
589  if(nbrow >= 4)
590  trackSecondLoop(I,J_mbt,R_mbt,cMo,lvl);
591 
592  if(nbInfos >= 4){
593  unsigned int shift = 0;
594  for (unsigned int i = 0; i < vpMbKltTracker::faces.size(); i += 1){
595  if(vpMbKltTracker::faces[i]->isVisible() && vpMbKltTracker::faces[i]->hasEnoughPoints()){
596  vpSubColVector subR(R_klt, shift, 2*vpMbKltTracker::faces[i]->getNbPointsCur());
597  vpSubMatrix subJ(J_klt, shift, 0, 2*vpMbKltTracker::faces[i]->getNbPointsCur(), 6);
598  vpMbKltTracker::faces[i]->computeHomography(ctTc0, H);
599  vpMbKltTracker::faces[i]->computeInteractionMatrixAndResidu(subR, subJ);
600  shift += 2*vpMbKltTracker::faces[i]->getNbPointsCur();
601  }
602  }
603  }
604 
605  if(iter == 0){
606  w.resize(nbrow + 2*nbInfos);
607  w=1;
608 
609  w_mbt.resize(nbrow);
610  w_mbt = 1;
611  robust_mbt.resize(nbrow);
612 
613  w_klt.resize(2*nbInfos);
614  w_klt = 1;
615  robust_klt.resize(2*nbInfos);
616 
617  w_true.resize(nbrow + 2*nbInfos);
618  }
619 
620  /* robust */
621  if(nbrow > 3){
622  residuMBT = 0;
623  for(unsigned int i = 0; i < R_mbt.getRows(); i++)
624  residuMBT += fabs(R_mbt[i]);
625  residuMBT /= R_mbt.getRows();
626 
627  robust_mbt.setIteration(iter);
628  robust_mbt.setThreshold(thresholdMBT/cam.get_px());
629  robust_mbt.MEstimator( vpRobust::TUKEY, R_mbt, w_mbt);
630  J->stackMatrices(J_mbt);
631  R->stackMatrices(R_mbt);
632  }
633 
634  if(nbInfos > 3){
635  residuKLT = 0;
636  for(unsigned int i = 0; i < R_klt.getRows(); i++)
637  residuKLT += fabs(R_klt[i]);
638  residuKLT /= R_klt.getRows();
639 
640  robust_klt.setIteration(iter);
641  robust_klt.setThreshold(thresholdKLT/cam.get_px());
642  robust_klt.MEstimator( vpRobust::TUKEY, R_klt, w_klt);
643 
644  J->stackMatrices(J_klt);
645  R->stackMatrices(R_klt);
646  }
647 
648  unsigned int cpt = 0;
649  while(cpt< (nbrow+2*nbInfos)){
650  if(cpt<(unsigned)nbrow){
651  w[cpt] = ((w_mbt[cpt] * factor[cpt]) * factorMBT) ;
652  }
653  else
654  w[cpt] = (w_klt[cpt-nbrow] * factorKLT);
655  cpt++;
656  }
657 
658  if(computeCovariance){
659  R_true = (*R);
660  J_true = (*J);
661  }
662 
663  residu_1 = residu;
664  residu = 0;
665  double num = 0;
666  double den = 0;
667  for (unsigned int i = 0; i < static_cast<unsigned int>(R->getRows()); i++){
668  num += w[i]*vpMath::sqr((*R)[i]);
669  den += w[i];
670 
671  w_true[i] = w[i]*w[i];
672  (*R)[i] *= w[i];
674  for (unsigned int j = 0; j < 6; j += 1){
675  (*J)[i][j] *= w[i];
676  }
677  }
678  }
679 
680  residu = sqrt(num/den);
681 
682  JTJ = J->AtA();
683  computeJTR(*J, *R, JTR);
684  v = -lambda * JTJ.pseudoInverse() * JTR;
687 
688  iter++;
689 
690  delete J;
691  delete R;
692  }
693 
694  if(computeCovariance){
695  vpMatrix D;
696  D.diag(w_true);
698  }
699 }
700 
708 void
710 {
711  unsigned int nbInfos;
712  unsigned int nbFaceUsed;
713  vpColVector w_klt;
714 
715  vpMbKltTracker::preTracking(I, nbInfos, nbFaceUsed);
716 
717  if(nbInfos >= 4)
718  vpMbKltTracker::computeVVS(nbInfos, w_klt);
719  else{
720  nbInfos = 0;
721  // std::cout << "[Warning] Unable to init with KLT" << std::endl;
722  }
723 
725 
726  vpColVector w_mbt;
727  computeVVS(I, nbInfos, w_mbt, w_klt);
728 
729  if(postTracking(I, w_mbt, w_klt)){
731 
732  initPyramid(I, Ipyramid);
733 
734  unsigned int n = 0;
735  for(unsigned int i = 0; i < vpMbKltTracker::faces.size() ; i++){
736  if(vpMbKltTracker::faces[i]->isVisible()){
737  vpMbEdgeTracker::faces[i]->isvisible = true;
738  n++;
739  }
740  else
741  vpMbEdgeTracker::faces[i]->isvisible = false;
742  }
744 
745  unsigned int i = (unsigned int)scales.size();
746  do {
747  i--;
748  if(scales[i]){
749  downScale(i);
751  upScale(i);
752  }
753  } while(i != 0);
754 
756  }
757 }
758 
759 unsigned int
761 {
762  vpMbtDistanceLine *l ;
764 
765  if(lvl >= scales.size() || !scales[lvl]){
766  throw vpException(vpException::dimensionError, "_lvl not used.");
767  }
768 
769  unsigned int nbrow = initMbtTracking(lvl);
770 
771  if (nbrow==0){
772 // vpERROR_TRACE("\n\t\t Error-> not enough data in the interaction matrix...") ;
773 // throw vpTrackingException(vpTrackingException::notEnoughPointError, "\n\t\t Error-> not enough data in the interaction matrix...");
774  return nbrow;
775  }
776 
777  factor.resize(nbrow);
778  factor = 1;
779 
780  unsigned int n = 0;
781  for(std::list<vpMbtDistanceLine*>::const_iterator it=lines[lvl].begin(); it!=lines[lvl].end(); ++it){
782  l = *it;
784 
785  double fac = 1;
786  for(std::list<int>::const_iterator itindex = l->Lindex_polygon.begin(); itindex!=l->Lindex_polygon.end(); ++itindex){
787  int index = *itindex;
788  if (l->hiddenface->isAppearing((unsigned int)index)) {
789  fac = 0.2;
790  break;
791  }
792  if(l->closeToImageBorder(I, 10)){
793  fac = 0.1;
794  break;
795  }
796  }
797 
798  std::list<vpMeSite>::const_iterator itListLine;
799  if (l->meline != NULL)
800  itListLine = l->meline->getMeList().begin();
801 
802  for (unsigned int i=0 ; i < l->nbFeature ; i++){
803  factor[n+i] = fac;
804  vpMeSite site = *itListLine;
805  if (site.getState() != vpMeSite::NO_SUPPRESSION) factor[n+i] = 0.2;
806  ++itListLine;
807  }
808  n+= l->nbFeature ;
809  }
810 
811  for(std::list<vpMbtDistanceCylinder*>::const_iterator it=cylinders[lvl].begin(); it!=cylinders[lvl].end(); ++it){
812  cy = *it;
814  double fac = 1.0;
815 
816  std::list<vpMeSite>::const_iterator itCyl1;
817  std::list<vpMeSite>::const_iterator itCyl2;
818  if ((cy->meline1 != NULL || cy->meline2 != NULL)){
819  itCyl1 = cy->meline1->getMeList().begin();
820  itCyl2 = cy->meline2->getMeList().begin();
821  }
822 
823  for(unsigned int i=0 ; i < cy->nbFeature ; i++){
824  factor[n+i] = fac;
825  vpMeSite site;
826  if(i<cy->nbFeaturel1) {
827  site= *itCyl1;
828  ++itCyl1;
829  }
830  else{
831  site= *itCyl2;
832  ++itCyl2;
833  }
834  if (site.getState() != vpMeSite::NO_SUPPRESSION) factor[n+i] = 0.2;
835  }
836 
837  n+= cy->nbFeature ;
838  }
839 
840  return nbrow;
841 }
842 
843 void
845  vpHomogeneousMatrix& cMo_, const unsigned int lvl)
846 {
849 
850  unsigned int n = 0 ;
851  for(std::list<vpMbtDistanceLine*>::const_iterator it=lines[lvl].begin(); it!=lines[lvl].end(); ++it){
852  l = *it;
854  for (unsigned int i=0 ; i < l->nbFeature ; i++){
855  for (unsigned int j=0; j < 6 ; j++){
856  L[n+i][j] = l->L[i][j];
857  error[n+i] = l->error[i];
858  }
859  }
860  n+= l->nbFeature;
861  }
862 
863  for(std::list<vpMbtDistanceCylinder*>::const_iterator it=cylinders[lvl].begin(); it!=cylinders[lvl].end(); ++it){
864  cy = *it;
865  cy->computeInteractionMatrixError(cMo_, I) ;
866  for(unsigned int i=0 ; i < cy->nbFeature ; i++){
867  for(unsigned int j=0; j < 6 ; j++){
868  L[n+i][j] = cy->L[i][j];
869  error[n+i] = cy->error[i];
870  }
871  }
872 
873  n+= cy->nbFeature ;
874  }
875 }
876 
882 void
884 {
885  this->cam = camera;
886 
889 }
890 
897 void
898 vpMbEdgeKltTracker::initFaceFromCorners(const std::vector<vpPoint>& corners, const unsigned int indexFace)
899 {
900  vpMbEdgeTracker::initFaceFromCorners(corners, indexFace);
901  vpMbKltTracker::initFaceFromCorners(corners, indexFace);
902 }
903 
913 void
914 vpMbEdgeKltTracker::initCylinder(const vpPoint& p1, const vpPoint &p2, const double radius, const unsigned int indexCylinder)
915 {
916  vpMbEdgeTracker::initCylinder(p1, p2, radius, indexCylinder);
917 }
918 
929 void
931  const vpColor& col, const unsigned int thickness, const bool displayFullModel)
932 {
933  vpMbtDistanceLine *l ;
934 
935  for (unsigned int i = 0; i < scales.size(); i += 1){
936  if(scales[i]){
937  for(std::list<vpMbtDistanceLine*>::const_iterator it=lines[scaleLevel].begin(); it!=lines[scaleLevel].end(); ++it){
938  l = *it;
939  l->display(I,cMo_, camera, col, thickness, displayFullModel);
940  }
941 
942  for(std::list<vpMbtDistanceCylinder*>::const_iterator it=cylinders[scaleLevel].begin(); it!=cylinders[scaleLevel].end(); ++it){
943  (*it)->display(I, cMo_, camera, col, thickness);
944  }
945 
946  break ; //displaying model on one scale only
947  }
948  }
949 
950  for (unsigned int i = 0; i < vpMbKltTracker::faces.size(); i += 1){
951  if(displayFeatures && vpMbKltTracker::faces[i]->hasEnoughPoints() && vpMbKltTracker::faces[i]->isVisible()) {
952  vpMbKltTracker::faces[i]->displayPrimitive(I);
953  }
954  }
955 
956 #ifdef VISP_HAVE_OGRE
959 #endif
960 }
961 
972 void
974  const vpColor& col , const unsigned int thickness, const bool displayFullModel)
975 {
976  vpMbtDistanceLine *l ;
977 
978  for (unsigned int i = 0; i < scales.size(); i += 1){
979  if(scales[i]){
980  for(std::list<vpMbtDistanceLine*>::const_iterator it=lines[scaleLevel].begin(); it!=lines[scaleLevel].end(); ++it){
981  l = *it;
982  l->display(I,cMo_, camera, col, thickness, displayFullModel);
983  }
984 
985  for(std::list<vpMbtDistanceCylinder*>::const_iterator it=cylinders[scaleLevel].begin(); it!=cylinders[scaleLevel].end(); ++it){
986  (*it)->display(I, cMo_, camera, col, thickness);
987  }
988 
989  break ; //displaying model on one scale only
990  }
991  }
992 
993  for (unsigned int i = 0; i < vpMbKltTracker::faces.size(); i += 1){
994  if(displayFeatures && vpMbKltTracker::faces[i]->hasEnoughPoints() && vpMbKltTracker::faces[i]->isVisible()) {
995  vpMbKltTracker::faces[i]->displayPrimitive(I);
996  }
997  }
998 
999 #ifdef VISP_HAVE_OGRE
1002 #endif
1003 }
1004 
1005 #endif //VISP_HAVE_OPENCV
void setWindowName(const Ogre::String &n)
Definition: vpAROgre.h:234
void trackSecondLoop(const vpImage< unsigned char > &I, vpMatrix &L, vpColVector &_error, vpHomogeneousMatrix &cMo, const unsigned int lvl=0)
double lambda
The gain of the virtual visual servoing stage.
unsigned int getMaskBorder() const
void setQuality(const double &q)
void postTrackingMbt(vpColVector &w, const unsigned int level=0)
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
void displayMovingEdges(const vpImage< unsigned char > &I)
vpMatrix covarianceMatrix
Covariance matrix.
Definition: vpMbTracker.h:118
void setMovingEdge(const vpMe &me)
void setQuality(double input)
Definition: vpKltOpencv.h:264
double getHarrisParam() const
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Definition: vpMatrix.cpp:183
virtual void initCylinder(const vpPoint &, const vpPoint &, const double, const unsigned int)
Parse an Xml file to extract configuration parameters of a mbtConfig object.Data parser for the model...
void upScale(const unsigned int _scale)
void parse(const char *filename)
unsigned int clippingFlag
Flags specifying which clipping to used.
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Compute the weights according a residue vector and a PsiFunction.
Definition: vpRobust.cpp:136
bool isAppearing(const unsigned int i)
void getCameraParameters(vpCameraParameters &_cam) const
bool Reinit
Indicates if the line has to be reinitialized.
void setMeanWeight2(const double wmean)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
#define vpERROR_TRACE
Definition: vpDebug.h:395
#define vpTRACE
Definition: vpDebug.h:418
unsigned int scaleLevel
Current scale level used. This attribute must not be modified outside of the downScale() and upScale(...
std::list< int > Lindex_polygon
Index of the faces which contain the line.
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
Definition: vpMeSite.h:76
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
vpHomogeneousMatrix cMo
The current pose.
Definition: vpMbTracker.h:108
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
unsigned int getBlockSize() const
void displayMovingEdges(const vpImage< unsigned char > &I)
double getNearClippingDistance() const
double thresholdKLT
The threshold used in the robust estimation of KLT.
void getMe(vpMe &_ecm) const
error that can be emited by ViSP classes.
Definition: vpException.h:76
void computeJTR(const vpMatrix &J, const vpColVector &R, vpMatrix &JTR)
Manage a cylinder used in the model-based tracker.
Contains predetermined masks for sites and holds moving edges tracking parameters.
Definition: vpMe.h:70
unsigned int getMaxFeatures() const
Manage the line of a polygon used in the model-based tracker.
unsigned int nbFeature
The number of moving edges.
void setPyramidLevels(const int input)
Definition: vpKltOpencv.h:263
std::vector< const vpImage< unsigned char > * > Ipyramid
Pyramid of image associated to the current image. This pyramid is computed in the init() and in the t...
void setBlockSize(const int input)
Definition: vpKltOpencv.h:219
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, const double radius, const unsigned int indexCylinder=0)
virtual void setCameraParameters(const vpCameraParameters &camera)
Definition of the vpSubMatrix vpSubMatrix class provides a mask on a vpMatrix all properties of vpMat...
Definition: vpSubMatrix.h:66
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
Definition: vpMbTracker.h:116
double angleDisappears
Angle used to detect a face disappearance.
vpMe me
The moving edges parameters.
void updateMovingEdge(const vpImage< unsigned char > &I)
std::vector< std::list< vpMbtDistanceLine * > > lines
Vector of list of all the lines tracked (each line is linked to a list of moving edges). Each element of the vector is for a scale (element 0 = level 0 = no subsampling).
static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b)
virtual void reinit(const vpImage< unsigned char > &I)
virtual void setFarClippingDistance(const double &dist)
unsigned int nbFeature
The number of moving edges.
void downScale(const unsigned int _scale)
bool hasNearClippingDistance() const
Class that defines what is a point.
Definition: vpPoint.h:65
vpMatrix L
The interaction matrix.
vpMeSiteState getState() const
Definition: vpMeSite.h:202
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor col, const unsigned int thickness=1, const bool displayFullModel=false)
vpCameraParameters cam
The camera parameters.
Definition: vpMbTracker.h:106
virtual void init(const vpImage< unsigned char > &I)
vpHomogeneousMatrix ctTc0
The estimated displacement of the pose between the current instant and the initial position...
double getFarClippingDistance() const
unsigned int nbFeaturel1
The number of moving edges on line 1.
bool hasFarClippingDistance() const
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:178
vpAROgre * getOgreContext()
void setPyramidLevels(const unsigned int &pL)
std::vector< bool > scales
Vector of scale level to use for the multi-scale tracking.
unsigned int getWindowSize() const
Error that can be emited by the vpTracker class and its derivates.
double getAngleDisappear() const
void initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &_cMo)
void setWindowSize(const int input)
Definition: vpKltOpencv.h:274
vpMatrix AtA() const
Definition: vpMatrix.cpp:1408
void setWindowSize(const unsigned int &w)
static double sqr(double x)
Definition: vpMath.h:106
void setAngleDisappear(const double &adisappear)
vpColVector error
The error vector.
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
bool isVisible() const
virtual void track(const vpImage< unsigned char > &I)
Definition of the vpSubColVector vpSubColVector class provides a mask on a vpColVector all properties...
unsigned int maskBorder
Erosion of the mask.
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
Generic class defining intrinsic camera parameters.
virtual void loadModel(const std::string &modelFile)
void initPyramid(const vpImage< unsigned char > &_I, std::vector< const vpImage< unsigned char > * > &_pyramid)
void cleanPyramid(std::vector< const vpImage< unsigned char > * > &_pyramid)
bool useOgre
Use Ogre3d for visibility tests.
vpMbHiddenFaces< vpMbtKltPolygon > faces
Set of faces describing the object.
virtual void initFaceFromCorners(const std::vector< vpPoint > &corners, const unsigned int indexFace=-1)
vpMbtMeLine * meline1
The moving edge containers (first line of the cylinder)
double angleAppears
Angle used to detect a face appearance.
bool compute_interaction
If true, compute the interaction matrix at each iteration of the minimization. Otherwise, compute it only on the first iteration.
void setHarrisParam(const double &hp)
bool firstTrack
First track() called.
virtual void initFaceFromCorners(const std::vector< vpPoint > &_corners, const unsigned int _indexFace=-1)
std::list< vpMeSite > & getMeList()
Definition: vpMeTracker.h:161
void setMinDistance(const double &mD)
void loadConfigFile(const char *configFile)
void setCameraParameters(const vpCameraParameters &_cam)
vpKltOpencv tracker
Points tracker.
void stackMatrices(const vpMatrix &A)
Definition: vpMatrix.cpp:3003
void setState(const vpMeSiteState &flag)
Definition: vpMeSite.h:189
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &_cMo)
double get_px() const
static double rad(double deg)
Definition: vpMath.h:100
void setMeanWeight1(const double wmean)
virtual void setCameraParameters(const vpCameraParameters &cam)
virtual void setMaxIter(const unsigned int max)
void diag(const vpColVector &A)
Definition: vpMatrix.cpp:2572
void preTracking(const vpImage< unsigned char > &I, unsigned int &nbInfos, unsigned int &nbFaceUsed)
unsigned int size() const
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
void setMaxFeatures(const unsigned int &mF)
bool closeToImageBorder(const vpImage< unsigned char > &I, const unsigned int threshold)
double getQuality() const
static double deg(double rad)
Definition: vpMath.h:93
bool displayFeatures
If true, the features are displayed.
Definition: vpMbTracker.h:120
void setCameraParameters(const vpCameraParameters &cam)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
std::vector< std::list< vpMbtDistanceCylinder * > > cylinders
Vector of the tracked cylinders.
void setAngleAppear(const double &aappear)
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo)
unsigned int initMbtTracking(const unsigned int level=0)
vpHomogeneousMatrix inverse() const
unsigned int trackFirstLoop(const vpImage< unsigned char > &I, vpColVector &factor, const unsigned int lvl=0)
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
static vpHomogeneousMatrix direct(const vpColVector &v)
bool isVisible(const unsigned int i)
Contains an M-Estimator and various influence function.
Definition: vpRobust.h:63
virtual void initFaceFromCorners(const std::vector< vpPoint > &corners, const unsigned int indexFace=-1)
unsigned int nbvisiblepolygone
Number of polygon (face) currently visible.
double angleAppears
Angle used to detect a face appearance.
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w_mbt, vpColVector &w_klt, const unsigned int lvl=0)
void setMeanWeight(const double w_mean)
vpColVector error
The error vector.
virtual void setClipping(const unsigned int &flags)
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
Definition: vpMatrix.cpp:1861
bool Reinit
Indicates if the line has to be reinitialized.
virtual void init(const vpImage< unsigned char > &I)
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
void setBlockSize(const unsigned int &bs)
void trackMovingEdge(const vpImage< unsigned char > &I)
void displayOgre(const vpHomogeneousMatrix &cMo)
unsigned int clippingFlag
Flags specifying which clipping to used.
double getAngleAppear() const
virtual void setClipping(const unsigned int &flags)
void setMaxFeatures(const int input)
unsigned int nbFeaturel2
The number of moving edges on line 2.
double angleDisappears
Angle used to detect a face disappearance.
void setThreshold(const double noise_threshold)
Definition: vpRobust.h:128
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:161
double getMinDistance() const
void resize(unsigned int n_data)
Resize containers for sort methods.
Definition: vpRobust.cpp:88
vpMbtMeLine * meline2
The moving edge containers (second line of the cylinder)
bool getFovClipping() const
void setMinDistance(double input)
Definition: vpKltOpencv.h:243
void setIteration(const unsigned int iter)
Set iteration.
Definition: vpRobust.h:122
vpMatrix L
The interaction matrix.
void computeVVS(const unsigned int &nbInfos, vpColVector &w)
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo, const vpImage< unsigned char > &I)
void setMovingEdge(const vpMe &_ecm)
void setMaskBorder(const unsigned int &mb)
vpMbtMeLine * meline
The moving edge container.
unsigned int getPyramidLevels() const
virtual void loadModel(const std::string &modelFile)
double thresholdMBT
The threshold used in the robust estimation of MBT.
void setHarrisFreeParameter(double input)
Definition: vpKltOpencv.h:227
virtual void setNearClippingDistance(const double &dist)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94
void computeVVS(const vpImage< unsigned char > &I, const unsigned int &nbInfos, vpColVector &w_mbt, vpColVector &w_klt, const unsigned int lvl=0)