Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpMbEdgeKltMultiTracker.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2016 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://www.irisa.fr/lagadic/visp/visp.html 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  * http://www.irisa.fr/lagadic
24  *
25  * If you have questions regarding the use of this file, please contact
26  * INRIA at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  *
32  * Description:
33  * Model-based edge klt tracker with multiple cameras.
34  *
35  * Authors:
36  * Souriya Trinh
37  *
38  *****************************************************************************/
39 
45 #include <visp3/core/vpConfig.h>
46 
47 #if (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
48 
49 #include <visp3/core/vpTrackingException.h>
50 #include <visp3/core/vpVelocityTwistMatrix.h>
51 #include <visp3/mbt/vpMbEdgeKltMultiTracker.h>
52 
53 
59  compute_interaction(true), lambda(0.8), m_factorKLT(0.65), m_factorMBT(0.35),
60  thresholdKLT(2.), thresholdMBT(2.), maxIter(200),
61  m_mapOfCameraTransformationMatrix(), m_referenceCameraName("Camera") {
62  //Add default camera transformation matrix
64 }
65 
72  : vpMbEdgeMultiTracker(nbCameras), vpMbKltMultiTracker(nbCameras),
73  compute_interaction(true), lambda(0.8), m_factorKLT(0.65), m_factorMBT(0.35),
74  thresholdKLT(2.), thresholdMBT(2.), maxIter(200),
75  m_mapOfCameraTransformationMatrix(), m_referenceCameraName("Camera") {
76 
77  if(nbCameras == 0) {
78  throw vpException(vpTrackingException::fatalError, "Cannot construct a vpMbkltMultiTracker with no camera !");
79  } else if(nbCameras == 1) {
80  //Add default camera transformation matrix
82  } else if(nbCameras == 2) {
83  //Add default camera transformation matrix
86 
87  //Set by default the reference camera
88  m_referenceCameraName = "Camera1";
89  } else {
90  for(unsigned int i = 1; i <= nbCameras; i++) {
91  std::stringstream ss;
92  ss << "Camera" << i;
93 
94  //Add default camera transformation matrix
96  }
97 
98  //Set by default the reference camera to the first one
100  }
101 }
102 
108 vpMbEdgeKltMultiTracker::vpMbEdgeKltMultiTracker(const std::vector<std::string> &cameraNames)
109  : vpMbEdgeMultiTracker(cameraNames), vpMbKltMultiTracker(cameraNames),
110  compute_interaction(true), lambda(0.8), m_factorKLT(0.65), m_factorMBT(0.35),
111  thresholdKLT(2.), thresholdMBT(2.), maxIter(200),
112  m_mapOfCameraTransformationMatrix(), m_referenceCameraName("Camera") {
113  //Set by default the reference camera
114  m_referenceCameraName = cameraNames.front();
115 }
116 
118 }
119 
120 void vpMbEdgeKltMultiTracker::computeVVS(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
121  std::map<std::string, unsigned int> &mapOfNumberOfRows, std::map<std::string, unsigned int> &mapOfNbInfos,
122  vpColVector &w_mbt, vpColVector &w_klt, const unsigned int lvl) {
123 
124  //Factor for MBT, each factor for each camera are appended
125  vpColVector factor;
126  //Indicate for each row in the final interaction matrix or residual or weight for the MBT part
127  //whether the considered features is a line, a cylinder or a circle
128  std::vector<FeatureType> indexOfFeatures;
129  std::map<std::string, unsigned int> mapOfNumberOfLines;
130  std::map<std::string, unsigned int> mapOfNumberOfCylinders;
131  std::map<std::string, unsigned int> mapOfNumberOfCircles;
132  //Get the number of rows for the MBT part
133  //Get also the number of rows, lines, cylinders and circle for each camera
134  unsigned int nbrow = trackFirstLoop(mapOfImages, factor, indexOfFeatures,
135  mapOfNumberOfRows, mapOfNumberOfLines, mapOfNumberOfCylinders, mapOfNumberOfCircles, lvl);
136 
137 // unsigned int nbInfos = w_klt.size() / 2;
138  unsigned int nbInfos = 0;
139  for(std::map<std::string, unsigned int>::const_iterator it = mapOfNbInfos.begin(); it != mapOfNbInfos.end(); ++it) {
140  nbInfos += it->second;
141  }
142 
143  if(nbInfos < 4 && nbrow < 4) {
144  throw vpTrackingException(vpTrackingException::notEnoughPointError, "\n\t\t Error-> not enough data");
145  } else if(nbrow < 4) {
146  nbrow = 0;
147  }
148 
149 // double factorMBT = 1.0;
150 // double factorKLT = 1.0;
151 //
152 // //More efficient weight repartition for hybrid tracker should come soon...
155 // factorMBT = 0.35;
156 // factorKLT = 0.65;
157 
158  double factorMBT = m_factorMBT;
159  double factorKLT = m_factorKLT;
160  if (nbrow < 4) {
161  factorKLT = 1.;
162  std::cerr << "There are less than 4 KLT features, set factorKLT = 1. !" << std::endl;
163  }
164 
165  if (nbInfos < 4) {
166  factorMBT = 1.;
167  std::cerr << "There are less than 4 moving edges, set factorMBT = 1. !" << std::endl;
168  nbInfos = 0;
169  }
170 
171 
172  vpHomogeneousMatrix cMoPrev;
173  vpHomogeneousMatrix ctTc0_Prev;
174  //Error vector for MBT + KLT for the previous iteration
175  vpColVector m_error_prev(2*nbInfos + nbrow);
176  //Weighting vector for MBT + KLT for the previous iteration
177  vpColVector m_w_prev(2*nbInfos + nbrow);
178  double mu = 0.01;
179 
180  //Create the map of VelocityTwistMatrices
181  std::map<std::string, vpVelocityTwistMatrix> mapOfVelocityTwist;
182  for(std::map<std::string, vpHomogeneousMatrix>::const_iterator it = m_mapOfCameraTransformationMatrix.begin();
183  it != m_mapOfCameraTransformationMatrix.end(); ++it) {
185  cVo.buildFrom(it->second);
186  mapOfVelocityTwist[it->first] = cVo;
187  }
188 
189  //Map of robust for edge trackers
190  //Individual weights for each primitives and for each camera
191  std::map<std::string, vpRobust> mapOfEdgeRobustLines;
192  std::map<std::string, vpRobust> mapOfEdgeRobustCylinders;
193  std::map<std::string, vpRobust> mapOfEdgeRobustCircles;
194  //Init map of robust
195  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
196  it != m_mapOfEdgeTrackers.end(); ++it) {
197  mapOfEdgeRobustLines[it->first] = vpRobust(mapOfNumberOfLines[it->first]);
198  mapOfEdgeRobustLines[it->first].setIteration(0);
199 
200  mapOfEdgeRobustCylinders[it->first] = vpRobust(mapOfNumberOfCylinders[it->first]);
201  mapOfEdgeRobustCylinders[it->first].setIteration(0);
202 
203  mapOfEdgeRobustCircles[it->first] = vpRobust(mapOfNumberOfCircles[it->first]);
204  mapOfEdgeRobustCircles[it->first].setIteration(0);
205  }
206 
207  //Map of robust for KLT trackers
208  std::map<std::string, vpRobust> mapOfKltRobusts;
209  for(std::map<std::string, vpMbKltTracker*>::const_iterator it = m_mapOfKltTrackers.begin();
210  it != m_mapOfKltTrackers.end(); ++it) {
211  mapOfKltRobusts[it->first] = vpRobust(2*mapOfNbInfos[it->first]);
212  }
213 
214  //Individual primitive residuals for MBT for all the cameras
215  vpColVector error_lines;
216  vpColVector error_cylinders;
217  vpColVector error_circles;
218 
219  //Individual primitive weights for MBT for all the cameras
220  vpColVector w_lines;
221  vpColVector w_cylinders;
222  vpColVector w_circles;
223 
224  //Map of primitive weights for each camera and for MBT
225  std::map<std::string, vpColVector> mapOfWeightLines;
226  std::map<std::string, vpColVector> mapOfWeightCylinders;
227  std::map<std::string, vpColVector> mapOfWeightCircles;
228 
229  //Variables used in the minimization process
230  double residu = 0;
231  double residu_1 = -1;
232  unsigned int iter = 0;
233 
234  vpMatrix *L;
235  vpColVector *R;
236  vpMatrix L_true;
237  vpMatrix LVJ_true;
238  vpColVector w_true;
239 
240  vpColVector v;
241  vpHomography H;
242 
243  vpMatrix LTL;
244  vpColVector LTR;
245 
246  while( ((int)((residu - residu_1)*1e8) !=0 ) && (iter<maxIter) ){
247  L = new vpMatrix();
248  R = new vpColVector();
249 
250  //MBT
251  error_lines.resize(0);
252  error_cylinders.resize(0);
253  error_circles.resize(0);
254 
255  std::map<std::string, vpColVector> mapOfErrorLines;
256  std::map<std::string, vpColVector> mapOfErrorCylinders;
257  std::map<std::string, vpColVector> mapOfErrorCircles;
258 
259  vpColVector R_mbt;
260  vpMatrix L_mbt;
261  if(nbrow >= 4) {
262  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
263  it != m_mapOfEdgeTrackers.end(); ++it) {
264  vpMatrix L_tmp(mapOfNumberOfRows[it->first], 6);
265  vpColVector error_lines_tmp(mapOfNumberOfLines[it->first]);
266  vpColVector error_cylinders_tmp(mapOfNumberOfCylinders[it->first]);
267  vpColVector error_circles_tmp(mapOfNumberOfCircles[it->first]);
268 
269  //Set the corresponding cMo for the current camera
270  it->second->cMo = m_mapOfCameraTransformationMatrix[it->first]*cMo;
271 
272  vpColVector R_tmp;
273  R_tmp.resize(mapOfNumberOfRows[it->first]);
274  it->second->computeVVSSecondPhase(*mapOfImages[it->first], L_tmp, error_lines_tmp,
275  error_cylinders_tmp, error_circles_tmp, R_tmp, 0);
276  //Set the computed weight
277  it->second->m_w = R_tmp;
278  L_tmp = L_tmp*mapOfVelocityTwist[it->first];
279 
280  //Stack interaction matrix for MBT
281  L_mbt.stack(L_tmp);
282  //Stack residual for MBT
283  R_mbt.stack(R_tmp);
284 
285  error_lines.stack(error_lines_tmp);
286  error_cylinders.stack(error_cylinders_tmp);
287  error_circles.stack(error_circles_tmp);
288 
289  mapOfErrorLines[it->first] = error_lines_tmp;
290  mapOfErrorCylinders[it->first] = error_cylinders_tmp;
291  mapOfErrorCircles[it->first] = error_circles_tmp;
292  }
293  }
294 
295  //KLT
296  vpColVector R_klt;
297  vpMatrix L_klt;
298  for(std::map<std::string, vpMbKltTracker*>::const_iterator it1 = m_mapOfKltTrackers.begin();
299  it1 != m_mapOfKltTrackers.end(); ++it1) {
300  if(mapOfNbInfos[it1->first] > 0) {
301  unsigned int shift = 0;
302  vpColVector R_current; // residu for the current camera for KLT
303  vpMatrix L_current; // interaction matrix for the current camera for KLT
304  vpHomography H_current;
305 
306  R_current.resize(2 * mapOfNbInfos[it1->first]);
307  L_current.resize(2 * mapOfNbInfos[it1->first], 6, 0);
308 
309  //Use the ctTc0 variable instead of the formula in the monocular case
310  //to ensure that we have the same result than vpMbKltTracker
311  //as some slight differences can occur due to numerical imprecision
312  if(m_mapOfKltTrackers.size() == 1) {
313  computeVVSInteractionMatrixAndResidu(shift, R_current, L_current, H_current,
314  it1->second->kltPolygons, it1->second->kltCylinders, ctTc0);
315  } else {
316  vpHomogeneousMatrix c_curr_tTc_curr0 = m_mapOfCameraTransformationMatrix[it1->first] *
317  cMo * it1->second->c0Mo.inverse();
318  computeVVSInteractionMatrixAndResidu(shift, R_current, L_current, H_current,
319  it1->second->kltPolygons, it1->second->kltCylinders, c_curr_tTc_curr0);
320  }
321 
322  //Transform the current interaction matrix with VelocityTwistMatrix
323  L_current = L_current*mapOfVelocityTwist[it1->first];
324 
325  //Stack residual and interaction matrix
326  R_klt.stack(R_current);
327  L_klt.stack(L_current);
328  }
329  }
330 
331 
332  bool reStartFromLastIncrement = false;
334  if( m_error.sumSquare()/(double)(2*nbInfos + nbrow) > m_error_prev.sumSquare()/(double)(2*nbInfos + nbrow) ) {
335  mu *= 10.0;
336 
337  if(mu > 1.0) {
338  throw vpTrackingException(vpTrackingException::fatalError, "Optimization diverged");
339  }
340 
341  cMo = cMoPrev;
342  m_error = m_error_prev;
343  m_w = m_w_prev;
344  ctTc0 = ctTc0_Prev;
345  reStartFromLastIncrement = true;
346  }
347  }
348 
349  if(iter == 0) {
350  m_w.resize(nbrow + 2*nbInfos);
351  m_w = 1;
352 
353  w_true.resize(nbrow + 2*nbInfos);
354  }
355 
356  if(!reStartFromLastIncrement) {
357  //MBT
358  w_lines.resize(0);
359  w_cylinders.resize(0);
360  w_circles.resize(0);
361 
362  //Compute the weights for MBT
363  computeVVSSecondPhaseWeights(iter, nbrow, w_mbt, w_lines, w_cylinders, w_circles, mapOfNumberOfLines,
364  mapOfNumberOfCylinders, mapOfNumberOfCircles, mapOfWeightLines, mapOfWeightCylinders, mapOfWeightCircles,
365  mapOfErrorLines, mapOfErrorCylinders, mapOfErrorCircles, mapOfEdgeRobustLines, mapOfEdgeRobustCylinders,
366  mapOfEdgeRobustCircles, thresholdMBT);
367 
368  for(unsigned int cpt = 0, cpt_lines = 0, cpt_cylinders = 0, cpt_circles = 0; cpt < nbrow; cpt++) {
369  switch(indexOfFeatures[cpt]) {
370  case LINE:
371  w_mbt[cpt] = w_lines[cpt_lines];
372  cpt_lines++;
373  break;
374 
375  case CYLINDER:
376  w_mbt[cpt] = w_cylinders[cpt_cylinders];
377  cpt_cylinders++;
378  break;
379 
380  case CIRCLE:
381  w_mbt[cpt] = w_circles[cpt_circles];
382  cpt_circles++;
383  break;
384 
385  default:
386  std::cerr << "Problem with feature type !" << std::endl;
387  break;
388  }
389  }
390 
391  //KLT
392  vpColVector w_true_klt; //not used
393  //Compute the weights for KLT
394  computeVVSWeights(iter, nbInfos, mapOfNbInfos, R_klt, w_true_klt, w_klt, mapOfKltRobusts, thresholdKLT);
395 
396 
397  //Stack MBT first and then KLT
398  /* robust */
399  if(nbrow > 3) {
400  //Stack interaction matrix and residual from MBT
401  L->stack(L_mbt);
402  R->stack(R_mbt);
403  }
404 
405  if(nbInfos > 3) {
406  //Stack interaction matrix and residual from KLT
407  L->stack(L_klt);
408  R->stack(R_klt);
409  }
410 
411  //Set weight for m_w with the good weighting between MBT and KLT
412  unsigned int cpt = 0;
413  while( cpt < (nbrow + 2*nbInfos) ) {
414  if(cpt < (unsigned int) nbrow) {
415  m_w[cpt] = ((w_mbt[cpt] * factor[cpt]) * factorMBT);
416  }
417  else {
418  m_w[cpt] = (w_klt[cpt-nbrow] * factorKLT);
419  }
420  cpt++;
421  }
422 
423  m_error = (*R);
424  if(computeCovariance) {
425  L_true = (*L);
426  if(!isoJoIdentity) {
428  cVo.buildFrom(cMo);
429  LVJ_true = ( (*L)*cVo*oJo );
430  }
431  }
432 
433  residu_1 = residu;
434  residu = 0;
435  double num = 0;
436  double den = 0;
437  for (unsigned int i = 0; i < R->getRows(); i++) {
438  num += m_w[i]*vpMath::sqr((*R)[i]);
439  den += m_w[i];
440 
441  w_true[i] = m_w[i];
442  (*R)[i] *= m_w[i];
443  if(compute_interaction) {
444  for (unsigned int j = 0; j < 6; j++) {
445  (*L)[i][j] *= m_w[i];
446  }
447  }
448  }
449 
450  residu = sqrt(num/den);
451 
452  if(isoJoIdentity) {
453  LTL = L->AtA();
454  computeJTR(*L, *R, LTR);
455 
456  switch(m_optimizationMethod) {
458  {
459  vpMatrix LMA(LTL.getRows(), LTL.getCols());
460  LMA.eye();
461  vpMatrix LTLmuI = LTL + (LMA*mu);
462  v = -lambda*LTLmuI.pseudoInverse(LTLmuI.getRows()*std::numeric_limits<double>::epsilon())*LTR;
463 
464  if(iter != 0) {
465  mu /= 10.0;
466  }
467 
468  m_error_prev = m_error;
469  m_w_prev = m_w;
470  break;
471  }
473  default:
474  v = -lambda * LTL.pseudoInverse(LTL.getRows()*std::numeric_limits<double>::epsilon()) * LTR;
475  break;
476  }
477  }
478  else {
480  cVo.buildFrom(cMo);
481  vpMatrix LVJ = ((*L)*cVo*oJo);
482  vpMatrix LVJTLVJ = (LVJ).AtA();
483  vpColVector LVJTR;
484  computeJTR(LVJ, *R, LVJTR);
485 
486  switch(m_optimizationMethod) {
488  {
489  vpMatrix LMA(LVJTLVJ.getRows(), LVJTLVJ.getCols());
490  LMA.eye();
491  vpMatrix LTLmuI = LVJTLVJ + (LMA*mu);
492  v = -lambda*LTLmuI.pseudoInverse(LTLmuI.getRows()*std::numeric_limits<double>::epsilon())*LVJTR;
493  v = cVo * v;
494 
495  if(iter != 0) {
496  mu /= 10.0;
497  }
498 
499  m_error_prev = m_error;
500  m_w_prev = m_w;
501  break;
502  }
504  default:
505  {
506  v = -lambda*LVJTLVJ.pseudoInverse(LVJTLVJ.getRows()*std::numeric_limits<double>::epsilon())*LVJTR;
507  v = cVo * v;
508  break;
509  }
510  }
511  }
512 
513  cMoPrev = cMo;
514  ctTc0_Prev = ctTc0;
516  cMo = ctTc0 * c0Mo;
517  }
518 
519  iter++;
520 
521  delete L;
522  delete R;
523  }
524 
525  if(computeCovariance) {
526  vpMatrix D;
527  D.diag(w_true);
528 
529  // Note that here the covariance is computed on cMoPrev for time computation efficiency
530  if(isoJoIdentity) {
532  }
533  else {
535  }
536  }
537 }
538 
550  const vpCameraParameters &cam_, const vpColor& col, const unsigned int thickness,
551  const bool displayFullModel) {
552  vpMbEdgeMultiTracker::display(I, cMo_, cam_, col, thickness, displayFullModel);
553 // vpMbKltMultiTracker::display(I, cMo_, cam_, col, thickness, displayFullModel);
554 
555  //Display only features for KLT trackers
556  for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt = m_mapOfKltTrackers.begin();
557  it_klt != m_mapOfKltTrackers.end(); ++it_klt) {
558 
559  vpMbtDistanceKltPoints *kltpoly;
560  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it_pts = it_klt->second->kltPolygons.begin();
561  it_pts != it_klt->second->kltPolygons.end(); ++it_pts){
562  kltpoly = *it_pts;
563  if(displayFeatures && kltpoly->hasEnoughPoints() && kltpoly->isTracked() && kltpoly->polygon->isVisible()) {
564  kltpoly->displayPrimitive(I);
565  }
566  }
567 
568  vpMbtDistanceKltCylinder *kltPolyCylinder;
569  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it_cyl = it_klt->second->kltCylinders.begin();
570  it_cyl != it_klt->second->kltCylinders.end(); ++it_cyl){
571  kltPolyCylinder = *it_cyl;
572  if(displayFeatures && kltPolyCylinder->isTracked() && kltPolyCylinder->hasEnoughPoints())
573  kltPolyCylinder->displayPrimitive(I);
574  }
575  }
576 }
577 
589  const vpCameraParameters &cam_, const vpColor& color , const unsigned int thickness,
590  const bool displayFullModel) {
591  vpMbEdgeMultiTracker::display(I, cMo_, cam_, color, thickness, displayFullModel);
592 // vpMbKltMultiTracker::display(I, cMo_, cam_, color, thickness, displayFullModel);
593 
594  //Display only features for KLT trackers
595  for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt = m_mapOfKltTrackers.begin();
596  it_klt != m_mapOfKltTrackers.end(); ++it_klt) {
597 
598  vpMbtDistanceKltPoints *kltpoly;
599  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it_pts = it_klt->second->kltPolygons.begin();
600  it_pts != it_klt->second->kltPolygons.end(); ++it_pts){
601  kltpoly = *it_pts;
602  if(displayFeatures && kltpoly->hasEnoughPoints() && kltpoly->isTracked() && kltpoly->polygon->isVisible()) {
603  kltpoly->displayPrimitive(I);
604  }
605  }
606 
607  vpMbtDistanceKltCylinder *kltPolyCylinder;
608  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it_cyl = it_klt->second->kltCylinders.begin();
609  it_cyl != it_klt->second->kltCylinders.end(); ++it_cyl){
610  kltPolyCylinder = *it_cyl;
611  if(displayFeatures && kltPolyCylinder->isTracked() && kltPolyCylinder->hasEnoughPoints())
612  kltPolyCylinder->displayPrimitive(I);
613  }
614  }
615 }
616 
631  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1,
632  const vpCameraParameters &cam2, const vpColor& color, const unsigned int thickness,
633  const bool displayFullModel) {
634  vpMbEdgeMultiTracker::display(I1, I2, c1Mo, c2Mo, cam1, cam2, color, thickness, displayFullModel);
635 // vpMbKltMultiTracker::display(I1, I2, c1Mo, c2Mo, cam1, cam2, color, thickness, displayFullModel);
636 
637  //Display only features for KLT trackers
638  bool first = true;
639  for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt = m_mapOfKltTrackers.begin();
640  it_klt != m_mapOfKltTrackers.end(); ++it_klt) {
641  vpMbtDistanceKltPoints *kltpoly;
642  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it_pts = it_klt->second->kltPolygons.begin();
643  it_pts != it_klt->second->kltPolygons.end(); ++it_pts){
644  kltpoly = *it_pts;
645  if(displayFeatures && kltpoly->hasEnoughPoints() && kltpoly->isTracked() && kltpoly->polygon->isVisible()) {
646  if(first) {
647  kltpoly->displayPrimitive(I1);
648  } else {
649  kltpoly->displayPrimitive(I2);
650  }
651  }
652  }
653 
654  vpMbtDistanceKltCylinder *kltPolyCylinder;
655  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it_cyl = it_klt->second->kltCylinders.begin();
656  it_cyl != it_klt->second->kltCylinders.end(); ++it_cyl){
657  kltPolyCylinder = *it_cyl;
658  if(displayFeatures && kltPolyCylinder->isTracked() && kltPolyCylinder->hasEnoughPoints()) {
659  if(first) {
660  kltPolyCylinder->displayPrimitive(I1);
661  } else {
662  kltPolyCylinder->displayPrimitive(I2);
663  }
664  }
665  }
666 
667  first = false;
668  }
669 }
670 
685  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1,
686  const vpCameraParameters &cam2, const vpColor& color, const unsigned int thickness,
687  const bool displayFullModel) {
688  vpMbEdgeMultiTracker::display(I1, I2, c1Mo, c2Mo, cam1, cam2, color, thickness, displayFullModel);
689 // vpMbKltMultiTracker::display(I1, I2, c1Mo, c2Mo, cam1, cam2, color, thickness, displayFullModel);
690 
691  //Display only features for KLT trackers (not the model)
692  bool first = true;
693  for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt = m_mapOfKltTrackers.begin();
694  it_klt != m_mapOfKltTrackers.end(); ++it_klt) {
695  vpMbtDistanceKltPoints *kltpoly;
696  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it_pts = it_klt->second->kltPolygons.begin();
697  it_pts != it_klt->second->kltPolygons.end(); ++it_pts){
698  kltpoly = *it_pts;
699  if(displayFeatures && kltpoly->hasEnoughPoints() && kltpoly->isTracked() && kltpoly->polygon->isVisible()) {
700  if(first) {
701  kltpoly->displayPrimitive(I1);
702  } else {
703  kltpoly->displayPrimitive(I2);
704  }
705  }
706  }
707 
708  vpMbtDistanceKltCylinder *kltPolyCylinder;
709  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it_cyl = it_klt->second->kltCylinders.begin();
710  it_cyl != it_klt->second->kltCylinders.end(); ++it_cyl){
711  kltPolyCylinder = *it_cyl;
712  if(displayFeatures && kltPolyCylinder->isTracked() && kltPolyCylinder->hasEnoughPoints()) {
713  if(first) {
714  kltPolyCylinder->displayPrimitive(I1);
715  } else {
716  kltPolyCylinder->displayPrimitive(I2);
717  }
718  }
719  }
720 
721  first = false;
722  }
723 }
724 
735 void vpMbEdgeKltMultiTracker::display(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
736  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
737  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters,
738  const vpColor& col, const unsigned int thickness, const bool displayFullModel) {
739  vpMbEdgeMultiTracker::display(mapOfImages, mapOfCameraPoses, mapOfCameraParameters, col, thickness, displayFullModel);
740 // vpMbKltMultiTracker::display(mapOfImages, mapOfCameraPoses, mapOfCameraParameters, col, thickness, displayFullModel);
741 
742  //Display only features for KLT trackers (not the model)
743  for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt = m_mapOfKltTrackers.begin();
744  it_klt != m_mapOfKltTrackers.end(); ++it_klt) {
745 
746  std::map<std::string, const vpImage<unsigned char> *>::const_iterator it_img = mapOfImages.find(it_klt->first);
747  if(it_img != mapOfImages.end()) {
748  vpMbtDistanceKltPoints *kltpoly;
749  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it_pts = it_klt->second->kltPolygons.begin();
750  it_pts != it_klt->second->kltPolygons.end(); ++it_pts) {
751  kltpoly = *it_pts;
752  if(displayFeatures && kltpoly->hasEnoughPoints() && kltpoly->isTracked() && kltpoly->polygon->isVisible()) {
753  kltpoly->displayPrimitive( *(it_img->second) );
754  }
755  }
756 
757  vpMbtDistanceKltCylinder *kltPolyCylinder;
758  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it_cyl = it_klt->second->kltCylinders.begin();
759  it_cyl != it_klt->second->kltCylinders.end(); ++it_cyl) {
760  kltPolyCylinder = *it_cyl;
761  if(displayFeatures && kltPolyCylinder->isTracked() && kltPolyCylinder->hasEnoughPoints())
762  kltPolyCylinder->displayPrimitive( *(it_img->second) );
763  }
764  }
765  }
766 }
767 
778 void vpMbEdgeKltMultiTracker::display(const std::map<std::string, const vpImage<vpRGBa> *> &mapOfImages,
779  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
780  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters,
781  const vpColor& col, const unsigned int thickness, const bool displayFullModel) {
782  vpMbEdgeMultiTracker::display(mapOfImages, mapOfCameraPoses, mapOfCameraParameters, col, thickness, displayFullModel);
783 // vpMbKltMultiTracker::display(mapOfImages, mapOfCameraPoses, mapOfCameraParameters, col, thickness, displayFullModel);
784 
785  //Display only features for KLT trackers (not the model)
786  for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt = m_mapOfKltTrackers.begin();
787  it_klt != m_mapOfKltTrackers.end(); ++it_klt) {
788 
789  std::map<std::string, const vpImage<vpRGBa> *>::const_iterator it_img = mapOfImages.find(it_klt->first);
790  if(it_img != mapOfImages.end()) {
791  vpMbtDistanceKltPoints *kltpoly;
792  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it_pts = it_klt->second->kltPolygons.begin();
793  it_pts != it_klt->second->kltPolygons.end(); ++it_pts){
794  kltpoly = *it_pts;
795  if(displayFeatures && kltpoly->hasEnoughPoints() && kltpoly->isTracked() && kltpoly->polygon->isVisible()) {
796  kltpoly->displayPrimitive( *(it_img->second) );
797  }
798  }
799 
800  vpMbtDistanceKltCylinder *kltPolyCylinder;
801  for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it_cyl = it_klt->second->kltCylinders.begin();
802  it_cyl != it_klt->second->kltCylinders.end(); ++it_cyl){
803  kltPolyCylinder = *it_cyl;
804  if(displayFeatures && kltPolyCylinder->isTracked() && kltPolyCylinder->hasEnoughPoints())
805  kltPolyCylinder->displayPrimitive( *(it_img->second) );
806  }
807  }
808  }
809 }
810 
816 std::vector<std::string> vpMbEdgeKltMultiTracker::getCameraNames() const {
818 }
819 
826  camera = this->cam;
827 }
828 
836  //We could use either the vpMbEdgeMultiTracker or vpMbKltMultiTracker class
838 }
839 
846 void vpMbEdgeKltMultiTracker::getCameraParameters(const std::string &cameraName, vpCameraParameters &camera) const {
847  //We could use either the vpMbEdgeMultiTracker or vpMbKltMultiTracker class
848  vpMbEdgeMultiTracker::getCameraParameters(cameraName, camera);
849 }
850 
856 void vpMbEdgeKltMultiTracker::getCameraParameters(std::map<std::string, vpCameraParameters> &mapOfCameraParameters) const {
857  //Clear the input map
858  mapOfCameraParameters.clear();
859 
860  //We could use either the vpMbEdgeMultiTracker or vpMbKltMultiTracker class
861  vpMbEdgeMultiTracker::getCameraParameters(mapOfCameraParameters);
862 }
863 
870 unsigned int vpMbEdgeKltMultiTracker::getClipping(const std::string &cameraName) const {
871  std::map<std::string, vpMbKltTracker *>::const_iterator it = m_mapOfKltTrackers.find(cameraName);
872  if(it != m_mapOfKltTrackers.end()) {
873  //Return the clipping flags for m_mapOfKltTrackers as it should be the same for the
874  //same camera in m_mapOfEdgeTrackers
875  return it->second->getClipping();
876  } else {
877  std::cerr << "Cannot find camera: " << cameraName << std::endl;
878  }
879 
880  return vpMbTracker::getClipping();
881 }
882 
884  std::cerr << "Return the wrong faces reference !" << std::endl;
885  std::cerr << "Use vpMbEdgeKltMultiTracker::getEdgeFaces or "
886  "vpMbEdgeKltMultiTracker::getKltFaces instead !" << std::endl;
887 
888  return faces;
889 }
890 
897  return vpMbEdgeMultiTracker::getFaces(cameraName);
898 }
899 
905 std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > vpMbEdgeKltMultiTracker::getEdgeFaces() const {
907 }
908 
915  return vpMbKltMultiTracker::getFaces(cameraName);
916 }
917 
923 std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > vpMbEdgeKltMultiTracker::getKltFaces() const {
925 }
926 
928  std::cerr << "Use vpMbEdgeKltMultiTracker::getEdgeMultiNbPolygon or "
929  "vpMbEdgeKltMultiTracker::getKltMultiNbPolygon instead !" << std::endl;
930  return 0;
931 }
932 
938 std::map<std::string, unsigned int> vpMbEdgeKltMultiTracker::getEdgeMultiNbPolygon() const {
940 }
941 
947 std::map<std::string, unsigned int> vpMbEdgeKltMultiTracker::getKltMultiNbPolygon() const {
949 }
950 
958  //We could use either the vpMbEdgeMultiTracker or vpMbKltMultiTracker class
959  vpMbEdgeMultiTracker::getPose(c1Mo, c2Mo);
960 }
961 
970 void vpMbEdgeKltMultiTracker::getPose(const std::string &cameraName, vpHomogeneousMatrix &cMo_) const {
971  //We could use either the vpMbEdgeMultiTracker or vpMbKltMultiTracker class
972  vpMbEdgeMultiTracker::getPose(cameraName, cMo_);
973 }
974 
980 void vpMbEdgeKltMultiTracker::getPose(std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) const {
981  //Clear the map
982  mapOfCameraPoses.clear();
983 
984  //We could use either the vpMbEdgeMultiTracker or vpMbKltMultiTracker class
985  vpMbEdgeMultiTracker::getPose(mapOfCameraPoses);
986 }
987 
989  if(!modelInitialised){
990  throw vpException(vpTrackingException::initializationError, "model not initialized");
991  }
992 }
993 
994 #ifdef VISP_HAVE_MODULE_GUI
995 
1004 void vpMbEdgeKltMultiTracker::initClick(const vpImage<unsigned char>& I, const std::vector<vpPoint> &points3D_list,
1005  const std::string &displayFile) {
1006  //Cannot use directly set pose for KLT as it is different than for the edge case
1007  //It moves the KLT points instead of detecting new KLT points
1008  vpMbKltMultiTracker::initClick(I, points3D_list, displayFile);
1009 
1010  //Set pose for Edge (setPose or initFromPose is equivalent with vpMbEdgeTracker)
1011  //And it avoids to click a second time
1013 }
1014 
1035 void vpMbEdgeKltMultiTracker::initClick(const vpImage<unsigned char>& I, const std::string& initFile, const bool displayHelp) {
1036  //Cannot use directly set pose for KLT as it is different than for the edge case
1037  //It moves the KLT points instead of detecting new KLT points
1038  vpMbKltMultiTracker::initClick(I, initFile, displayHelp);
1039 
1040  //Set pose for Edge (setPose or initFromPose is equivalent with vpMbEdgeTracker)
1041  //And it avoids to click a second time
1043 }
1044 
1069  const std::string& initFile1, const std::string& initFile2, const bool displayHelp, const bool firstCameraIsReference) {
1070  vpMbKltMultiTracker::initClick(I1, I2, initFile1, initFile2, displayHelp, firstCameraIsReference);
1071 
1072  //Get c2Mo
1073  vpHomogeneousMatrix c2Mo;
1074  std::map<std::string, vpMbKltTracker *>::const_iterator it_klt = m_mapOfKltTrackers.begin();
1075  if(firstCameraIsReference) {
1076  ++it_klt;
1077  it_klt->second->getPose(c2Mo);
1078  } else {
1079  it_klt->second->getPose(c2Mo);
1080  }
1081 
1082  //Set pose for Edge (setPose or initFromPose is equivalent with vpMbEdgeTracker)
1083  vpMbEdgeMultiTracker::setPose(I1, I2, cMo, c2Mo, firstCameraIsReference);
1084 }
1085 
1107 void vpMbEdgeKltMultiTracker::initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1108  const std::string &initFile, const bool displayHelp) {
1109  vpMbKltMultiTracker::initClick(mapOfImages, initFile, displayHelp);
1110 
1111  //Get pose for all the cameras
1112  std::map<std::string, vpHomogeneousMatrix> mapOfCameraPoses;
1113  vpMbKltMultiTracker::getPose(mapOfCameraPoses);
1114 
1115  //Set pose for Edge for all the cameras (setPose or initFromPose is equivalent with vpMbEdgeTracker)
1116  //And it avoids to click a second time
1117  vpMbEdgeMultiTracker::setPose(mapOfImages, mapOfCameraPoses);
1118 }
1119 
1142 void vpMbEdgeKltMultiTracker::initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1143  const std::map<std::string, std::string> &mapOfInitFiles, const bool displayHelp) {
1144  vpMbKltMultiTracker::initClick(mapOfImages, mapOfInitFiles, displayHelp);
1145 
1146  //Get pose for all the cameras
1147  std::map<std::string, vpHomogeneousMatrix> mapOfCameraPoses;
1148  vpMbKltMultiTracker::getPose(mapOfCameraPoses);
1149 
1150  //Set pose for Edge for all the cameras (setPose or initFromPose is equivalent with vpMbEdgeTracker)
1151  //And it avoids to click a second time
1152  vpMbEdgeMultiTracker::setPose(mapOfImages, mapOfCameraPoses);
1153 }
1154 #endif //#ifdef VISP_HAVE_MODULE_GUI
1155 
1156 void vpMbEdgeKltMultiTracker::initCircle(const vpPoint&, const vpPoint &, const vpPoint &, const double, const int,
1157  const std::string &) {
1158  std::cerr << "The method initCircle is not used in vpMbEdgeKltMultiTracker !" << std::endl;
1159 }
1160 
1161 void vpMbEdgeKltMultiTracker::initCylinder(const vpPoint&, const vpPoint &, const double, const int,
1162  const std::string &) {
1163  std::cerr << "The method initCylinder is not used in vpMbEdgeKltMultiTracker !" << std::endl;
1164 }
1165 
1167  std::cerr << "The method initFaceFromCorners is not used in vpMbEdgeKltMultiTracker !" << std::endl;
1168 }
1169 
1171  std::cerr << "The method initFaceFromLines is not used in vpMbEdgeKltMultiTracker !" << std::endl;
1172 }
1173 
1192 void vpMbEdgeKltMultiTracker::initFromPose(const vpImage<unsigned char>& I, const std::string &initFile) {
1193  //Monocular case only !
1194  if(m_mapOfKltTrackers.size() > 1) {
1195  throw vpException(vpTrackingException::fatalError, "This function can only be used for the monocular case !");
1196  }
1197 
1198  char s[FILENAME_MAX];
1199  std::fstream finit ;
1200  vpPoseVector init_pos;
1201 
1202  std::string ext = ".pos";
1203  size_t pos = initFile.rfind(ext);
1204 
1205  if( pos == initFile.size()-ext.size() && pos != 0)
1206  sprintf(s,"%s", initFile.c_str());
1207  else
1208  sprintf(s,"%s.pos", initFile.c_str());
1209 
1210  finit.open(s,std::ios::in) ;
1211  if (finit.fail()){
1212  std::cerr << "cannot read " << s << std::endl;
1213  throw vpException(vpException::ioError, "cannot read init file");
1214  }
1215 
1216  for (unsigned int i = 0; i < 6; i += 1){
1217  finit >> init_pos[i];
1218  }
1219 
1220  cMo.buildFrom(init_pos);
1223 }
1224 
1232  //Monocular case only !
1233  if(m_mapOfKltTrackers.size() > 1) {
1234  throw vpException(vpTrackingException::fatalError, "This function can only be used for the monocular case !");
1235  }
1236 
1237  this->cMo = cMo_;
1240 }
1241 
1249  vpHomogeneousMatrix _cMo(cPo);
1250  initFromPose(I, _cMo);
1251 }
1252 
1263  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const bool firstCameraIsReference) {
1264  vpMbEdgeMultiTracker::initFromPose(I1, I2, c1Mo, c2Mo, firstCameraIsReference);
1265  vpMbKltMultiTracker::initFromPose(I1, I2, c1Mo, c2Mo, firstCameraIsReference);
1266 }
1267 
1274 void vpMbEdgeKltMultiTracker::initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1275  const vpHomogeneousMatrix &cMo_) {
1276  vpMbEdgeMultiTracker::initFromPose(mapOfImages, cMo_);
1277  vpMbKltMultiTracker::initFromPose(mapOfImages, cMo_);
1278 }
1279 
1286 void vpMbEdgeKltMultiTracker::initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1287  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) {
1288  vpMbEdgeMultiTracker::initFromPose(mapOfImages, mapOfCameraPoses);
1289  vpMbKltMultiTracker::initFromPose(mapOfImages, mapOfCameraPoses);
1290 }
1291 
1292 unsigned int vpMbEdgeKltMultiTracker::initMbtTracking(std::vector<FeatureType> &indexOfFeatures,
1293  std::map<std::string, unsigned int> &mapOfNumberOfRows,
1294  std::map<std::string, unsigned int> &mapOfNumberOfLines,
1295  std::map<std::string, unsigned int> &mapOfNumberOfCylinders,
1296  std::map<std::string, unsigned int> &mapOfNumberOfCircles) {
1297  unsigned int nbrow = 0;
1298  unsigned int nberrors_lines = 0;
1299  unsigned int nberrors_cylinders = 0;
1300  unsigned int nberrors_circles = 0;
1301 
1302  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it1 = m_mapOfEdgeTrackers.begin();
1303  it1 != m_mapOfEdgeTrackers.end(); ++it1) {
1304  unsigned int nrows = 0;
1305  unsigned int nlines = 0;
1306  unsigned int ncylinders = 0;
1307  unsigned int ncircles = 0;
1308 
1309  nrows = it1->second->initMbtTracking(nlines, ncylinders, ncircles);
1310 
1311  mapOfNumberOfRows[it1->first] = nrows;
1312  mapOfNumberOfLines[it1->first] = nlines;
1313  mapOfNumberOfCylinders[it1->first] = ncylinders;
1314  mapOfNumberOfCircles[it1->first] = ncircles;
1315 
1316  nbrow += nrows;
1317  nberrors_lines += nlines;
1318  nberrors_cylinders += ncylinders;
1319  nberrors_circles += ncircles;
1320 
1321  for(unsigned int i = 0; i < nlines; i++) {
1322  indexOfFeatures.push_back(LINE);
1323  }
1324 
1325  for(unsigned int i = 0; i < ncylinders; i++) {
1326  indexOfFeatures.push_back(CYLINDER);
1327  }
1328 
1329  for(unsigned int i = 0; i < ncircles; i++) {
1330  indexOfFeatures.push_back(CIRCLE);
1331  }
1332  }
1333 
1334  return nbrow;
1335 }
1336 
1383 void vpMbEdgeKltMultiTracker::loadConfigFile(const std::string &configFile) {
1386 }
1387 
1402 void vpMbEdgeKltMultiTracker::loadConfigFile(const std::string& configFile1, const std::string& configFile2,
1403  const bool firstCameraIsReference) {
1404  vpMbEdgeMultiTracker::loadConfigFile(configFile1, configFile2, firstCameraIsReference);
1405  vpMbKltMultiTracker::loadConfigFile(configFile1, configFile2, firstCameraIsReference);
1406 }
1407 
1420 void vpMbEdgeKltMultiTracker::loadConfigFile(const std::map<std::string, std::string> &mapOfConfigFiles) {
1421  vpMbEdgeMultiTracker::loadConfigFile(mapOfConfigFiles);
1422  vpMbKltMultiTracker::loadConfigFile(mapOfConfigFiles);
1423 }
1424 
1450 void vpMbEdgeKltMultiTracker::loadModel(const std::string &modelFile, const bool verbose) {
1451  vpMbEdgeMultiTracker::loadModel(modelFile, verbose);
1452  vpMbKltMultiTracker::loadModel(modelFile, verbose);
1453 
1454  modelInitialised = true;
1455 }
1456 
1457 void vpMbEdgeKltMultiTracker::postTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1458  vpColVector &w_mbt, vpColVector &w_klt, std::map<std::string, unsigned int> &mapOfNumberOfRows,
1459  std::map<std::string, unsigned int> &mapOfNbInfos, const unsigned int lvl) {
1460  //MBT
1461  unsigned int cpt = 0;
1462  for(std::map<std::string, unsigned int>::const_iterator it = mapOfNumberOfRows.begin(); it != mapOfNumberOfRows.end(); ++it) {
1463  for(unsigned int i = 0; i < mapOfNumberOfRows[it->first]; i++) {
1464  m_mapOfEdgeTrackers[it->first]->m_w[i] = w_mbt[i+cpt];
1465  }
1466 
1467  m_mapOfEdgeTrackers[it->first]->updateMovingEdgeWeights();
1468  cpt += mapOfNumberOfRows[it->first];
1469  }
1470 
1471  if(displayFeatures) {
1472  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
1473  it != m_mapOfEdgeTrackers.end(); ++it) {
1474  it->second->displayFeaturesOnImage(*mapOfImages[it->first], lvl);
1475  }
1476  }
1477 
1478  //KLT
1479  vpMbKltMultiTracker::postTracking(mapOfImages, mapOfNbInfos, w_klt);
1480 
1481  // Looking for new visible face
1482  bool newvisibleface = false;
1483  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
1484  it != m_mapOfEdgeTrackers.end(); ++it) {
1485  it->second->visibleFace(*mapOfImages[it->first], it->second->cMo, newvisibleface);
1486  }
1487 
1488  if(useScanLine) {
1489  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
1490  it != m_mapOfEdgeTrackers.end(); ++it) {
1491  it->second->faces.computeClippedPolygons(it->second->cMo, it->second->cam);
1492  it->second->faces.computeScanLineRender(it->second->cam, mapOfImages[it->first]->getWidth(),
1493  mapOfImages[it->first]->getHeight());
1494  }
1495  }
1496 
1497  try {
1498  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
1499  it != m_mapOfEdgeTrackers.end(); ++it) {
1500  it->second->updateMovingEdge(*mapOfImages[it->first]);
1501  }
1502  } catch(vpException &e) {
1503  throw e;
1504  }
1505 
1506  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
1507  it != m_mapOfEdgeTrackers.end(); ++it) {
1508  it->second->initMovingEdge(*mapOfImages[it->first], it->second->cMo);
1509 
1510  // Reinit the moving edge for the lines which need it.
1511  it->second->reinitMovingEdge(*mapOfImages[it->first], it->second->cMo);
1512 
1513  if(computeProjError) {
1514  it->second->computeProjectionError(*mapOfImages[it->first]);
1515  }
1516  }
1517 }
1518 
1519 void vpMbEdgeKltMultiTracker::reinit(/*const vpImage<unsigned char>& I */) {
1520 // vpMbEdgeMultiTracker::reinit();
1522 }
1523 
1533 void vpMbEdgeKltMultiTracker::reInitModel(const vpImage<unsigned char>& I, const std::string &cad_name,
1534  const vpHomogeneousMatrix& cMo_, const bool verbose) {
1535  vpMbEdgeMultiTracker::reInitModel(I, cad_name, cMo_, verbose);
1536  vpMbKltMultiTracker::reInitModel(I, cad_name, cMo_, verbose);
1537 }
1538 
1552  const std::string &cad_name, const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
1553  const bool verbose, const bool firstCameraIsReference) {
1554  vpMbEdgeMultiTracker::reInitModel(I1, I2, cad_name, c1Mo, c2Mo, verbose, firstCameraIsReference);
1555  vpMbKltMultiTracker::reInitModel(I1, I2, cad_name, c1Mo, c2Mo, verbose, firstCameraIsReference);
1556 }
1557 
1567 void vpMbEdgeKltMultiTracker::reInitModel(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1568  const std::string &cad_name, const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
1569  const bool verbose) {
1570  vpMbEdgeMultiTracker::reInitModel(mapOfImages, cad_name, mapOfCameraPoses, verbose);
1571  vpMbKltMultiTracker::reInitModel(mapOfImages, cad_name, mapOfCameraPoses, verbose);
1572 }
1573 
1581 }
1582 
1595 }
1596 
1609 }
1610 
1619 
1620  this->cam = camera;
1621 }
1622 
1631  const bool firstCameraIsReference) {
1632  vpMbEdgeMultiTracker::setCameraParameters(camera1, camera2, firstCameraIsReference);
1633  vpMbKltMultiTracker::setCameraParameters(camera1, camera2, firstCameraIsReference);
1634 
1635  if(firstCameraIsReference) {
1636  this->cam = camera1;
1637  } else {
1638  this->cam = camera2;
1639  }
1640 }
1641 
1648 void vpMbEdgeKltMultiTracker::setCameraParameters(const std::string &cameraName, const vpCameraParameters& camera) {
1649  vpMbEdgeMultiTracker::setCameraParameters(cameraName, camera);
1650  vpMbKltMultiTracker::setCameraParameters(cameraName, camera);
1651 
1652  if(cameraName == m_referenceCameraName) {
1653  this->cam = camera;
1654  }
1655 }
1656 
1662 void vpMbEdgeKltMultiTracker::setCameraParameters(const std::map<std::string, vpCameraParameters> &mapOfCameraParameters) {
1663  vpMbEdgeMultiTracker::setCameraParameters(mapOfCameraParameters);
1664  vpMbKltMultiTracker::setCameraParameters(mapOfCameraParameters);
1665 
1666  for(std::map<std::string, vpCameraParameters>::const_iterator it = mapOfCameraParameters.begin();
1667  it != mapOfCameraParameters.end(); ++it) {
1668  if(it->first == m_referenceCameraName) {
1669  this->cam = it->second;
1670  }
1671  }
1672 }
1673 
1681  const vpHomogeneousMatrix &cameraTransformationMatrix) {
1682  vpMbEdgeMultiTracker::setCameraTransformationMatrix(cameraName, cameraTransformationMatrix);
1683  vpMbKltMultiTracker::setCameraTransformationMatrix(cameraName, cameraTransformationMatrix);
1684 
1685  std::map<std::string, vpHomogeneousMatrix>::iterator it = m_mapOfCameraTransformationMatrix.find(cameraName);
1686  if(it != m_mapOfCameraTransformationMatrix.end()) {
1687  it->second = cameraTransformationMatrix;
1688  } else {
1689  std::cerr << "Cannot find camera: " << cameraName << " !" << std::endl;
1690  }
1691 }
1692 
1700  const std::map<std::string, vpHomogeneousMatrix> &mapOfTransformationMatrix) {
1701  vpMbEdgeMultiTracker::setCameraTransformationMatrix(mapOfTransformationMatrix);
1702  vpMbKltMultiTracker::setCameraTransformationMatrix(mapOfTransformationMatrix);
1703 
1704  m_mapOfCameraTransformationMatrix = mapOfTransformationMatrix;
1705 }
1706 
1714 void vpMbEdgeKltMultiTracker::setClipping(const unsigned int &flags) {
1717 }
1718 
1727 void vpMbEdgeKltMultiTracker::setClipping(const std::string &cameraName, const unsigned int &flags) {
1728  //Here, we do not change the general clipping flag
1729  vpMbEdgeMultiTracker::setClipping(cameraName, flags);
1730  vpMbKltMultiTracker::setClipping(cameraName, flags);
1731 }
1732 
1741 }
1742 
1757 }
1758 
1767 }
1768 
1775 void vpMbEdgeKltMultiTracker::setFarClippingDistance(const std::string &cameraName, const double &dist) {
1778 }
1779 
1780 #ifdef VISP_HAVE_OGRE
1781 
1791  }
1792 
1804  }
1805 #endif
1806 
1816 void vpMbEdgeKltMultiTracker::setLod(const bool useLod, const std::string &name) {
1817  vpMbEdgeMultiTracker::setLod(useLod, name);
1818  vpMbKltMultiTracker::setLod(useLod, name);
1819 }
1820 
1831 void vpMbEdgeKltMultiTracker::setLod(const bool useLod, const std::string &cameraName, const std::string &name) {
1832  vpMbEdgeMultiTracker::setLod(useLod, cameraName, name);
1833  vpMbKltMultiTracker::setLod(useLod, cameraName, name);
1834 }
1835 
1844 void vpMbEdgeKltMultiTracker::setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name) {
1845  vpMbEdgeMultiTracker::setMinLineLengthThresh(minLineLengthThresh, name);
1846 }
1847 
1857 void vpMbEdgeKltMultiTracker::setMinLineLengthThresh(const double minLineLengthThresh, const std::string &cameraName,
1858  const std::string &name) {
1859  vpMbEdgeMultiTracker::setMinLineLengthThresh(minLineLengthThresh, cameraName, name);
1860 }
1861 
1870 void vpMbEdgeKltMultiTracker::setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name) {
1871  vpMbEdgeMultiTracker::setMinPolygonAreaThresh(minPolygonAreaThresh, name);
1872  vpMbKltMultiTracker::setMinPolygonAreaThresh(minPolygonAreaThresh, name);
1873 }
1874 
1884 void vpMbEdgeKltMultiTracker::setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &cameraName,
1885  const std::string &name) {
1886  vpMbEdgeMultiTracker::setMinPolygonAreaThresh(minPolygonAreaThresh, cameraName, name);
1887  vpMbKltMultiTracker::setMinPolygonAreaThresh(minPolygonAreaThresh, cameraName, name);
1888 }
1889 
1898 }
1899 
1906 void vpMbEdgeKltMultiTracker::setNearClippingDistance(const std::string &cameraName, const double &dist) {
1909 }
1910 
1921 void vpMbEdgeKltMultiTracker::setOgreShowConfigDialog(const bool showConfigDialog) {
1924 }
1925 
1934  //Edge
1935  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
1936  it != m_mapOfEdgeTrackers.end(); ++it) {
1937  it->second->setOgreVisibilityTest(v);
1938  }
1939 
1940 #ifdef VISP_HAVE_OGRE
1941  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
1942  it != m_mapOfEdgeTrackers.end(); ++it) {
1943  it->second->faces.getOgreContext()->setWindowName("Multi Edge MBT Hybrid (" + it->first + ")");
1944  }
1945 #endif
1946 
1947 
1948  //KLT
1949  for(std::map<std::string, vpMbKltTracker *>::const_iterator it = m_mapOfKltTrackers.begin();
1950  it != m_mapOfKltTrackers.end(); ++it) {
1951  it->second->setOgreVisibilityTest(v);
1952  }
1953 
1954 #ifdef VISP_HAVE_OGRE
1955  for(std::map<std::string, vpMbKltTracker *>::const_iterator it = m_mapOfKltTrackers.begin();
1956  it != m_mapOfKltTrackers.end(); ++it) {
1957  it->second->faces.getOgreContext()->setWindowName("Multi KLT MBT Hybrid (" + it->first + ")");
1958  }
1959 #endif
1960 
1961  useOgre = v;
1962 }
1963 
1972 }
1973 
1982  if(m_mapOfEdgeTrackers.size() != 1 || m_mapOfKltTrackers.size() != 1) {
1983  std::cerr << "This method requires only 1 camera !" << std::endl;
1984  } else {
1985  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1986  std::map<std::string, vpMbKltTracker *>::const_iterator it_klt = m_mapOfKltTrackers.find(m_referenceCameraName);
1987  if(it_edge != m_mapOfEdgeTrackers.end() && it_klt != m_mapOfKltTrackers.end()) {
1988  it_edge->second->setPose(I, cMo_);
1989  it_klt->second->setPose(I, cMo_);
1990 
1991  this->cMo = cMo_;
1992  c0Mo = this->cMo;
1993  ctTc0.eye();
1994  } else {
1995  std::cerr << "Cannot find the reference camera: " << m_referenceCameraName << " !" << std::endl;
1996  }
1997  }
1998 }
1999 
2011  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix c2Mo, const bool firstCameraIsReference) {
2012  vpMbEdgeMultiTracker::setPose(I1, I2, c1Mo, c2Mo, firstCameraIsReference);
2013  vpMbKltMultiTracker::setPose(I1, I2, c1Mo, c2Mo, firstCameraIsReference);
2014 }
2015 
2024 void vpMbEdgeKltMultiTracker::setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
2025  const vpHomogeneousMatrix &cMo_) {
2026  vpMbEdgeMultiTracker::setPose(mapOfImages, cMo_);
2027  vpMbKltMultiTracker::setPose(mapOfImages, cMo_);
2028 }
2029 
2039 void vpMbEdgeKltMultiTracker::setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
2040  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) {
2041  vpMbEdgeMultiTracker::setPose(mapOfImages, mapOfCameraPoses);
2042  vpMbKltMultiTracker::setPose(mapOfImages, mapOfCameraPoses);
2043 }
2044 
2051  //Set the general flag for the current class
2053 
2054  //Set the flag for each camera
2055  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2056  it != m_mapOfEdgeTrackers.end(); ++it) {
2057  it->second->setProjectionErrorComputation(flag);
2058  }
2059 }
2060 
2066 void vpMbEdgeKltMultiTracker::setReferenceCameraName(const std::string &referenceCameraName) {
2067  vpMbEdgeMultiTracker::setReferenceCameraName(referenceCameraName);
2068  vpMbKltMultiTracker::setReferenceCameraName(referenceCameraName);
2069  m_referenceCameraName = referenceCameraName;
2070 }
2071 
2080 }
2081 
2089 }
2090 
2092  std::cerr << "The method vpMbEdgeKltMultiTracker::testTracking is not used !" << std::endl;
2093 }
2094 
2103  //Track only with reference camera
2104  //Get the reference camera parameters
2105  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_mbt = m_mapOfEdgeTrackers.find(m_referenceCameraName);
2106  std::map<std::string, vpMbKltTracker *>::const_iterator it_klt = m_mapOfKltTrackers.find(m_referenceCameraName);
2107 
2108  if(it_mbt != m_mapOfEdgeTrackers.end() && it_klt != m_mapOfKltTrackers.end()) {
2109  std::map<std::string, const vpImage<unsigned char> *> mapOfImages;
2110  mapOfImages[m_referenceCameraName] = &I;
2111  track(mapOfImages);
2112  } else {
2113  std::stringstream ss;
2114  ss << "The reference camera: " << m_referenceCameraName << " does not exist !";
2115  throw vpException(vpTrackingException::fatalError, ss.str().c_str());
2116  }
2117 
2118  //Set the projection error from the single camera
2119  if(computeProjError) {
2120  projectionError = it_mbt->second->getProjectionError();
2121  }
2122 }
2123 
2133  if(m_mapOfEdgeTrackers.size() == 2 && m_mapOfKltTrackers.size() == 2) {
2134  std::map<std::string, vpMbKltTracker *>::const_iterator it = m_mapOfKltTrackers.begin();
2135  std::map<std::string, const vpImage<unsigned char> *> mapOfImages;
2136  //Assume that the first image is the first name in alphabetic order
2137  mapOfImages[it->first] = &I1;
2138  ++it;
2139 
2140  mapOfImages[it->first] = &I2;
2141  track(mapOfImages);
2142  } else {
2143  std::stringstream ss;
2144  ss << "Require two cameras ! There are " << m_mapOfKltTrackers.size() << " cameras !";
2145  throw vpException(vpTrackingException::fatalError, ss.str().c_str());
2146  }
2147 }
2148 
2156 void vpMbEdgeKltMultiTracker::track(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages) {
2157  //Reset the projectionError
2158  projectionError = 90.0;
2159 
2160  //Check if there is an image for each camera
2161  //mbt
2162  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it_edge = m_mapOfEdgeTrackers.begin();
2163  it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
2164  std::map<std::string, const vpImage<unsigned char>* >::const_iterator it_img = mapOfImages.find(it_edge->first);
2165 
2166  if(it_img == mapOfImages.end()) {
2167  throw vpException(vpTrackingException::fatalError, "Missing images for edge trackers !");
2168  }
2169  }
2170 
2171  //klt
2172  for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt = m_mapOfKltTrackers.begin();
2173  it_klt != m_mapOfKltTrackers.end(); ++it_klt) {
2174  std::map<std::string, const vpImage<unsigned char>* >::const_iterator it_img = mapOfImages.find(it_klt->first);
2175 
2176  if(it_img == mapOfImages.end()) {
2177  throw vpException(vpTrackingException::fatalError, "Missing images for KLT trackers !");
2178  }
2179  }
2180 
2181  std::map<std::string, unsigned int> mapOfNbInfos;
2182  std::map<std::string, unsigned int> mapOfNbFaceUsed;
2183 
2184  try {
2185  vpMbKltMultiTracker::preTracking(mapOfImages, mapOfNbInfos, mapOfNbFaceUsed);
2186  } catch(/*vpException &e*/...) {
2187 // std::cerr << "Catch an exception in vpMbKltMultiTracker::preTracking: " << e.what() << std::endl;
2188  }
2189 
2190  vpColVector w_klt;
2191 
2192  //MBT: track moving edges
2193  trackMovingEdges(mapOfImages);
2194 
2195  vpColVector w_mbt;
2196  std::map<std::string, unsigned int> mapOfNumberOfRows;
2197  computeVVS(mapOfImages, mapOfNumberOfRows, mapOfNbInfos, w_mbt, w_klt);
2198 
2199  postTracking(mapOfImages, w_mbt, w_klt, mapOfNumberOfRows, mapOfNbInfos, 0);
2200 
2201  if(computeProjError) {
2203  }
2204 }
2205 
2206 unsigned int vpMbEdgeKltMultiTracker::trackFirstLoop(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
2207  vpColVector &factor, std::vector<FeatureType> &indexOfFeatures,
2208  std::map<std::string, unsigned int> &mapOfNumberOfRows,
2209  std::map<std::string, unsigned int> &mapOfNumberOfLines,
2210  std::map<std::string, unsigned int> &mapOfNumberOfCylinders,
2211  std::map<std::string, unsigned int> &mapOfNumberOfCircles, const unsigned int lvl) {
2212 
2213  //Number of moving edges
2214  unsigned int nbrow = initMbtTracking(indexOfFeatures, mapOfNumberOfRows, mapOfNumberOfLines,
2215  mapOfNumberOfCylinders, mapOfNumberOfCircles);
2216 
2217  if (nbrow == 0) {
2218  return nbrow;
2219  }
2220 
2221  factor = vpColVector();
2222  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2223  it != m_mapOfEdgeTrackers.end(); ++it) {
2224  //Set the corresponding cMo for each camera
2225  //Used in computeVVSFirstPhaseFactor with computeInteractionMatrixError
2226  it->second->cMo = m_mapOfCameraTransformationMatrix[it->first] * cMo;
2227 
2228  vpColVector factor_tmp;
2229  factor_tmp.resize(mapOfNumberOfRows[it->first]);
2230  factor_tmp = 1;
2231  it->second->computeVVSFirstPhaseFactor(*mapOfImages[it->first], factor_tmp, lvl);
2232 
2233  factor.stack(factor_tmp);
2234  }
2235 
2236  return nbrow;
2237 }
2238 
2239 void vpMbEdgeKltMultiTracker::trackMovingEdges(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages) {
2240  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it1 = m_mapOfEdgeTrackers.begin();
2241  it1 != m_mapOfEdgeTrackers.end(); ++it1) {
2242  //Track moving edges
2243  try {
2244  it1->second->trackMovingEdge(*mapOfImages[it1->first]);
2245  } catch(...) {
2246  std::cerr << "Error in moving edge tracking" << std::endl;
2247  throw ;
2248  }
2249  }
2250 }
2251 
2252 #elif !defined(VISP_BUILD_SHARED_LIBS)
2253 // Work arround to avoid warning: libvisp_mbt.a(dummy_vpMbEdgeKltMultiTracker.cpp.o) has no symbols
2254 void dummy_vpMbEdgeKltMultiTracker() {};
2255 #endif //VISP_HAVE_OPENCV
bool computeProjError
Flag used to specify if the gradient error criteria has to be computed or not.
Definition: vpMbTracker.h:131
void setGoodNbRayCastingAttemptsRatio(const double &ratio)
virtual void trackMovingEdges(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages)
virtual void initClick(const vpImage< unsigned char > &I, const std::vector< vpPoint > &points3D_list, const std::string &displayFile="")
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
vpMatrix covarianceMatrix
Covariance matrix.
Definition: vpMbTracker.h:129
virtual void loadModel(const std::string &modelFile, const bool verbose=false)
void displayPrimitive(const vpImage< unsigned char > &_I)
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
virtual void setFarClippingDistance(const double &dist)
virtual void setFarClippingDistance(const double &dist)
virtual void setNearClippingDistance(const double &dist)
double lambda
The gain of the virtual visual servoing stage.
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls, const vpMatrix &W)
virtual void setLod(const bool useLod, const std::string &name="")
double thresholdMBT
The threshold used in the robust estimation of MBT.
virtual void setOgreVisibilityTest(const bool &v)
virtual void setCovarianceComputation(const bool &flag)
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:208
std::map< std::string, vpMbHiddenFaces< vpMbtPolygon > > getEdgeFaces() const
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void stack(const double &d)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
virtual void computeVVS(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, std::map< std::string, unsigned int > &mapOfNumberOfRows, std::map< std::string, unsigned int > &mapOfNbInfos, vpColVector &w_mbt, vpColVector &w_klt, const unsigned int lvl=0)
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
Definition: vpMbTracker.h:144
virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt)
virtual void computeProjectionError()
virtual void computeVVSWeights(const unsigned int iter, const unsigned int nbInfos, std::map< std::string, unsigned int > &mapOfNbInfos, vpColVector &R, vpColVector &w_true, vpColVector &w, std::map< std::string, vpRobust > &mapOfRobusts, double threshold)
void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
virtual void setAngleDisappear(const double &a)
std::map< std::string, vpHomogeneousMatrix > m_mapOfCameraTransformationMatrix
Map of camera transformation matrix between the current camera frame to the reference camera frame (c...
virtual void setDisplayFeatures(const bool displayF)
virtual void loadConfigFile(const std::string &configFile)
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual void preTracking(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, std::map< std::string, unsigned int > &mapOfNbInfos, std::map< std::string, unsigned int > &mapOfNbFaceUsed)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
virtual std::map< std::string, unsigned int > getMultiNbPolygon() const
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
virtual void setLod(const bool useLod, const std::string &name="")
virtual void setFarClippingDistance(const double &dist)
vpHomogeneousMatrix cMo
The current pose.
Definition: vpMbTracker.h:115
void stack(const vpMatrix &A)
Definition: vpMatrix.cpp:2981
double m_factorMBT
Factor for edge trackers.
void setGoodNbRayCastingAttemptsRatio(const double &ratio)
virtual void setDisplayFeatures(const bool displayF)
virtual void loadConfigFile(const std::string &configFile)
virtual void setDisplayFeatures(const bool displayF)
virtual void setCameraTransformationMatrix(const std::string &cameraName, const vpHomogeneousMatrix &cameraTransformationMatrix)
bool modelInitialised
Flag used to ensure that the CAD model is loaded before the initialisation.
Definition: vpMbTracker.h:123
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
error that can be emited by ViSP classes.
Definition: vpException.h:73
virtual void setThresholdAcceptation(const double th)
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
virtual void setCovarianceComputation(const bool &flag)
virtual void setClipping(const unsigned int &flags)
virtual void setOgreShowConfigDialog(const bool showConfigDialog)
virtual void init(const vpImage< unsigned char > &I)
virtual void setAngleAppear(const double &a)
virtual void setAngleDisappear(const double &a)
virtual void getCameraParameters(vpCameraParameters &camera) const
bool useOgre
Use Ogre3d for visibility tests.
Definition: vpMbTracker.h:156
virtual void setLod(const bool useLod, const std::string &name="")
unsigned int getCols() const
Return the number of columns of the 2D array.
Definition: vpArray2D.h:154
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
virtual void loadConfigFile(const std::string &configFile)
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
Definition: vpMbTracker.h:127
virtual void loadModel(const std::string &modelFile, const bool verbose=false)
virtual void setReferenceCameraName(const std::string &referenceCameraName)
virtual void setNearClippingDistance(const double &dist)
Implementation of a polygon of the model containing points of interest. It is used by the model-based...
Class that defines what is a point.
Definition: vpPoint.h:59
double thresholdKLT
The threshold used in the robust estimation of KLT.
vpCameraParameters cam
The camera parameters.
Definition: vpMbTracker.h:113
virtual std::map< std::string, unsigned int > getEdgeMultiNbPolygon() const
vpHomogeneousMatrix ctTc0
The estimated displacement of the pose between the current instant and the initial position...
virtual void setReferenceCameraName(const std::string &referenceCameraName)
void computeJTR(const vpMatrix &J, const vpColVector &R, vpColVector &JTR) const
double projectionError
Error angle between the gradient direction of the model features projected at the resulting pose and ...
Definition: vpMbTracker.h:133
Implementation of an homography and operations on homographies.
Definition: vpHomography.h:179
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 initFaceFromLines(vpMbtPolygon &polygon)
void computeVVSInteractionMatrixAndResidu(unsigned int shift, vpColVector &R, vpMatrix &L, vpHomography &H, std::list< vpMbtDistanceKltPoints * > &kltPolygons_, std::list< vpMbtDistanceKltCylinder * > &kltCylinders_, const vpHomogeneousMatrix &ctTc0_)
virtual void track(const vpImage< unsigned char > &I)
void setGoodNbRayCastingAttemptsRatio(const double &ratio)
vpMatrix oJo
The Degrees of Freedom to estimate.
Definition: vpMbTracker.h:117
Error that can be emited by the vpTracker class and its derivates.
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:64
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
virtual unsigned int trackFirstLoop(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, vpColVector &factor, std::vector< FeatureType > &indexOfFeatures, std::map< std::string, unsigned int > &mapOfNumberOfRows, std::map< std::string, unsigned int > &mapOfNumberOfLines, std::map< std::string, unsigned int > &mapOfNumberOfCylinders, std::map< std::string, unsigned int > &mapOfNumberOfCircles, const unsigned int lvl)
virtual void setClipping(const unsigned int &flags)
vpMatrix AtA() const
Definition: vpMatrix.cpp:376
bool compute_interaction
If true, compute the interaction matrix at each iteration of the minimization. Otherwise, compute it only on the first iteration.
virtual vpHomogeneousMatrix getPose() const
Definition: vpMbTracker.h:342
void displayPrimitive(const vpImage< unsigned char > &_I)
void diag(const double &val=1.0)
Definition: vpMatrix.cpp:524
virtual void setOgreShowConfigDialog(const bool showConfigDialog)
bool useScanLine
Use Scanline for visibility tests.
Definition: vpMbTracker.h:159
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double sqr(double x)
Definition: vpMath.h:110
virtual void setScanLineVisibilityTest(const bool &v)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
virtual void setCameraParameters(const vpCameraParameters &camera)
vpColVector m_error
Error s-s*.
Definition: vpMbTracker.h:139
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
Generic class defining intrinsic camera parameters.
virtual void setCameraTransformationMatrix(const std::string &cameraName, const vpHomogeneousMatrix &cameraTransformationMatrix)
Implementation of a polygon of the model containing points of interest. It is used by the model-based...
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
virtual void setAngleAppear(const double &a)
Implementation of a velocity twist matrix and operations on such kind of matrices.
virtual unsigned int initMbtTracking(std::vector< FeatureType > &indexOfFeatures, std::map< std::string, unsigned int > &mapOfNumberOfRows, std::map< std::string, unsigned int > &mapOfNumberOfLines, std::map< std::string, unsigned int > &mapOfNumberOfCylinders, std::map< std::string, unsigned int > &mapOfNumberOfCircles)
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
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 bool isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo=false, const vpCameraParameters &cam=vpCameraParameters(), const vpImage< unsigned char > &I=vpImage< unsigned char >())
virtual void setCovarianceComputation(const bool &flag)
virtual void postTracking(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, std::map< std::string, unsigned int > &mapOfNbInfos, vpColVector &w_klt)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
std::map< std::string, vpMbKltTracker * > m_mapOfKltTrackers
Map of Model-based klt trackers.
virtual void setThresholdAcceptation(const double th)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
virtual void setNearClippingDistance(const double &dist)
double sumSquare() const
virtual void setCameraParameters(const vpCameraParameters &camera)
void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
bool displayFeatures
If true, the features are displayed.
Definition: vpMbTracker.h:135
virtual std::map< std::string, unsigned int > getKltMultiNbPolygon() const
virtual void getCameraParameters(vpCameraParameters &camera) const
virtual void initCylinder(const vpPoint &, const vpPoint &, const double, const int, const std::string &name="")
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
virtual void loadModel(const std::string &modelFile, const bool verbose=false)
virtual void setCameraParameters(const vpCameraParameters &camera)
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:93
vpHomogeneousMatrix inverse() const
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
static vpHomogeneousMatrix direct(const vpColVector &v)
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
Contains an M-Estimator and various influence function.
Definition: vpRobust.h:60
std::string m_referenceCameraName
Name of the reference camera.
virtual void setOgreShowConfigDialog(const bool showConfigDialog)
virtual std::vector< std::string > getCameraNames() const
vpMbtPolygon * polygon
Pointer to the polygon that define a face.
virtual void postTracking(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, vpColVector &w_mbt, vpColVector &w_klt, std::map< std::string, unsigned int > &mapOfNumberOfRows, std::map< std::string, unsigned int > &mapOfNbInfos, const unsigned int lvl)
virtual std::vector< std::string > getCameraNames() const
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
virtual void setScanLineVisibilityTest(const bool &v)
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
Definition: vpMatrix.cpp:1741
void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
virtual void setAngleDisappear(const double &a)
virtual void initClick(const vpImage< unsigned char > &I, const std::vector< vpPoint > &points3D_list, const std::string &displayFile="")
virtual void setClipping(const unsigned int &flags)
double m_factorKLT
Factor for KLT trackers.
virtual void setCameraTransformationMatrix(const std::string &cameraName, const vpHomogeneousMatrix &cameraTransformationMatrix)
std::map< std::string, vpMbEdgeTracker * > m_mapOfEdgeTrackers
Map of Model-based edge trackers.
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
Make the complete stereo (or more) tracking of an object by using its CAD model.
virtual void setProjectionErrorComputation(const bool &flag)
virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt)
virtual void setReferenceCameraName(const std::string &referenceCameraName)
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
void eye()
Definition: vpMatrix.cpp:194
virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, const double, const int, const std::string &name="")
bool isoJoIdentity
Boolean to know if oJo is identity (for fast computation)
Definition: vpMbTracker.h:119
Model based stereo (or more) tracker using only KLT.
vpHomogeneousMatrix c0Mo
Initial pose.
virtual std::map< std::string, unsigned int > getMultiNbPolygon() const
std::map< std::string, vpMbHiddenFaces< vpMbtPolygon > > getKltFaces() const
virtual void setAngleAppear(const double &a)
virtual void computeVVSSecondPhaseWeights(const unsigned int iter, const unsigned int nerror, vpColVector &weighted_error, vpColVector &w_lines, vpColVector &w_cylinders, vpColVector &w_circles, std::map< std::string, unsigned int > &mapOfNumberOfLines, std::map< std::string, unsigned int > &mapOfNumberOfCylinders, std::map< std::string, unsigned int > &mapOfNumberOfCircles, std::map< std::string, vpColVector > &mapOfWeightLines, std::map< std::string, vpColVector > &mapOfWeightCylinders, std::map< std::string, vpColVector > &mapOfWeightCircles, std::map< std::string, vpColVector > &mapOfErrorLines, std::map< std::string, vpColVector > &mapOfErrorCylinders, std::map< std::string, vpColVector > &mapOfErrorCircles, std::map< std::string, vpRobust > &mapOfRobustLines, std::map< std::string, vpRobust > &mapOfRobustCylinders, std::map< std::string, vpRobust > &mapOfRobustCircles, double threshold)
virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt)
virtual unsigned int getNbPolygon() const
virtual void setScanLineVisibilityTest(const bool &v)
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:225
vpColVector m_w
Weights used in the robust scheme.
Definition: vpMbTracker.h:137
virtual void setProjectionErrorComputation(const bool &flag)
Definition: vpMbTracker.h:437