Visual Servoing Platform  version 3.0.0
vpMbKltTracker.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Model based tracker using only KLT
32  *
33  * Authors:
34  * Romain Tallonneau
35  * Aurelien Yol
36  *
37  *****************************************************************************/
38 
39 #include <visp3/core/vpImageConvert.h>
40 #include <visp3/mbt/vpMbKltTracker.h>
41 #include <visp3/core/vpVelocityTwistMatrix.h>
42 #include <visp3/core/vpTrackingException.h>
43 
44 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
45 
47  :
48 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
49  cur(),
50 #else
51  cur(NULL),
52 #endif
53  c0Mo(), compute_interaction(true),
54  firstInitialisation(true), maskBorder(5), lambda(0.8), maxIter(200), threshold_outlier(0.5),
55  percentGood(0.6), ctTc0(), tracker(), kltPolygons(), kltCylinders(), circles_disp()
56 {
59  tracker.setMaxFeatures(10000);
61  tracker.setQuality(0.01);
66 
69 
70 #ifdef VISP_HAVE_OGRE
71  faces.getOgreContext()->setWindowName("MBT Klt");
72 #endif
73 }
74 
80 {
81 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
82  if(cur != NULL){
83  cvReleaseImage(&cur);
84  cur = NULL;
85  }
86 #endif
87 
88  // delete the Klt Polygon features
89  vpMbtDistanceKltPoints *kltpoly;
90  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
91  kltpoly = *it;
92  if (kltpoly!=NULL){
93  delete kltpoly ;
94  }
95  kltpoly = NULL ;
96  }
97  kltPolygons.clear();
98 
99  vpMbtDistanceKltCylinder *kltPolyCylinder;
100  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
101  kltPolyCylinder = *it;
102  if (kltPolyCylinder!=NULL){
103  delete kltPolyCylinder ;
104  }
105  kltPolyCylinder = NULL ;
106  }
107  kltCylinders.clear();
108 
109  // delete the structures used to display circles
111  for(std::list<vpMbtDistanceCircle*>::const_iterator it=circles_disp.begin(); it!=circles_disp.end(); ++it){
112  ci = *it;
113  if (ci!=NULL){
114  delete ci ;
115  }
116  ci = NULL ;
117  }
118 
119  circles_disp.clear();
120 }
121 
122 void
124 {
125  if(!modelInitialised){
126  throw vpException(vpException::fatalError, "model not initialized");
127  }
128 
129  bool reInitialisation = false;
130  if(!useOgre)
131  faces.setVisible(I, cam, cMo, angleAppears, angleDisappears, reInitialisation);
132  else{
133 #ifdef VISP_HAVE_OGRE
134  if(!faces.isOgreInitialised()){
137  faces.initOgre(cam);
138  // Turn off Ogre config dialog display for the next call to this function
139  // since settings are saved in the ogre.cfg file and used during the next
140  // call
141  ogreShowConfigDialog = false;
142  }
143 
144  faces.setVisibleOgre(I, cam, cMo, angleAppears, angleDisappears, reInitialisation);
145 
146 #else
147  faces.setVisible(I, cam, cMo, angleAppears, angleDisappears, reInitialisation);
148 #endif
149  }
150  reinit(I);
151 }
152 
153 void
155 {
156  c0Mo = cMo;
157  ctTc0.eye();
158 
160 
161  cam.computeFov(I.getWidth(), I.getHeight());
162 
163  if(useScanLine){
166  }
167 
168  // mask
169 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
170  cv::Mat mask((int)I.getRows(), (int)I.getCols(), CV_8UC1, cv::Scalar(0));
171 #else
172  IplImage* mask = cvCreateImage(cvSize((int)I.getWidth(), (int)I.getHeight()), IPL_DEPTH_8U, 1);
173  cvZero(mask);
174 #endif
175 
176  vpMbtDistanceKltPoints *kltpoly;
177  vpMbtDistanceKltCylinder *kltPolyCylinder;
178  if(useScanLine){
180  }
181  else{
182  unsigned char val = 255/* - i*15*/;
183  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
184  kltpoly = *it;
185  if(kltpoly->polygon->isVisible() && kltpoly->isTracked() && kltpoly->polygon->getNbPoint() > 2){
186  kltpoly->polygon->computePolygonClipped(cam); // Might not be necessary when scanline is activated
187  kltpoly->updateMask(mask, val, maskBorder);
188  }
189  }
190 
191  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
192  kltPolyCylinder = *it;
193 
194  if(kltPolyCylinder->isTracked())
195  {
196  for(unsigned int k = 0 ; k < kltPolyCylinder->listIndicesCylinderBBox.size() ; k++)
197  {
198  int indCylBBox = kltPolyCylinder->listIndicesCylinderBBox[k];
199  if(faces[indCylBBox]->isVisible() && faces[indCylBBox]->getNbPoint() > 2){
200  faces[indCylBBox]->computePolygonClipped(cam); // Might not be necessary when scanline is activated
201  }
202  }
203 
204  kltPolyCylinder->updateMask(mask, val, maskBorder);
205  }
206  }
207  }
208 
209  tracker.initTracking(cur, mask);
210 // tracker.track(cur); // AY: Not sure to be usefull but makes sure that the points are valid for tracking and avoid too fast reinitialisations.
211 // vpCTRACE << "init klt. detected " << tracker.getNbFeatures() << " points" << std::endl;
212 
213  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
214  kltpoly = *it;
215  if(kltpoly->polygon->isVisible() && kltpoly->isTracked() && kltpoly->polygon->getNbPoint() > 2){
216  kltpoly->init(tracker);
217  }
218  }
219 
220  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
221  kltPolyCylinder = *it;
222 
223  if(kltPolyCylinder->isTracked())
224  kltPolyCylinder->init(tracker, cMo);
225  }
226 
227 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
228  cvReleaseImage(&mask);
229 #endif
230 }
231 
236 void
238 {
239  cMo.eye();
240 
241 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
242  if(cur != NULL){
243  cvReleaseImage(&cur);
244  cur = NULL;
245  }
246 #endif
247 
248  // delete the Klt Polygon features
249  vpMbtDistanceKltPoints *kltpoly;
250  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
251  kltpoly = *it;
252  if (kltpoly!=NULL){
253  delete kltpoly ;
254  }
255  kltpoly = NULL ;
256  }
257  kltPolygons.clear();
258 
259  vpMbtDistanceKltCylinder *kltPolyCylinder;
260  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
261  kltPolyCylinder = *it;
262  if (kltPolyCylinder!=NULL){
263  delete kltPolyCylinder ;
264  }
265  kltPolyCylinder = NULL ;
266  }
267  kltCylinders.clear();
268 
269  // delete the structures used to display circles
271  for(std::list<vpMbtDistanceCircle*>::const_iterator it=circles_disp.begin(); it!=circles_disp.end(); ++it){
272  ci = *it;
273  if (ci!=NULL){
274  delete ci ;
275  }
276  ci = NULL ;
277  }
278 
279  circles_disp.clear();
280 
281  compute_interaction = true;
282  firstInitialisation = true;
283  computeCovariance = false;
284 
287 
288  tracker.setMaxFeatures(10000);
290  tracker.setQuality(0.01);
295 
298 
300 
301  maskBorder = 5;
302  threshold_outlier = 0.5;
303  percentGood = 0.7;
304 
305  lambda = 0.8;
306  maxIter = 200;
307 
308  faces.reset();
309 
311 
312  useScanLine = false;
313 
314 #ifdef VISP_HAVE_OGRE
315  useOgre = false;
316 #endif
317 }
318 
326 std::vector<vpImagePoint>
328 {
329  std::vector<vpImagePoint> kltPoints;
330  for (unsigned int i = 0; i < static_cast<unsigned int>(tracker.getNbFeatures()); i ++){
331  int id;
332  float x_tmp, y_tmp;
333  tracker.getFeature((int)i, id, x_tmp, y_tmp);
334  kltPoints.push_back(vpImagePoint(y_tmp, x_tmp));
335  }
336 
337  return kltPoints;
338 }
339 
347 std::map<int, vpImagePoint>
349 {
350  std::map<int, vpImagePoint> kltPoints;
351  for (unsigned int i = 0; i < static_cast<unsigned int>(tracker.getNbFeatures()); i ++){
352  int id;
353  float x_tmp, y_tmp;
354  tracker.getFeature((int)i, id, x_tmp, y_tmp);
355  kltPoints[id] = vpImagePoint(y_tmp, x_tmp);
356  }
357 
358  return kltPoints;
359 }
360 
366 void
375 }
376 
382 void
384 {
385 // for (unsigned int i = 0; i < faces.size(); i += 1){
386 // faces[i]->setCameraParameters(camera);
387 // }
388 
389  vpMbtDistanceKltPoints *kltpoly;
390  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
391  kltpoly = *it;
392  kltpoly->setCameraParameters(camera);
393  }
394 
395  vpMbtDistanceKltCylinder *kltPolyCylinder;
396  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
397  kltPolyCylinder = *it;
398  kltPolyCylinder->setCameraParameters(camera);
399  }
400 
401  this->cam = camera;
402 }
403 
413 void
415 {
416  if((int)(kltCylinders.size()) != 0)
417  {
418  std::cout << "WARNING: Cannot set pose when model contains cylinder(s). This feature is not implemented yet." << std::endl;
419  std::cout << "Tracker will be reinitialized with the given pose." << std::endl;
420  cMo = cdMo;
421  init(I);
422  }
423  else
424  {
425  vpMbtDistanceKltPoints *kltpoly;
426 
427 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
428  std::vector<cv::Point2f> init_pts;
429  std::vector<long> init_ids;
430  std::vector<cv::Point2f> guess_pts;
431 #else
432  unsigned int nbp = 0;
433  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it) {
434  kltpoly = *it;
435  if(kltpoly->polygon->isVisible() && kltpoly->polygon->getNbPoint() > 2)
436  nbp += (*it)->getCurrentNumberPoints();
437  }
438 
439  CvPoint2D32f* init_pts = NULL;
440  init_pts = (CvPoint2D32f*)cvAlloc(tracker.getMaxFeatures()*sizeof(init_pts[0]));
441  long *init_ids = (long*)cvAlloc((unsigned int)tracker.getMaxFeatures()*sizeof(long));
442  unsigned int iter_pts = 0;
443 
444  CvPoint2D32f* guess_pts = NULL;
445  guess_pts = (CvPoint2D32f*)cvAlloc(tracker.getMaxFeatures()*sizeof(guess_pts[0]));
446 #endif
447 
448  vpHomogeneousMatrix cdMc = cdMo * cMo.inverse();
449  vpHomogeneousMatrix cMcd = cdMc.inverse();
450 
451  vpRotationMatrix cdRc;
452  vpTranslationVector cdtc;
453 
454  cdMc.extract(cdRc);
455  cdMc.extract(cdtc);
456 
457  unsigned int nbCur = 0;
458 
459  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it) {
460  kltpoly = *it;
461 
462  if(kltpoly->polygon->isVisible() && kltpoly->polygon->getNbPoint() > 2) {
463  kltpoly->polygon->changeFrame(cdMo);
464 
465  //Get the normal to the face at the current state cMo
466  vpPlane plan(kltpoly->polygon->p[0], kltpoly->polygon->p[1], kltpoly->polygon->p[2]);
467  plan.changeFrame(cMcd);
468 
469  vpColVector Nc = plan.getNormal();
470  Nc.normalize();
471 
472  double invDc = 1.0 / plan.getD();
473 
474  //Create the homography
475  vpMatrix cdHc;
476  vpGEMM(cdtc, Nc, -invDc, cdRc, 1.0, cdHc, VP_GEMM_B_T);
477  cdHc /= cdHc[2][2];
478 
479  //Create the 2D homography
480  vpMatrix cdGc = cam.get_K() * cdHc * cam.get_K_inverse();
481 
482  //Points displacement
483  std::map<int, vpImagePoint>::const_iterator iter = kltpoly->getCurrentPoints().begin();
484  nbCur+= (unsigned int)kltpoly->getCurrentPoints().size();
485  for( ; iter != kltpoly->getCurrentPoints().end(); iter++){
486  vpColVector cdp(3);
487  cdp[0] = iter->second.get_j(); cdp[1] = iter->second.get_i(); cdp[2] = 1.0;
488 
489 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
490  cv::Point2f p((float)cdp[0], (float)cdp[1]);
491  init_pts.push_back(p);
492  init_ids.push_back((size_t)(kltpoly->getCurrentPointsInd())[(size_t)iter->first]);
493 #else
494  init_pts[iter_pts].x = (float)cdp[0];
495  init_pts[iter_pts].y = (float)cdp[1];
496  init_ids[iter_pts] = (kltpoly->getCurrentPointsInd())[(size_t)iter->first];
497 #endif
498 
499  double p_mu_t_2 = cdp[0] * cdGc[2][0] + cdp[1] * cdGc[2][1] + cdGc[2][2];
500 
501  if( fabs(p_mu_t_2) < std::numeric_limits<double>::epsilon()){
502  cdp[0] = 0.0;
503  cdp[1] = 0.0;
504  throw vpException(vpException::divideByZeroError, "the depth of the point is calculated to zero");
505  }
506 
507  cdp[0] = (cdp[0] * cdGc[0][0] + cdp[1] * cdGc[0][1] + cdGc[0][2]) / p_mu_t_2;
508  cdp[1] = (cdp[0] * cdGc[1][0] + cdp[1] * cdGc[1][1] + cdGc[1][2]) / p_mu_t_2;
509 
510  //Set value to the KLT tracker
511 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
512  cv::Point2f p_guess((float)cdp[0], (float)cdp[1]);
513  guess_pts.push_back(p_guess);
514 #else
515  guess_pts[iter_pts].x = (float)cdp[0];
516  guess_pts[iter_pts++].y = (float)cdp[1];
517 #endif
518  }
519  }
520  }
521 
523 
524 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
525  tracker.setInitialGuess(init_pts, guess_pts, init_ids);
526 #else
527  tracker.setInitialGuess(&init_pts, &guess_pts, init_ids, iter_pts);
528 
529  if(init_pts) cvFree(&init_pts);
530  init_pts = NULL;
531 
532  if(guess_pts) cvFree(&guess_pts);
533  guess_pts = NULL;
534 
535  if(init_ids)cvFree(&init_ids);
536  init_ids = NULL;
537 #endif
538 
539  bool reInitialisation = false;
540  if(!useOgre)
541  faces.setVisible(I, cam, cdMo, angleAppears, angleDisappears, reInitialisation);
542  else{
543 #ifdef VISP_HAVE_OGRE
544  faces.setVisibleOgre(I, cam, cdMo, angleAppears, angleDisappears, reInitialisation);
545 #else
546  faces.setVisible(I, cam, cdMo, angleAppears, angleDisappears, reInitialisation);
547 #endif
548  }
549 
550  cam.computeFov(I.getWidth(), I.getHeight());
551 
552  if(useScanLine){
555  }
556 
557  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
558  kltpoly = *it;
559  if(kltpoly->polygon->isVisible() && kltpoly->polygon->getNbPoint() > 2){
560  kltpoly->polygon->computePolygonClipped(cam);
561  kltpoly->init(tracker);
562  }
563  }
564 
565  cMo = cdMo;
566  c0Mo = cMo;
567  ctTc0.eye();
568  }
569 }
570 
576 void
578 {
580  kltPoly->setCameraParameters(cam) ;
581  kltPoly->polygon = &polygon;
582  kltPoly->hiddenface = &faces ;
583  kltPoly->useScanLine = useScanLine;
584  kltPolygons.push_back(kltPoly);
585 }
591 void
593 {
595  kltPoly->setCameraParameters(cam) ;
596  kltPoly->polygon = &polygon;
597  kltPoly->hiddenface = &faces ;
598  kltPoly->useScanLine = useScanLine;
599  kltPolygons.push_back(kltPoly);
600 }
601 
609 void
610 vpMbKltTracker::preTracking(const vpImage<unsigned char>& I, unsigned int &nbInfos, unsigned int &nbFaceUsed)
611 {
613  tracker.track(cur);
614 
615  nbInfos = 0;
616  nbFaceUsed = 0;
617  vpMbtDistanceKltPoints *kltpoly;
618 // for (unsigned int i = 0; i < faces.size(); i += 1){
619  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
620  kltpoly = *it;
621  if(kltpoly->polygon->isVisible() && kltpoly->isTracked() && kltpoly->polygon->getNbPoint() > 2){
623 // faces[i]->ransac();
624  if(kltpoly->hasEnoughPoints()){
625  nbInfos += kltpoly->getCurrentNumberPoints();
626  nbFaceUsed++;
627  }
628  }
629  }
630 
631  vpMbtDistanceKltCylinder *kltPolyCylinder;
632  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
633  kltPolyCylinder = *it;
634 
635  if(kltPolyCylinder->isTracked())
636  {
637  kltPolyCylinder->computeNbDetectedCurrent(tracker);
638  if(kltPolyCylinder->hasEnoughPoints()){
639  nbInfos += kltPolyCylinder->getCurrentNumberPoints();
640  nbFaceUsed++;
641  }
642  }
643  }
644 }
645 
649 bool
651 {
652  // # For a better Post Tracking, tracker should reinitialize if so faces don't have enough points but are visible.
653  // # Here we are not doing it for more speed performance.
654  bool reInitialisation = false;
655 
656  unsigned int initialNumber = 0;
657  unsigned int currentNumber = 0;
658  unsigned int shift = 0;
659  vpMbtDistanceKltPoints *kltpoly;
660 // for (unsigned int i = 0; i < faces.size(); i += 1){
661  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
662  kltpoly = *it;
663  if(kltpoly->polygon->isVisible() && kltpoly->isTracked() && kltpoly->polygon->getNbPoint() > 2){
664  initialNumber += kltpoly->getInitialNumberPoint();
665  if(kltpoly->hasEnoughPoints()){
666  vpSubColVector sub_w(w, shift, 2*kltpoly->getCurrentNumberPoints());
667  shift += 2*kltpoly->getCurrentNumberPoints();
668  kltpoly->removeOutliers(sub_w, threshold_outlier);
669 
670  currentNumber += kltpoly->getCurrentNumberPoints();
671  }
672 // else{
673 // reInitialisation = true;
674 // break;
675 // }
676  }
677  }
678 
679  vpMbtDistanceKltCylinder *kltPolyCylinder;
680  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
681  kltPolyCylinder = *it;
682 
683  if(kltPolyCylinder->isTracked())
684  {
685  initialNumber += kltPolyCylinder->getInitialNumberPoint();
686  if(kltPolyCylinder->hasEnoughPoints()){
687  vpSubColVector sub_w(w, shift, 2*kltPolyCylinder->getCurrentNumberPoints());
688  shift += 2*kltPolyCylinder->getCurrentNumberPoints();
689  kltPolyCylinder->removeOutliers(sub_w, threshold_outlier);
690 
691  currentNumber += kltPolyCylinder->getCurrentNumberPoints();
692  }
693  }
694  }
695 
696 // if(!reInitialisation){
697  double value = percentGood * (double)initialNumber;
698  if((double)currentNumber < value){
699 // std::cout << "Too many point disappear : " << initialNumber << "/" << currentNumber << std::endl;
700  reInitialisation = true;
701  }
702  else{
703  if(!useOgre)
704  faces.setVisible(I, cam, cMo, angleAppears, angleDisappears, reInitialisation);
705  else{
706 #ifdef VISP_HAVE_OGRE
707  faces.setVisibleOgre(I, cam, cMo, angleAppears, angleDisappears, reInitialisation);
708 #else
709  faces.setVisible(I, cam, cMo, angleAppears, angleDisappears, reInitialisation);
710 #endif
711  }
712  }
713 // }
714 
715  if(reInitialisation)
716  return true;
717 
718  return false;
719 }
720 
727 void
728 vpMbKltTracker::computeVVS(const unsigned int &nbInfos, vpColVector &w)
729 {
730  vpMatrix L; // interaction matrix
731  vpColVector R; // residu
732  vpMatrix L_true; // interaction matrix
733  vpMatrix LVJ_true;
734  //vpColVector R_true; // residu
735  vpColVector v; // "speed" for VVS
736  vpHomography H;
737  vpColVector w_true;
738  vpRobust robust(2*nbInfos);
739 
740  vpMatrix LTL;
741  vpColVector LTR;
742  vpHomogeneousMatrix cMoPrev;
743  vpHomogeneousMatrix ctTc0_Prev;
744  vpColVector m_error_prev(2*nbInfos);
745  double mu = 0.01;
746 
747  double normRes = 0;
748  double normRes_1 = -1;
749  unsigned int iter = 0;
750 
751  R.resize(2*nbInfos);
752  L.resize(2*nbInfos, 6, 0);
753 
754  while( ((int)((normRes - normRes_1)*1e8) != 0 ) && (iter<maxIter) ){
755 
756  unsigned int shift = 0;
757  vpMbtDistanceKltPoints *kltpoly;
758  // for (unsigned int i = 0; i < faces.size(); i += 1){
759  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
760  kltpoly = *it;
761  if(kltpoly->polygon->isVisible() && kltpoly->isTracked() && kltpoly->polygon->getNbPoint() > 2 &&
762  kltpoly->hasEnoughPoints()){
763  vpSubColVector subR(R, shift, 2*kltpoly->getCurrentNumberPoints());
764  vpSubMatrix subL(L, shift, 0, 2*kltpoly->getCurrentNumberPoints(), 6);
765  try{
766  kltpoly->computeHomography(ctTc0, H);
767  kltpoly->computeInteractionMatrixAndResidu(subR, subL);
768  }catch(...){
769  throw vpTrackingException(vpTrackingException::fatalError, "Cannot compute interaction matrix");
770  }
771 
772  shift += 2*kltpoly->getCurrentNumberPoints();
773  }
774  }
775 
776  vpMbtDistanceKltCylinder *kltPolyCylinder;
777  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
778  kltPolyCylinder = *it;
779 
780  if(kltPolyCylinder->isTracked() && kltPolyCylinder->hasEnoughPoints())
781  {
782  vpSubColVector subR(R, shift, 2*kltPolyCylinder->getCurrentNumberPoints());
783  vpSubMatrix subL(L, shift, 0, 2*kltPolyCylinder->getCurrentNumberPoints(), 6);
784  try{
785  kltPolyCylinder->computeInteractionMatrixAndResidu(ctTc0,subR, subL);
786  }catch(...){
787  throw vpTrackingException(vpTrackingException::fatalError, "Cannot compute interaction matrix");
788  }
789 
790  shift += 2*kltPolyCylinder->getCurrentNumberPoints();
791  }
792  }
793 
794  bool reStartFromLastIncrement = false;
796  if(m_error.sumSquare()/(double)(2*nbInfos) > m_error_prev.sumSquare()/(double)(2*nbInfos)){
797  mu *= 10.0;
798 
799  if(mu > 1.0)
800  throw vpTrackingException(vpTrackingException::fatalError, "Optimization diverged");
801 
802  cMo = cMoPrev;
803  m_error = m_error_prev;
804  ctTc0 = ctTc0_Prev;
805  reStartFromLastIncrement = true;
806  }
807  }
808 
809  if(!reStartFromLastIncrement){
810  if(iter == 0){
811  w_true.resize(2*nbInfos);
812  w.resize(2*nbInfos);
813  w = 1;
814  w_true = 1;
815  }
816  robust.setIteration(iter);
817  robust.setThreshold(2/cam.get_px());
818  robust.MEstimator( vpRobust::TUKEY, R, w);
819 
820  m_error = R;
821  if(computeCovariance){
822  L_true = L;
823  if(!isoJoIdentity){
825  cVo.buildFrom(cMo);
826  LVJ_true = (L*cVo*oJo);
827  }
828  }
829 
830  normRes_1 = normRes;
831  normRes = 0;
832  for (unsigned int i = 0; i < static_cast<unsigned int>(R.getRows()); i += 1){
833  w_true[i] = w[i];
834  R[i] = R[i] * w[i];
835  normRes += R[i];
836  }
837 
838  if((iter == 0) || compute_interaction){
839  for(unsigned int i=0; i<static_cast<unsigned int>(R.getRows()); i++){
840  for(unsigned int j=0; j<6; j++){
841  L[i][j] *= w[i];
842  }
843  }
844  }
845 
846  if(isoJoIdentity){
847  LTL = L.AtA();
848  computeJTR(L, R, LTR);
849 
850  switch(m_optimizationMethod){
852  {
853  vpMatrix LMA(LTL.getRows(), LTL.getCols());
854  LMA.eye();
855  vpMatrix LTLmuI = LTL + (LMA*mu);
856  v = -lambda*LTLmuI.pseudoInverse(LTLmuI.getRows()*std::numeric_limits<double>::epsilon())*LTR;
857 
858  if(iter != 0)
859  mu /= 10.0;
860 
861  m_error_prev = m_error;
862  break;
863  }
865  default:
866  v = -lambda * LTL.pseudoInverse(LTL.getRows()*std::numeric_limits<double>::epsilon()) * LTR;
867  }
868  }
869  else{
871  cVo.buildFrom(cMo);
872  vpMatrix LVJ = (L*cVo*oJo);
873  vpMatrix LVJTLVJ = (LVJ).AtA();
874  vpColVector LVJTR;
875  computeJTR(LVJ, R, LVJTR);
876 
877  switch(m_optimizationMethod){
879  {
880  vpMatrix LMA(LVJTLVJ.getRows(), LVJTLVJ.getCols());
881  LMA.eye();
882  vpMatrix LTLmuI = LVJTLVJ + (LMA*mu);
883  v = -lambda*LTLmuI.pseudoInverse(LTLmuI.getRows()*std::numeric_limits<double>::epsilon())*LVJTR;
884  v = cVo * v;
885 
886  if(iter != 0)
887  mu /= 10.0;
888 
889  m_error_prev = m_error;
890  break;
891  }
893  default:
894  {
895  v = -lambda*LVJTLVJ.pseudoInverse(LVJTLVJ.getRows()*std::numeric_limits<double>::epsilon())*LVJTR;
896  v = cVo * v;
897  break;
898  }
899  }
900  }
901 
902  cMoPrev = cMo;
903  ctTc0_Prev = ctTc0;
905  cMo = ctTc0 * c0Mo;
906  } // endif(!restartFromLast)
907 
908  iter++;
909  }
910 
911  if(computeCovariance){
912  vpMatrix D;
913  D.diag(w_true);
914 
915  // Note that here the covariance is computed on cMoPrev for time computation efficiency
916  if(isoJoIdentity){
918  }
919  else{
921  }
922  }
923 }
924 
932 void
934 {
935  unsigned int nbInfos = 0;
936  unsigned int nbFaceUsed = 0;
937 
938  try{
939  preTracking(I, nbInfos, nbFaceUsed);
940  }
941  catch(vpException &e){
942  throw e;
943  }
944 
945  if(nbInfos < 4 || nbFaceUsed == 0){
946  vpERROR_TRACE("\n\t\t Error-> not enough data") ;
947  throw vpTrackingException(vpTrackingException::notEnoughPointError, "\n\t\t Error-> not enough data");
948  }
949 
950  //vpColVector w;
951  computeVVS(nbInfos, m_w);
952 
953  if(postTracking(I, m_w))
954  reinit(I);
955 }
956 
968 void
969 vpMbKltTracker::loadConfigFile(const std::string& configFile)
970 {
971  vpMbKltTracker::loadConfigFile(configFile.c_str());
972 }
973 
1020 void
1021 vpMbKltTracker::loadConfigFile(const char* configFile)
1022 {
1023 #ifdef VISP_HAVE_XML2
1024  vpMbtKltXmlParser xmlp;
1025 
1026  xmlp.setMaxFeatures(10000);
1027  xmlp.setWindowSize(5);
1028  xmlp.setQuality(0.01);
1029  xmlp.setMinDistance(5);
1030  xmlp.setHarrisParam(0.01);
1031  xmlp.setBlockSize(3);
1032  xmlp.setPyramidLevels(3);
1033  xmlp.setMaskBorder(maskBorder);
1036 
1037  try{
1038  std::cout << " *********** Parsing XML for MBT KLT Tracker ************ " << std::endl;
1039  xmlp.parse(configFile);
1040  }
1041  catch(...){
1042  vpERROR_TRACE("Can't open XML file \"%s\"\n ", configFile);
1043  throw vpException(vpException::ioError, "problem to parse configuration file.");
1044  }
1045 
1046  vpCameraParameters camera;
1047  xmlp.getCameraParameters(camera);
1048  setCameraParameters(camera);
1049 
1050  tracker.setMaxFeatures((int)xmlp.getMaxFeatures());
1051  tracker.setWindowSize((int)xmlp.getWindowSize());
1052  tracker.setQuality(xmlp.getQuality());
1055  tracker.setBlockSize((int)xmlp.getBlockSize());
1057  maskBorder = xmlp.getMaskBorder();
1060 
1061  //if(useScanLine)
1062  faces.getMbScanLineRenderer().setMaskBorder(maskBorder);
1063 
1064  if(xmlp.hasNearClippingDistance())
1066 
1067  if(xmlp.hasFarClippingDistance())
1069 
1070  if(xmlp.getFovClipping())
1072 
1073  useLodGeneral = xmlp.getLodState();
1076 
1077  applyLodSettingInConfig = false;
1078  if(this->getNbPolygon() > 0) {
1079  applyLodSettingInConfig = true;
1083  }
1084 
1085 #else
1086  vpTRACE("You need the libXML2 to read the config file %s", configFile);
1087 #endif
1088 }
1089 
1100 void
1102  const vpColor& col, const unsigned int thickness, const bool displayFullModel)
1103 {
1104  vpCameraParameters c = camera;
1105 
1106  if(clippingFlag > 3) // Contains at least one FOV constraint
1107  c.computeFov(I.getWidth(), I.getHeight());
1108 
1109  vpMbtDistanceKltPoints *kltpoly;
1110  vpMbtDistanceKltCylinder *kltPolyCylinder;
1111 
1112  // Previous version 12/08/2015
1113 // for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
1114 // kltpoly = *it;
1115 // kltpoly->polygon->changeFrame(cMo_);
1116 // kltpoly->polygon->computePolygonClipped(c);
1117 // }
1118  faces.computeClippedPolygons(cMo_,c);
1119 
1120  if(useScanLine && !displayFullModel)
1122 
1123  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
1124  kltpoly = *it;
1125 
1126  kltpoly->display(I,cMo_,camera,col,thickness,displayFullModel);
1127 
1128  if(displayFeatures && kltpoly->hasEnoughPoints() && kltpoly->polygon->isVisible() && kltpoly->isTracked()) {
1129  kltpoly->displayPrimitive(I);
1130 // faces[i]->displayNormal(I);
1131  }
1132  }
1133 
1134  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
1135  kltPolyCylinder = *it;
1136 
1137  kltPolyCylinder->display(I,cMo_,camera,col,thickness,displayFullModel);
1138 
1139  if(displayFeatures && kltPolyCylinder->isTracked() && kltPolyCylinder->hasEnoughPoints())
1140  kltPolyCylinder->displayPrimitive(I);
1141  }
1142 
1143  for(std::list<vpMbtDistanceCircle*>::const_iterator it=circles_disp.begin(); it!=circles_disp.end(); ++it){
1144  (*it)->display(I, cMo_, camera, col, thickness, displayFullModel);
1145  }
1146 
1147 #ifdef VISP_HAVE_OGRE
1148  if(useOgre)
1149  faces.displayOgre(cMo_);
1150 #endif
1151 }
1152 
1163 void
1165  const vpColor& col , const unsigned int thickness, const bool displayFullModel)
1166 {
1167  vpCameraParameters c = camera;
1168 
1169  if(clippingFlag > 3) // Contains at least one FOV constraint
1170  c.computeFov(I.getWidth(), I.getHeight());
1171 
1172  vpMbtDistanceKltPoints *kltpoly;
1173  vpMbtDistanceKltCylinder *kltPolyCylinder;
1174 
1175  // Previous version 12/08/2015
1176 // for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
1177 // kltpoly = *it;
1178 // kltpoly->polygon->changeFrame(cMo_);
1179 // kltpoly->polygon->computePolygonClipped(c);
1180 // }
1181  faces.computeClippedPolygons(cMo_,c);
1182 
1183  if(useScanLine && !displayFullModel)
1185 
1186  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
1187  kltpoly = *it;
1188 
1189  kltpoly->display(I,cMo_,camera,col,thickness,displayFullModel);
1190 
1191  if(displayFeatures && kltpoly->hasEnoughPoints() && kltpoly->polygon->isVisible() && kltpoly->isTracked()) {
1192  kltpoly->displayPrimitive(I);
1193 // faces[i]->displayNormal(I);
1194  }
1195  }
1196 
1197  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
1198  kltPolyCylinder = *it;
1199 
1200  kltPolyCylinder->display(I,cMo_,camera,col,thickness,displayFullModel);
1201 
1202  if(displayFeatures && kltPolyCylinder->isTracked() && kltPolyCylinder->hasEnoughPoints())
1203  kltPolyCylinder->displayPrimitive(I);
1204  }
1205 
1206  for(std::list<vpMbtDistanceCircle*>::const_iterator it=circles_disp.begin(); it!=circles_disp.end(); ++it){
1207  (*it)->display(I, cMo_, camera, col, thickness);
1208  }
1209 
1210 #ifdef VISP_HAVE_OGRE
1211  if(useOgre)
1212  faces.displayOgre(cMo_);
1213 #endif
1214 }
1215 
1224 void
1226 {
1227  unsigned int nbTotalPoints = 0;
1228  vpMbtDistanceKltPoints *kltpoly;
1229 // for (unsigned int i = 0; i < faces.size(); i += 1){
1230  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
1231  kltpoly = *it;
1232  if(kltpoly->polygon->isVisible() && kltpoly->isTracked() && kltpoly->polygon->getNbPoint() > 2 && kltpoly->hasEnoughPoints()){
1233  nbTotalPoints += kltpoly->getCurrentNumberPoints();
1234  }
1235  }
1236 
1237  vpMbtDistanceKltCylinder *kltPolyCylinder;
1238  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){
1239  kltPolyCylinder = *it;
1240  if(kltPolyCylinder->isTracked() && kltPolyCylinder->hasEnoughPoints())
1241  nbTotalPoints += kltPolyCylinder->getCurrentNumberPoints();
1242  }
1243 
1244  if(nbTotalPoints < 10){
1245  std::cerr << "test tracking failed (too few points to realize a good tracking)." << std::endl;
1247  "test tracking failed (too few points to realize a good tracking).");
1248  }
1249 }
1250 
1261 void
1262 vpMbKltTracker::initCylinder(const vpPoint& p1, const vpPoint &p2, const double radius, const int idFace,
1263  const std::string &/*name*/)
1264 {
1266  kltPoly->setCameraParameters(cam) ;
1267 
1268  kltPoly->buildFrom(p1,p2,radius);
1269 
1270  // Add the Cylinder BBox to the list of polygons
1271  kltPoly->listIndicesCylinderBBox.push_back(idFace+1);
1272  kltPoly->listIndicesCylinderBBox.push_back(idFace+2);
1273  kltPoly->listIndicesCylinderBBox.push_back(idFace+3);
1274  kltPoly->listIndicesCylinderBBox.push_back(idFace+4);
1275 
1276  kltPoly->hiddenface = &faces ;
1277  kltPoly->useScanLine = useScanLine;
1278  kltCylinders.push_back(kltPoly);
1279 }
1280 
1291 void
1292 vpMbKltTracker::initCircle(const vpPoint& p1, const vpPoint &p2, const vpPoint &p3, const double radius,
1293  const int /*idFace*/, const std::string &name)
1294 {
1295  addCircle(p1, p2, p3, radius, name);
1296 }
1297 
1307 void
1308 vpMbKltTracker::addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r, const std::string &name)
1309 {
1310  bool already_here = false ;
1311  vpMbtDistanceCircle *ci ;
1312 
1313 // for(std::list<vpMbtDistanceCircle*>::const_iterator it=circles_disp.begin(); it!=circles_disp[i].end(); ++it){
1314 // ci = *it;
1315 // if((samePoint(*(ci->p1),P1) && samePoint(*(ci->p2),P2) && samePoint(*(ci->p3),P3)) ||
1316 // (samePoint(*(ci->p1),P1) && samePoint(*(ci->p2),P3) && samePoint(*(ci->p3),P2)) ){
1317 // already_here = (std::fabs(ci->radius - r) < std::numeric_limits<double>::epsilon() * vpMath::maximum(ci->radius, r));
1318 // }
1319 // }
1320 
1321  if (!already_here){
1322  ci = new vpMbtDistanceCircle ;
1323 
1324  ci->setCameraParameters(cam);
1325  ci->setName(name);
1326  ci->buildFrom(P1, P2, P3, r);
1327  circles_disp.push_back(ci);
1328  }
1329 }
1330 
1340 void
1341 vpMbKltTracker::reInitModel(const vpImage<unsigned char>& I, const std::string &cad_name,
1342  const vpHomogeneousMatrix& cMo_, const bool verbose)
1343 {
1344  reInitModel(I, cad_name.c_str(), cMo_, verbose);
1345 }
1346 
1356 void
1358  const vpHomogeneousMatrix& cMo_, const bool verbose)
1359 {
1360  this->cMo.eye();
1361 
1362 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1363  if(cur != NULL){
1364  cvReleaseImage(&cur);
1365  cur = NULL;
1366  }
1367 #endif
1368 
1369  firstInitialisation = true;
1370 
1371  faces.reset();
1372 
1373  loadModel(cad_name, verbose);
1374  initFromPose(I, cMo_);
1375 }
1376 
1383 void
1384 vpMbKltTracker::setUseKltTracking(const std::string &name, const bool &useKltTracking)
1385 {
1386  vpMbtDistanceKltPoints *kltpoly;
1387  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){
1388  kltpoly = *it;
1389  if(kltpoly->polygon->getName() == name){
1390  kltpoly->setTracked(useKltTracking);
1391  }
1392  }
1393 }
1394 
1395 #elif !defined(VISP_BUILD_SHARED_LIBS)
1396 // Work arround to avoid warning: libvisp_mbt.a(vpMbKltTracker.cpp.o) has no symbols
1397 void dummy_vpMbKltTracker() {};
1398 #endif //VISP_HAVE_OPENCV
void setKltOpencv(const vpKltOpencv &t)
bool compute_interaction
If true, compute the interaction matrix at each iteration of the minimization. Otherwise, compute it only on the first iteration.
void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r, const std::string &name="")
virtual void track(const vpImage< unsigned char > &I)
unsigned int getCols() const
Definition: vpImage.h:180
vpMatrix get_K_inverse() const
void setWindowName(const Ogre::String &n)
Definition: vpAROgre.h:263
std::list< vpMbtDistanceKltPoints * > kltPolygons
int getPyramidLevels() const
Get the list of features id.
Definition: vpKltOpencv.h:127
unsigned int getMaskBorder() const
void setQuality(const double &q)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
vpMatrix covarianceMatrix
Covariance matrix.
Definition: vpMbTracker.h:129
void displayPrimitive(const vpImage< unsigned char > &_I)
void setTracked(const bool &track)
virtual ~vpMbKltTracker()
double getHarrisParam() const
static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls, const vpMatrix &W)
void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
unsigned int computeNbDetectedCurrent(const vpKltOpencv &_tracker)
void setCameraParameters(const vpCameraParameters &camera)
void init(const vpKltOpencv &_tracker)
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Compute the weights according a residue vector and a PsiFunction.
Definition: vpRobust.cpp:132
void removeOutliers(const vpColVector &weight, const double &threshold_outlier)
void setUseKltTracking(const std::string &name, const bool &useKltTracking)
void setHarrisFreeParameter(double harris_k)
int getMaxFeatures() const
Get the list of lost feature.
Definition: vpKltOpencv.h:113
void parse(const char *filename)
unsigned int getWidth() const
Definition: vpImage.h:161
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
void getCameraParameters(vpCameraParameters &_cam) const
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
Definition: vpMbTracker.h:144
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
void removeOutliers(const vpColVector &weight, const double &threshold_outlier)
Implementation of an homogeneous matrix and operations on such kind of matrices.
std::vector< int > listIndicesCylinderBBox
Pointer to the polygon that define a face.
double getHarrisFreeParameter() const
Get the free parameter of the Harris detector.
Definition: vpKltOpencv.h:109
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
#define vpERROR_TRACE
Definition: vpDebug.h:391
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
void setMaxFeatures(const int maxCount)
double percentGood
Percentage of good points, according to the initial number, that must have the tracker.
void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w)
virtual void initCylinder(const vpPoint &, const vpPoint &, const double, const int, const std::string &name="")
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
vpHomogeneousMatrix cMo
The current pose.
Definition: vpMbTracker.h:115
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
unsigned int getBlockSize() const
double getNearClippingDistance() const
void setOgreShowConfigDialog(const bool showConfigDialog)
bool modelInitialised
Flag used to ensure that the CAD model is loaded before the initialisation.
Definition: vpMbTracker.h:123
void setMinDistance(double minDistance)
void buildFrom(const vpPoint &_p1, const vpPoint &_p2, const vpPoint &_p3, const double r)
error that can be emited by ViSP classes.
Definition: vpException.h:73
vpMbScanLine & getMbScanLineRenderer()
vpPoint * p
corners in the object frame
Definition: vpPolygon3D.h:81
unsigned int getMaxFeatures() const
void init(const vpKltOpencv &_tracker, const vpHomogeneousMatrix &cMo)
bool useOgre
Use Ogre3d for visibility tests.
Definition: vpMbTracker.h:156
unsigned int getCols() const
Return the number of columns of the 2D array.
Definition: vpArray2D.h:154
bool getLodState() const
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
Definition of the vpSubMatrix vpSubMatrix class provides a mask on a vpMatrix all properties of vpMat...
Definition: vpSubMatrix.h:62
unsigned int setVisibleOgre(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
Definition: vpMbTracker.h:127
bool firstInitialisation
Flag to specify whether the init method is called the first or not (specific calls to realize in this...
virtual void reinit(const vpImage< unsigned char > &I)
Implementation of a polygon of the model containing points of interest. It is used by the model-based...
virtual void testTracking()
bool hasNearClippingDistance() const
Class that defines what is a point.
Definition: vpPoint.h:59
virtual void loadConfigFile(const std::string &configFile)
unsigned int getInitialNumberPoint() const
vpCameraParameters cam
The camera parameters.
Definition: vpMbTracker.h:113
void computeClippedPolygons(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam)
unsigned int setVisible(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angle, bool &changed)
Implementation of a rotation matrix and operations on such kind of matrices.
void setQuality(double qualityLevel)
vpHomogeneousMatrix ctTc0
The estimated displacement of the pose between the current instant and the initial position...
std::map< int, int > & getCurrentPointsInd()
double getFarClippingDistance() const
void initOgre(const vpCameraParameters &cam=vpCameraParameters())
bool hasFarClippingDistance() const
unsigned int computeNbDetectedCurrent(const vpKltOpencv &_tracker)
Implementation of an homography and operations on homographies.
Definition: vpHomography.h:179
vpAROgre * getOgreContext()
void changeFrame(const vpHomogeneousMatrix &cMo)
unsigned int getRows() const
Definition: vpImage.h:171
std::vector< vpImagePoint > getKltImagePoints() const
void setPyramidLevels(const unsigned int &pL)
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
vpColVector & normalize()
Parse an Xml file to extract configuration parameters of a Mbt Klt object.Data parser for the KLT mod...
Manage a circle used in the model-based tracker.
vpMatrix oJo
The Degrees of Freedom to estimate.
Definition: vpMbTracker.h:117
unsigned int getWindowSize() const
Error that can be emited by the vpTracker class and its derivates.
double getAngleDisappear() const
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:64
virtual void setCameraParameters(const vpCameraParameters &_cam)
void computePolygonClipped(const vpCameraParameters &cam=vpCameraParameters())
void computeInteractionMatrixAndResidu(const vpHomogeneousMatrix &cMc0, vpColVector &_R, vpMatrix &_J)
void setName(const std::string &circle_name)
std::string getName() const
Definition: vpMbtPolygon.h:101
vpMatrix AtA() const
Definition: vpMatrix.cpp:391
double getQuality() const
Get the parameter characterizing the minimal accepted quality of image corners.
Definition: vpKltOpencv.h:129
void changeFrame(const vpHomogeneousMatrix &cMo)
Definition: vpPlane.cpp:372
void displayPrimitive(const vpImage< unsigned char > &_I)
void setWindowSize(const unsigned int &w)
void diag(const double &val=1.0)
Definition: vpMatrix.cpp:539
bool useScanLine
Use Scanline for visibility tests.
Definition: vpMbTracker.h:159
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
#define vpTRACE
Definition: vpDebug.h:414
double minLineLengthThresholdGeneral
Minimum line length threshold for LOD mode (general setting)
Definition: vpMbTracker.h:177
void setAngleDisappear(const double &adisappear)
double getMinPolygonAreaThreshold() const
vpColVector m_error
Error s-s*.
Definition: vpMbTracker.h:139
void setTrackerId(int tid)
Does nothing. Just here for compat with previous releases that use OpenCV C api to do the tracking...
Definition: vpKltOpencv.h:149
unsigned int maskBorder
Erosion of the mask.
Generic class defining intrinsic camera parameters.
int getBlockSize() const
Get the size of the averaging block used to track the features.
Definition: vpKltOpencv.h:100
Implementation of a polygon of the model containing points of interest. It is used by the model-based...
void getFeature(const int &index, int &id, float &x, float &y) const
std::map< int, vpImagePoint > getKltImagePointsWithId() const
unsigned int getInitialNumberPoint() const
void extract(vpRotationMatrix &R) const
void setHarrisParam(const double &hp)
Implementation of a velocity twist matrix and operations on such kind of matrices.
vpMbtOptimizationMethod m_optimizationMethod
Optimization method used.
Definition: vpMbTracker.h:141
unsigned int getRows() const
Return the number of rows of the 2D array.
Definition: vpArray2D.h:152
void setMinDistance(const double &mD)
void initTracking(const cv::Mat &I, const cv::Mat &mask=cv::Mat())
double angleAppears
Angle used to detect a face appearance.
Definition: vpMbTracker.h:146
vpKltOpencv tracker
Points tracker.
void setInitialGuess(const std::vector< cv::Point2f > &guess_pts)
virtual bool isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo=false, const vpCameraParameters &cam=vpCameraParameters(), const vpImage< unsigned char > &I=vpImage< unsigned char >())
vpColVector getNormal() const
Definition: vpPlane.cpp:246
void setPyramidLevels(const int pyrMaxLevel)
std::list< vpMbtDistanceKltCylinder * > kltCylinders
bool useScanLine
Use scanline rendering.
double get_px() const
std::map< int, vpImagePoint > & getCurrentPoints()
static double rad(double deg)
Definition: vpMath.h:104
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
void buildFrom(const vpPoint &p1, const vpPoint &p2, const double &r)
double threshold_outlier
Threshold below which the weight associated to a point to consider this one as an outlier...
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
void preTracking(const vpImage< unsigned char > &I, unsigned int &nbInfos, unsigned int &nbFaceUsed)
cv::Mat cur
Temporary OpenCV image for fast conversion.
double lambda
The gain of the virtual visual servoing stage.
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)
double getMinLineLengthThreshold() const
void computeJTR(const vpMatrix &J, const vpColVector &R, vpColVector &JTR)
void setMaxFeatures(const unsigned int &mF)
void computeHomography(const vpHomogeneousMatrix &_cTc0, vpHomography &cHc0)
double sumSquare() const
virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, const double, const int, const std::string &name="")
void setWindowSize(const int winSize)
double getQuality() const
std::list< vpMbtDistanceCircle * > circles_disp
Vector of the circles used here only to display the full model.
double minPolygonAreaThresholdGeneral
Minimum polygon area threshold for LOD mode (general setting)
Definition: vpMbTracker.h:179
vpMatrix get_K() const
static double deg(double rad)
Definition: vpMath.h:97
virtual void setCameraParameters(const vpCameraParameters &_cam)
bool displayFeatures
If true, the features are displayed.
Definition: vpMbTracker.h:135
virtual void loadModel(const char *modelFile, const bool verbose=false)
void setCameraParameters(const vpCameraParameters &cam)
bool ogreShowConfigDialog
Definition: vpMbTracker.h:157
bool applyLodSettingInConfig
True if the CAO model is loaded before the call to loadConfigFile, (deduced by the number of polygons...
Definition: vpMbTracker.h:175
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void setAngleAppear(const double &aappear)
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV.
Definition: vpKltOpencv.h:75
vpHomogeneousMatrix inverse() const
void setBlockSize(const int blockSize)
static vpHomogeneousMatrix direct(const vpColVector &v)
int getNbFeatures() const
Get the number of current features.
Definition: vpKltOpencv.h:117
Contains an M-Estimator and various influence function.
Definition: vpRobust.h:59
double angleDisappears
Angle used to detect a face disappearance.
Definition: vpMbTracker.h:148
virtual unsigned int getNbPolygon() const
Definition: vpMbTracker.h:309
virtual void initFaceFromLines(vpMbtPolygon &polygon)
vpMbtPolygon * polygon
Pointer to the polygon that define a face.
unsigned int getHeight() const
Definition: vpImage.h:152
unsigned int getNbPoint() const
Definition: vpPolygon3D.h:135
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
Definition: vpMatrix.cpp:1756
virtual void setClipping(const unsigned int &flags)
virtual void init(const vpImage< unsigned char > &I)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
void setUseHarris(const int useHarrisDetector)
unsigned int getCurrentNumberPoints() const
void setBlockSize(const unsigned int &bs)
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:58
unsigned int clippingFlag
Flags specifying which clipping to used.
Definition: vpMbTracker.h:154
double getMinDistance() const
Get the minimal Euclidean distance between detected corners during initialization.
Definition: vpKltOpencv.h:115
void displayOgre(const vpHomogeneousMatrix &cMo)
double getAngleAppear() const
unsigned int getCurrentNumberPoints() const
void setThreshold(const double noise_threshold)
Definition: vpRobust.h:124
void updateMask(cv::Mat &mask, unsigned char _nb=255, unsigned int _shiftBorder=0)
virtual void setFarClippingDistance(const double &dist)
double getMinDistance() const
bool getFovClipping() const
void setIteration(const unsigned int iter)
Set iteration.
Definition: vpRobust.h:118
bool useLodGeneral
True if LOD mode is enabled.
Definition: vpMbTracker.h:173
void computeScanLineRender(const vpCameraParameters &cam, const unsigned int &w, const unsigned int &h)
void computeVVS(const unsigned int &nbInfos, vpColVector &w)
Class that consider the case of a translation vector.
void eye()
Definition: vpMatrix.cpp:194
bool isoJoIdentity
Boolean to know if oJo is identity (for fast computation)
Definition: vpMbTracker.h:119
void setMaskBorder(const unsigned int &mb)
void computeInteractionMatrixAndResidu(vpColVector &_R, vpMatrix &_J)
vpHomogeneousMatrix c0Mo
Initial pose.
int getWindowSize() const
Get the window size used to refine the corner locations.
Definition: vpKltOpencv.h:131
double getD() const
Definition: vpPlane.h:112
void track(const cv::Mat &I)
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)
unsigned int getPyramidLevels() const
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)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
bool useScanLine
Use scanline rendering.
void updateMask(cv::Mat &mask, unsigned char _nb=255, unsigned int _shiftBorder=0)
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:217
vpColVector m_w
Weights used in the robust scheme.
Definition: vpMbTracker.h:137
virtual void setLod(const bool useLod, const std::string &name="")
virtual void setNearClippingDistance(const double &dist)
void computeFov(const unsigned int &w, const unsigned int &h)