Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpMbEdgeMultiTracker.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 tracker with multiple cameras.
34  *
35  * Authors:
36  * Souriya Trinh
37  *
38  *****************************************************************************/
39 
45 #include <visp3/core/vpDebug.h>
46 #include <visp3/mbt/vpMbEdgeMultiTracker.h>
47 #include <visp3/core/vpExponentialMap.h>
48 #include <visp3/core/vpTrackingException.h>
49 #include <visp3/core/vpVelocityTwistMatrix.h>
50 
51 
55 vpMbEdgeMultiTracker::vpMbEdgeMultiTracker() : m_mapOfCameraTransformationMatrix(), m_mapOfEdgeTrackers(),
56  m_mapOfPyramidalImages(), m_referenceCameraName("Camera") {
57  m_mapOfEdgeTrackers["Camera"] = new vpMbEdgeTracker();
58 
59  //Add default camera transformation matrix
61 }
62 
68 vpMbEdgeMultiTracker::vpMbEdgeMultiTracker(const unsigned int nbCameras) : m_mapOfCameraTransformationMatrix(),
69  m_mapOfEdgeTrackers(), m_mapOfPyramidalImages(), m_referenceCameraName("Camera") {
70 
71  if(nbCameras == 0) {
72  throw vpException(vpTrackingException::fatalError, "Cannot construct a vpMbEdgeMultiTracker with no camera !");
73  } else if (nbCameras == 1) {
74  m_mapOfEdgeTrackers["Camera"] = new vpMbEdgeTracker();
75 
76  //Add default camera transformation matrix
78  } else if(nbCameras == 2) {
79  m_mapOfEdgeTrackers["Camera1"] = new vpMbEdgeTracker();
80  m_mapOfEdgeTrackers["Camera2"] = new vpMbEdgeTracker();
81 
82  //Add default camera transformation matrix
85 
86  //Set by default the reference camera to Camera1
87  m_referenceCameraName = "Camera1";
88  } else {
89  for(unsigned int i = 1; i <= nbCameras; i++) {
90  std::stringstream ss;
91  ss << "Camera" << i;
92  m_mapOfEdgeTrackers[ss.str()] = new vpMbEdgeTracker();
93 
94  //Add default camera transformation matrix
96  }
97 
98  //Set by default the reference camera to the first one
100  }
101 }
102 
109 vpMbEdgeMultiTracker::vpMbEdgeMultiTracker(const std::vector<std::string> &cameraNames) : m_mapOfCameraTransformationMatrix(),
110  m_mapOfEdgeTrackers(), m_mapOfPyramidalImages(), m_referenceCameraName("Camera") {
111 
112  if(cameraNames.empty()) {
113  throw vpException(vpTrackingException::fatalError, "Cannot construct a vpMbEdgeMultiTracker with no camera !");
114  }
115 
116  for(std::vector<std::string>::const_iterator it = cameraNames.begin(); it != cameraNames.end(); ++it) {
118  }
119 
120  //Set by default the reference camera
121  m_referenceCameraName = cameraNames.front();
122 }
123 
128  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
129  it != m_mapOfEdgeTrackers.end(); ++it) {
130  delete it->second;
131  }
132 
133  m_mapOfEdgeTrackers.clear();
134 
136 }
137 
138 void vpMbEdgeMultiTracker::cleanPyramid(std::map<std::string, std::vector<const vpImage<unsigned char>* > >& pyramid) {
139  for(std::map<std::string, std::vector<const vpImage<unsigned char>* > >::iterator it1 = pyramid.begin();
140  it1 != pyramid.end(); ++it1) {
141  if(it1->second.size() > 0){
142  it1->second[0] = NULL;
143  for(size_t i = 1; i < it1->second.size(); i++) {
144  if(it1->second[i] != NULL) {
145  delete it1->second[i];
146  it1->second[i] = NULL;
147  }
148  }
149  it1->second.clear();
150  }
151  }
152 }
153 
155  if(computeProjError) {
156  double rawTotalProjectionError = 0.0;
157  unsigned int nbTotalFeaturesUsed = 0;
158  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
159  it != m_mapOfEdgeTrackers.end(); ++it) {
160  double curProjError = it->second->getProjectionError();
161  unsigned int nbFeaturesUsed = it->second->nbFeaturesForProjErrorComputation;
162 
163  if(nbFeaturesUsed > 0) {
164  nbTotalFeaturesUsed += nbFeaturesUsed;
165  rawTotalProjectionError += ( vpMath::rad(curProjError)*nbFeaturesUsed );
166  }
167  }
168 
169  if(nbTotalFeaturesUsed > 0) {
170  nbFeaturesForProjErrorComputation = nbTotalFeaturesUsed;
171  projectionError = vpMath::deg(rawTotalProjectionError / (double)nbTotalFeaturesUsed);
172  } else {
174  projectionError = 90.0;
175  }
176  }
177 }
178 
179 void vpMbEdgeMultiTracker::computeVVS(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages, const unsigned int lvl) {
180  //Number of moving edges
181  unsigned int nbrow = 0;
182  //unsigned int nberrors_lines = 0;
183  //unsigned int nberrors_cylinders = 0;
184  //unsigned int nberrors_circles = 0;
185 
186  std::vector<FeatureType> indexOfFeatures;
187  std::map<std::string, unsigned int> mapOfNumberOfRows;
188  std::map<std::string, unsigned int> mapOfNumberOfLines;
189  std::map<std::string, unsigned int> mapOfNumberOfCylinders;
190  std::map<std::string, unsigned int> mapOfNumberOfCircles;
191 
192  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it1 = m_mapOfEdgeTrackers.begin();
193  it1 != m_mapOfEdgeTrackers.end(); ++it1) {
194  unsigned int nrows = 0;
195  unsigned int nlines = 0;
196  unsigned int ncylinders = 0;
197  unsigned int ncircles = 0;
198 
199  nrows = it1->second->initMbtTracking(nlines, ncylinders, ncircles);
200 
201  mapOfNumberOfRows[it1->first] = nrows;
202  mapOfNumberOfLines[it1->first] = nlines;
203  mapOfNumberOfCylinders[it1->first] = ncylinders;
204  mapOfNumberOfCircles[it1->first] = ncircles;
205 
206  nbrow += nrows;
207  //nberrors_lines += nlines;
208  //nberrors_cylinders += ncylinders;
209  //nberrors_circles += ncircles;
210 
211  for(unsigned int i = 0; i < nlines; i++) {
212  indexOfFeatures.push_back(LINE);
213  }
214 
215  for(unsigned int i = 0; i < ncylinders; i++) {
216  indexOfFeatures.push_back(CYLINDER);
217  }
218 
219  for(unsigned int i = 0; i < ncircles; i++) {
220  indexOfFeatures.push_back(CIRCLE);
221  }
222  }
223 
224  if(nbrow < 4) {
225  throw vpTrackingException(vpTrackingException::notEnoughPointError, "No data found to compute the interaction matrix...");
226  }
227 
228  vpMatrix L;
229 
230  // compute the error vector
231  m_error.resize(nbrow);
232  unsigned int nerror = m_error.getRows();
233  vpColVector v;
234 
235 // double limite = 3; //Une limite de 3 pixels
236 // limite = limite / cam.get_px(); //Transformation limite pixel en limite metre.
237  unsigned int iter = 0;
238  vpColVector weighted_error;
239  vpColVector factor;
240  std::map<std::string, vpColVector> mapOfFactors;
241 
242  //Parametre pour la premiere phase d'asservissement
243  bool reloop = true;
244 
245  bool isoJoIdentity_ = isoJoIdentity; // Backup since it can be modified if L is not full rank
246 
247  std::map<std::string, vpVelocityTwistMatrix> mapOfVelocityTwist;
248  for(std::map<std::string, vpHomogeneousMatrix>::const_iterator it = m_mapOfCameraTransformationMatrix.begin();
249  it != m_mapOfCameraTransformationMatrix.end(); ++it) {
251  cVo.buildFrom(it->second);
252  mapOfVelocityTwist[it->first] = cVo;
253  }
254 
255 // std::cout << "\n\n\ncMo used before the first phase=\n" << cMo << std::endl;
256 
257  /*** First phase ***/
258 
259  while(reloop == true && iter < 10)
260  {
261  m_w.resize(0);
262  m_error.resize(0);
263 
264  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
265  it != m_mapOfEdgeTrackers.end(); ++it) {
266  it->second->cMo = m_mapOfCameraTransformationMatrix[it->first] * cMo;
267  }
268 
269  if(iter == 0)
270  {
271  weighted_error.resize(nerror);
272 
273  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
274  it != m_mapOfEdgeTrackers.end(); ++it) {
275  it->second->m_w.resize(mapOfNumberOfRows[it->first]);
276  it->second->m_w = 0;
277 
278  it->second->m_error.resize(mapOfNumberOfRows[it->first]);
279 
280  mapOfFactors[it->first].resize(mapOfNumberOfRows[it->first]);
281  mapOfFactors[it->first] = 1;
282  }
283  }
284 
285  double count = 0;
286  reloop = false;
287 
288  L = vpMatrix();
289  factor = vpColVector();
290 
291 
292  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
293  it != m_mapOfEdgeTrackers.end(); ++it) {
294  vpMatrix L_tmp(mapOfNumberOfRows[it->first], 6);
295 
296  double count_tmp = 0.0;
297  it->second->computeVVSFirstPhase(*mapOfImages[it->first], iter, L_tmp, mapOfFactors[it->first], count_tmp,
298  it->second->m_error, it->second->m_w, lvl);
299  count += count_tmp;
300 
301  L_tmp = L_tmp*mapOfVelocityTwist[it->first];
302 
303  L.stack(L_tmp);
304  factor.stack(mapOfFactors[it->first]);
305  m_w.stack(it->second->m_w);
306  m_error.stack(it->second->m_error);
307  }
308 
309  count = count / (double) nbrow;
310  if (count < 0.85) {
311  reloop = true;
312  }
313 
314  computeVVSFirstPhasePoseEstimation(nerror, iter, factor, weighted_error, L, isoJoIdentity_);
315 
316  iter++;
317  }
318 
319 // std::cout << "\n\t First minimization in " << iter << " iteration give as initial cMo: \n" << cMo << std::endl;
320 // std::cout << "Residual=" << m_error.sum() / m_error.size() << std::endl;
321 
322 
323  /*** Second phase ***/
324 
325  //Variables for individual weights
326  std::map<std::string, vpRobust> mapOfRobustLines;
327  std::map<std::string, vpRobust> mapOfRobustCylinders;
328  std::map<std::string, vpRobust> mapOfRobustCircles;
329  //Init map of robust
330  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
331  it != m_mapOfEdgeTrackers.end(); ++it) {
332  mapOfRobustLines[it->first] = vpRobust(mapOfNumberOfLines[it->first]);
333  mapOfRobustLines[it->first].setIteration(0);
334 
335  mapOfRobustCylinders[it->first] = vpRobust(mapOfNumberOfCylinders[it->first]);
336  mapOfRobustCylinders[it->first].setIteration(0);
337 
338  mapOfRobustCircles[it->first] = vpRobust(mapOfNumberOfCircles[it->first]);
339  mapOfRobustCircles[it->first].setIteration(0);
340  }
341 
342  vpColVector w_lines;
343  vpColVector w_cylinders;
344  vpColVector w_circles;
345 
346  std::map<std::string, vpColVector> mapOfWeightLines;
347  std::map<std::string, vpColVector> mapOfWeightCylinders;
348  std::map<std::string, vpColVector> mapOfWeightCircles;
349 
350  iter = 0;
351 
352  vpColVector error_lines;
353  vpColVector error_cylinders;
354  vpColVector error_circles;
355 
356  vpHomogeneousMatrix cMoPrev;
357  vpColVector W_true;
358  vpMatrix L_true;
359  vpMatrix LVJ_true;
360 
361  double mu = 0.01;
362  vpColVector m_error_prev(nbrow);
363  vpColVector m_w_prev(nbrow);
364 
365  double residu_1 = 1e3;
366  double r =1e3-1;
367 
368  //while ( ((int)((residu_1 - r)*1e8) != 0 ) && (iter<30))
369  while(std::fabs((residu_1 - r)*1e8) > std::numeric_limits<double>::epsilon() && (iter<30))
370  {
371  L.resize(0,0);
372  m_error.resize(0);
373 
374  error_lines.resize(0);
375  error_cylinders.resize(0);
376  error_circles.resize(0);
377 
378  std::map<std::string, vpColVector> mapOfErrorLines;
379  std::map<std::string, vpColVector> mapOfErrorCylinders;
380  std::map<std::string, vpColVector> mapOfErrorCircles;
381 
382  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
383  it != m_mapOfEdgeTrackers.end(); ++it) {
384  vpMatrix L_tmp(mapOfNumberOfRows[it->first], 6);
385  vpColVector error_lines_tmp(mapOfNumberOfLines[it->first]);
386  vpColVector error_cylinders_tmp(mapOfNumberOfCylinders[it->first]);
387  vpColVector error_circles_tmp(mapOfNumberOfCircles[it->first]);
388 
389  it->second->cMo = m_mapOfCameraTransformationMatrix[it->first]*cMo;
390 
391  vpColVector error_tmp;
392  error_tmp.resize(mapOfNumberOfRows[it->first]);
393 
394  it->second->computeVVSSecondPhase(*mapOfImages[it->first], L_tmp, error_lines_tmp,
395  error_cylinders_tmp, error_circles_tmp, error_tmp, lvl);
396  L_tmp = L_tmp*mapOfVelocityTwist[it->first];
397 
398  L.stack(L_tmp);
399  m_error.stack(error_tmp);
400 
401  error_lines.stack(error_lines_tmp);
402  error_cylinders.stack(error_cylinders_tmp);
403  error_circles.stack(error_circles_tmp);
404 
405  mapOfErrorLines[it->first] = error_lines_tmp;
406  mapOfErrorCylinders[it->first] = error_cylinders_tmp;
407  mapOfErrorCircles[it->first] = error_circles_tmp;
408  }
409 
410  bool reStartFromLastIncrement = false;
411  computeVVSSecondPhaseCheckLevenbergMarquardt(iter, nbrow, m_error_prev, m_w_prev, cMoPrev, mu, reStartFromLastIncrement);
412 
413  if(!reStartFromLastIncrement) {
414  w_lines.resize(0);
415  w_cylinders.resize(0);
416  w_circles.resize(0);
417 
418  computeVVSSecondPhaseWeights(iter, nerror, weighted_error, w_lines, w_cylinders, w_circles, mapOfNumberOfLines,
419  mapOfNumberOfCylinders, mapOfNumberOfCircles, mapOfWeightLines, mapOfWeightCylinders, mapOfWeightCircles,
420  mapOfErrorLines, mapOfErrorCylinders, mapOfErrorCircles, mapOfRobustLines, mapOfRobustCylinders,
421  mapOfRobustCircles, 2.0);
422 
423  if(iter == 0) {
424  m_w.resize(nerror);
425  m_w = 1;
426  }
427 
428  for(unsigned int cpt = 0, cpt_lines = 0, cpt_cylinders = 0, cpt_circles = 0; cpt < nbrow; cpt++) {
429  switch(indexOfFeatures[cpt]) {
430  case LINE:
431  m_w[cpt] = w_lines[cpt_lines];
432  cpt_lines++;
433  break;
434 
435  case CYLINDER:
436  m_w[cpt] = w_cylinders[cpt_cylinders];
437  cpt_cylinders++;
438  break;
439 
440  case CIRCLE:
441  m_w[cpt] = w_circles[cpt_circles];
442  cpt_circles++;
443  break;
444 
445  default:
446  std::cerr << "Problem with feature type !" << std::endl;
447  break;
448  }
449  }
450 
451  computeVVSSecondPhasePoseEstimation(nerror, L, L_true, LVJ_true, W_true, factor, iter, isoJoIdentity_,
452  weighted_error, mu, m_error_prev, m_w_prev, cMoPrev, residu_1, r);
453  }
454 
455  iter++;
456  }
457 
458 // std::cout << "VVS estimate pose cMo:\n" << cMo << std::endl;
459 
460  if(computeCovariance){
461  vpMatrix D;
462  D.diag(W_true);
463 
464  // Note that here the covariance is computed on cMoPrev for time computation efficiency
465  if(isoJoIdentity_){
467  }
468  else{
470  }
471  }
472 
473  unsigned int cpt = 0;
474  for(std::map<std::string, unsigned int>::const_iterator it = mapOfNumberOfRows.begin(); it != mapOfNumberOfRows.end(); ++it) {
475  for(unsigned int i = 0; i < mapOfNumberOfRows[it->first]; i++) {
476  m_mapOfEdgeTrackers[it->first]->m_w[i] = m_w[i+cpt];
477  }
478  m_mapOfEdgeTrackers[it->first]->updateMovingEdgeWeights();
479  cpt += mapOfNumberOfRows[it->first];
480  }
481 }
482 
483 void vpMbEdgeMultiTracker::computeVVSSecondPhaseWeights(const unsigned int iter, const unsigned int nerror,
484  vpColVector &weighted_error, vpColVector &w_lines, vpColVector &w_cylinders, vpColVector &w_circles,
485  std::map<std::string, unsigned int> &mapOfNumberOfLines,
486  std::map<std::string, unsigned int> &mapOfNumberOfCylinders, std::map<std::string, unsigned int> &mapOfNumberOfCircles,
487  std::map<std::string, vpColVector> &mapOfWeightLines, std::map<std::string, vpColVector> &mapOfWeightCylinders,
488  std::map<std::string, vpColVector> &mapOfWeightCircles, std::map<std::string, vpColVector> &mapOfErrorLines,
489  std::map<std::string, vpColVector> &mapOfErrorCylinders, std::map<std::string, vpColVector> &mapOfErrorCircles,
490  std::map<std::string, vpRobust> &mapOfRobustLines, std::map<std::string, vpRobust> &mapOfRobustCylinders,
491  std::map<std::string, vpRobust> &mapOfRobustCircles, double threshold) {
492  if(iter == 0)
493  {
494  weighted_error.resize(nerror);
495 
496  //Init weight size
497  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
498  it != m_mapOfEdgeTrackers.end(); ++it) {
499  mapOfWeightLines[it->first].resize(mapOfNumberOfLines[it->first]);
500  mapOfWeightLines[it->first] = 1;
501 
502  mapOfWeightCylinders[it->first].resize(mapOfNumberOfCylinders[it->first]);
503  mapOfWeightCylinders[it->first] = 1;
504 
505  mapOfWeightCircles[it->first].resize(mapOfNumberOfCircles[it->first]);
506  mapOfWeightCircles[it->first] = 1;
507  }
508 
509  //Set threshold for each robust
510  for(std::map<std::string, vpRobust>::iterator it = mapOfRobustLines.begin(); it != mapOfRobustLines.end(); ++it) {
511  vpCameraParameters current_cam;
512  m_mapOfEdgeTrackers[it->first]->getCameraParameters(current_cam);
513  it->second.setThreshold(threshold / current_cam.get_px());
514  }
515 
516  for(std::map<std::string, vpRobust>::iterator it = mapOfRobustCylinders.begin(); it != mapOfRobustCylinders.end(); ++it) {
517  vpCameraParameters current_cam;
518  m_mapOfEdgeTrackers[it->first]->getCameraParameters(current_cam);
519  it->second.setThreshold(threshold / current_cam.get_px());
520  }
521 
522  for(std::map<std::string, vpRobust>::iterator it = mapOfRobustCircles.begin(); it != mapOfRobustCircles.end(); ++it) {
523  vpCameraParameters current_cam;
524  m_mapOfEdgeTrackers[it->first]->getCameraParameters(current_cam);
525  it->second.setThreshold( vpMath::sqr(threshold / current_cam.get_px()) );
526  }
527 
528  //Compute weights
529  for(std::map<std::string, vpColVector>::const_iterator it = mapOfErrorLines.begin();
530  it != mapOfErrorLines.end(); ++it) {
531  if(mapOfNumberOfLines[it->first] > 0) {
532  mapOfRobustLines[it->first].MEstimator(vpRobust::TUKEY, it->second, mapOfWeightLines[it->first]);
533 
534  //Stack weights
535  w_lines.stack(mapOfWeightLines[it->first]);
536  }
537  }
538 
539  for(std::map<std::string, vpColVector>::const_iterator it = mapOfErrorCylinders.begin();
540  it != mapOfErrorCylinders.end(); ++it) {
541  if(mapOfNumberOfCylinders[it->first] > 0) {
542  mapOfRobustCylinders[it->first].MEstimator(vpRobust::TUKEY, it->second, mapOfWeightCylinders[it->first]);
543 
544  //Stack weights
545  w_cylinders.stack(mapOfWeightCylinders[it->first]);
546  }
547  }
548 
549  for(std::map<std::string, vpColVector>::const_iterator it = mapOfErrorCircles.begin();
550  it != mapOfErrorCircles.end(); ++it) {
551  if(mapOfNumberOfCircles[it->first] > 0) {
552  mapOfRobustCircles[it->first].MEstimator(vpRobust::TUKEY, it->second, mapOfWeightCircles[it->first]);
553 
554  //Stack weights
555  w_circles.stack(mapOfWeightCircles[it->first]);
556  }
557  }
558  }
559  else
560  {
561  //Set iteration for each robust
562  for(std::map<std::string, vpRobust>::iterator it = mapOfRobustLines.begin(); it != mapOfRobustLines.end(); ++it) {
563  it->second.setIteration(iter);
564  }
565 
566  for(std::map<std::string, vpRobust>::iterator it = mapOfRobustCylinders.begin(); it != mapOfRobustCylinders.end(); ++it) {
567  it->second.setIteration(iter);
568  }
569 
570  for(std::map<std::string, vpRobust>::iterator it = mapOfRobustCircles.begin(); it != mapOfRobustCircles.end(); ++it) {
571  it->second.setIteration(iter);
572  }
573 
574  //Compute weights
575  for(std::map<std::string, vpColVector>::const_iterator it = mapOfErrorLines.begin();
576  it != mapOfErrorLines.end(); ++it) {
577  if(mapOfNumberOfLines[it->first] > 0) {
578  mapOfRobustLines[it->first].MEstimator(vpRobust::TUKEY, it->second, mapOfWeightLines[it->first]);
579 
580  //Stack weights
581  w_lines.stack(mapOfWeightLines[it->first]);
582  }
583  }
584 
585  for(std::map<std::string, vpColVector>::const_iterator it = mapOfErrorCylinders.begin();
586  it != mapOfErrorCylinders.end(); ++it) {
587  if(mapOfNumberOfCylinders[it->first] > 0) {
588  mapOfRobustCylinders[it->first].MEstimator(vpRobust::TUKEY, it->second, mapOfWeightCylinders[it->first]);
589 
590  //Stack weights
591  w_cylinders.stack(mapOfWeightCylinders[it->first]);
592  }
593  }
594 
595  for(std::map<std::string, vpColVector>::const_iterator it = mapOfErrorCircles.begin();
596  it != mapOfErrorCircles.end(); ++it) {
597  if(mapOfNumberOfCircles[it->first] > 0) {
598  mapOfRobustCircles[it->first].MEstimator(vpRobust::TUKEY, it->second, mapOfWeightCircles[it->first]);
599 
600  //Stack weights
601  w_circles.stack(mapOfWeightCircles[it->first]);
602  }
603  }
604  }
605 }
606 
618  const vpCameraParameters &cam_, const vpColor& col, const unsigned int thickness, const bool displayFullModel) {
619 
620  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
621  if(it != m_mapOfEdgeTrackers.end()) {
622  it->second->display(I, cMo_, cam_, col, thickness, displayFullModel);
623  } else {
624  std::cerr << "Cannot find reference camera: " << m_referenceCameraName << " !" << std::endl;
625  }
626 }
627 
639  const vpColor& col, const unsigned int thickness, const bool displayFullModel) {
640 
641  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
642  if(it != m_mapOfEdgeTrackers.end()) {
643  it->second->display(I, cMo_, cam_, col, thickness, displayFullModel);
644  } else {
645  std::cerr << "Cannot find reference camera: " << m_referenceCameraName << " !" << std::endl;
646  }
647 }
648 
663  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1,
664  const vpCameraParameters &cam2, const vpColor& col, const unsigned int thickness, const bool displayFullModel) {
665 
666  if(m_mapOfEdgeTrackers.size() == 2) {
667  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
668  it->second->display(I1, c1Mo, cam1, col, thickness, displayFullModel);
669  ++it;
670 
671  it->second->display(I2, c2Mo, cam2, col, thickness, displayFullModel);
672  } else {
673  std::cerr << "This display is only for the stereo case ! There are "
674  << m_mapOfEdgeTrackers.size() << " camera !" << std::endl;
675  }
676 }
677 
692  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1,
693  const vpCameraParameters &cam2, const vpColor& col, const unsigned int thickness, const bool displayFullModel) {
694 
695  if(m_mapOfEdgeTrackers.size() == 2) {
696  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
697  it->second->display(I1, c1Mo, cam1, col, thickness, displayFullModel);
698  ++it;
699 
700  it->second->display(I2, c2Mo, cam2, col, thickness, displayFullModel);
701  } else {
702  std::cerr << "This display is only for the stereo case ! There are "
703  << m_mapOfEdgeTrackers.size() << " cameras !" << std::endl;
704  }
705 }
706 
717 void vpMbEdgeMultiTracker::display(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
718  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
719  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters,
720  const vpColor& col, const unsigned int thickness, const bool displayFullModel) {
721 
722  //Display only for the given images
723  for(std::map<std::string, const vpImage<unsigned char> *>::const_iterator it_img = mapOfImages.begin();
724  it_img != mapOfImages.end(); ++it_img) {
725  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(it_img->first);
726  std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camPose = mapOfCameraPoses.find(it_img->first);
727  std::map<std::string, vpCameraParameters>::const_iterator it_cam = mapOfCameraParameters.find(it_img->first);
728 
729  if(it_edge != m_mapOfEdgeTrackers.end() && it_camPose != mapOfCameraPoses.end() && it_cam != mapOfCameraParameters.end()) {
730  it_edge->second->display(*it_img->second, it_camPose->second, it_cam->second, col, thickness, displayFullModel);
731  } else {
732  std::cerr << "Missing elements !" << std::endl;
733  }
734  }
735 }
736 
747 void vpMbEdgeMultiTracker::display(const std::map<std::string, const vpImage<vpRGBa> *> &mapOfImages,
748  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
749  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters,
750  const vpColor& col, const unsigned int thickness, const bool displayFullModel) {
751 
752  //Display only for the given images
753  for(std::map<std::string, const vpImage<vpRGBa> *>::const_iterator it_img = mapOfImages.begin();
754  it_img != mapOfImages.end(); ++it_img) {
755  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(it_img->first);
756  std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camPose = mapOfCameraPoses.find(it_img->first);
757  std::map<std::string, vpCameraParameters>::const_iterator it_cam = mapOfCameraParameters.find(it_img->first);
758 
759  if(it_edge != m_mapOfEdgeTrackers.end() && it_camPose != mapOfCameraPoses.end() && it_cam != mapOfCameraParameters.end()) {
760  it_edge->second->display(*it_img->second, it_camPose->second, it_cam->second, col, thickness, displayFullModel);
761  } else {
762  std::cerr << "Missing elements !" << std::endl;
763  }
764  }
765 }
766 
772 std::vector<std::string> vpMbEdgeMultiTracker::getCameraNames() const {
773  std::vector<std::string> cameraNames;
774 
775  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.begin();
776  it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
777  cameraNames.push_back(it_edge->first);
778  }
779 
780  return cameraNames;
781 }
782 
789  //Get the reference camera parameters
790  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
791  if(it != m_mapOfEdgeTrackers.end()) {
792  it->second->getCameraParameters(camera);
793  } else {
794  std::cerr << "The reference camera name: " << m_referenceCameraName << " does not exist !" << std::endl;
795  }
796 }
797 
805  if(m_mapOfEdgeTrackers.size() == 2) {
806  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
807  it->second->getCameraParameters(cam1);
808  ++it;
809 
810  it->second->getCameraParameters(cam2);
811  } else {
812  std::cerr << "Problem with the number of cameras ! There are "
813  << m_mapOfEdgeTrackers.size() << " cameras !" << std::endl;
814  }
815 }
816 
823 void vpMbEdgeMultiTracker::getCameraParameters(const std::string &cameraName, vpCameraParameters &camera) const {
824  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
825  if(it != m_mapOfEdgeTrackers.end()) {
826  it->second->getCameraParameters(camera);
827  } else {
828  std::cerr << "The camera: " << cameraName << " does not exist !" << std::endl;
829  }
830 }
831 
837 void vpMbEdgeMultiTracker::getCameraParameters(std::map<std::string, vpCameraParameters> &mapOfCameraParameters) const {
838  //Clear the input map
839  mapOfCameraParameters.clear();
840 
841  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
842  it != m_mapOfEdgeTrackers.end(); ++it) {
843  vpCameraParameters cam_;
844  it->second->getCameraParameters(cam_);
845  mapOfCameraParameters[it->first] = cam_;
846  }
847 }
848 
855 unsigned int vpMbEdgeMultiTracker::getClipping(const std::string &cameraName) const {
856  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
857  if(it != m_mapOfEdgeTrackers.end()) {
858  return it->second->getClipping();
859  } else {
860  std::cerr << "Cannot find camera: " << cameraName << std::endl;
861  }
862 
863  return vpMbTracker::getClipping();
864 }
865 
872  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
873  if(it != m_mapOfEdgeTrackers.end()) {
874  return it->second->getFaces();
875  }
876 
877  std::cerr << "The reference camera: " << m_referenceCameraName << " cannot be found !" << std::endl;
878  return faces;
879 }
880 
887  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
888  if(it != m_mapOfEdgeTrackers.end()) {
889  return it->second->getFaces();
890  }
891 
892  std::cerr << "The camera: " << cameraName << " cannot be found !" << std::endl;
893  return faces;
894 }
895 
901 std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > vpMbEdgeMultiTracker::getFaces() const {
902  std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > mapOfFaces;
903  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
904  it != m_mapOfEdgeTrackers.end(); ++it) {
905  mapOfFaces[it->first] = it->second->faces;
906  }
907 
908  return mapOfFaces;
909 }
910 
921 void vpMbEdgeMultiTracker::getLcircle(std::list<vpMbtDistanceCircle *>& circlesList, const unsigned int level) const {
922  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
923 
924  if(it_edge != m_mapOfEdgeTrackers.end()) {
925  it_edge->second->getLcircle(circlesList, level);
926  } else {
927  std::cerr << "Cannot find reference camera: " << m_referenceCameraName << " !" << std::endl;
928  }
929 }
930 
942 void vpMbEdgeMultiTracker::getLcircle(const std::string &cameraName, std::list<vpMbtDistanceCircle *>& circlesList,
943  const unsigned int level) const {
944  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
945  if(it != m_mapOfEdgeTrackers.end()) {
946  it->second->getLcircle(circlesList, level);
947  } else {
948  std::cerr << "The camera: " << cameraName << " does not exist !" << std::endl;
949  }
950 }
951 
962 void vpMbEdgeMultiTracker::getLcylinder(std::list<vpMbtDistanceCylinder *>& cylindersList, const unsigned int level) const {
963  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
964 
965  if(it_edge != m_mapOfEdgeTrackers.end()) {
966  it_edge->second->getLcylinder(cylindersList, level);
967  } else {
968  std::cerr << "Cannot find reference camera: " << m_referenceCameraName << " !" << std::endl;
969  }
970 }
971 
983 void vpMbEdgeMultiTracker::getLcylinder(const std::string &cameraName, std::list<vpMbtDistanceCylinder *>& cylindersList,
984  const unsigned int level) const {
985  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
986  if(it != m_mapOfEdgeTrackers.end()) {
987  it->second->getLcylinder(cylindersList, level);
988  } else {
989  std::cerr << "The camera: " << cameraName << " does not exist !" << std::endl;
990  }
991 }
992 
1003 void vpMbEdgeMultiTracker::getLline(std::list<vpMbtDistanceLine *>& linesList, const unsigned int level) const {
1004  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1005 
1006  if(it_edge != m_mapOfEdgeTrackers.end()) {
1007  it_edge->second->getLline(linesList, level);
1008  } else {
1009  std::cerr << "Cannot find reference camera: " << m_referenceCameraName << " !" << std::endl;
1010  }
1011 }
1012 
1024 void vpMbEdgeMultiTracker::getLline(const std::string &cameraName, std::list<vpMbtDistanceLine *>& linesList,
1025  const unsigned int level) const {
1026  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
1027  if(it != m_mapOfEdgeTrackers.end()) {
1028  it->second->getLline(linesList, level);
1029  } else {
1030  std::cerr << "The camera: " << cameraName << " does not exist !" << std::endl;
1031  }
1032 }
1033 
1041  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1042  if(it_edge != m_mapOfEdgeTrackers.end()) {
1043  it_edge->second->getMovingEdge(p_me);
1044  } else {
1045  std::cerr << "The reference camera: " << m_referenceCameraName << " does not exist !" << std::endl;
1046  }
1047 }
1048 
1055  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1056  vpMe me_tmp;
1057  if(it_edge != m_mapOfEdgeTrackers.end()) {
1058  it_edge->second->getMovingEdge(me_tmp);
1059  } else {
1060  std::cerr << "The reference camera: " << m_referenceCameraName << " does not exist !" << std::endl;
1061  }
1062 
1063  return me_tmp;
1064 }
1065 
1073 void vpMbEdgeMultiTracker::getMovingEdge(const std::string &cameraName, vpMe &p_me) const {
1074  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
1075  if(it != m_mapOfEdgeTrackers.end()) {
1076  it->second->getMovingEdge(p_me);
1077  } else {
1078  std::cerr << "The camera: " << cameraName << " does not exist !" << std::endl;
1079  }
1080 }
1081 
1089 vpMe vpMbEdgeMultiTracker::getMovingEdge(const std::string &cameraName) const {
1090  vpMe me_tmp;
1091  getMovingEdge(cameraName, me_tmp);
1092  return me_tmp;
1093 }
1094 
1107 unsigned int vpMbEdgeMultiTracker::getNbPoints(const unsigned int level) const {
1108  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1109 
1110  unsigned int nbGoodPoints = 0;
1111  if (it_edge != m_mapOfEdgeTrackers.end()) {
1112 
1113  nbGoodPoints += it_edge->second->getNbPoints(level);
1114  } else {
1115  std::cerr << "The reference camera: " << m_referenceCameraName << " does not exist !" << std::endl;
1116  }
1117 
1118  return nbGoodPoints;
1119 }
1120 
1134 unsigned int vpMbEdgeMultiTracker::getNbPoints(const std::string &cameraName, const unsigned int level) const {
1135  std::map<std::string, vpMbEdgeTracker *>::const_iterator it =
1136  m_mapOfEdgeTrackers.find(cameraName);
1137  if (it != m_mapOfEdgeTrackers.end()) {
1138  return it->second->getNbPoints(level);
1139  } else {
1140  std::cerr << "The camera: " << cameraName << " does not exist !"
1141  << std::endl;
1142  }
1143 
1144  return 0;
1145 }
1146 
1153  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1154  if(it != m_mapOfEdgeTrackers.end()) {
1155  return it->second->getNbPolygon();
1156  }
1157 
1158  std::cerr << "The reference camera: " << m_referenceCameraName << " cannot be found !" << std::endl;
1159  return 0;
1160 }
1161 
1167 unsigned int vpMbEdgeMultiTracker::getNbPolygon(const std::string &cameraName) const {
1168  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
1169  if(it != m_mapOfEdgeTrackers.end()) {
1170  return it->second->getNbPolygon();
1171  }
1172 
1173  std::cerr << "The camera: " << cameraName << " cannot be found !" << std::endl;
1174  return 0;
1175 }
1176 
1182 std::map<std::string, unsigned int> vpMbEdgeMultiTracker::getMultiNbPolygon() const {
1183  std::map<std::string, unsigned int> mapOfNbPolygons;
1184  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
1185  it != m_mapOfEdgeTrackers.end(); ++it) {
1186  mapOfNbPolygons[it->first] = it->second->getNbPolygon();
1187  }
1188 
1189  return mapOfNbPolygons;
1190 }
1191 
1199  if (m_mapOfEdgeTrackers.size() == 2) {
1200  std::map<std::string, vpMbEdgeTracker *>::const_iterator it =
1201  m_mapOfEdgeTrackers.begin();
1202  it->second->getPose(c1Mo);
1203  ++it;
1204 
1205  it->second->getPose(c2Mo);
1206  } else {
1207  std::cerr << "Require two cameras ! There are "
1208  << m_mapOfEdgeTrackers.size() << " cameras !" << std::endl;
1209  }
1210 }
1211 
1220 void vpMbEdgeMultiTracker::getPose(const std::string &cameraName, vpHomogeneousMatrix &cMo_) const {
1221  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
1222  if(it != m_mapOfEdgeTrackers.end()) {
1223  it->second->getPose(cMo_);
1224  } else {
1225  std::cerr << "The camera: " << cameraName << " does not exist !" << std::endl;
1226  }
1227 }
1228 
1234 void vpMbEdgeMultiTracker::getPose(std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) const {
1235  //Clear the map
1236  mapOfCameraPoses.clear();
1237 
1238  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
1239  it != m_mapOfEdgeTrackers.end(); ++it) {
1240  vpHomogeneousMatrix cMo_;
1241  it->second->getPose(cMo_);
1242  mapOfCameraPoses[it->first] = cMo_;
1243  }
1244 }
1245 
1247 }
1248 
1249 #ifdef VISP_HAVE_MODULE_GUI
1250 
1259 void vpMbEdgeMultiTracker::initClick(const vpImage<unsigned char>& I, const std::vector<vpPoint> &points3D_list,
1260  const std::string &displayFile) {
1261  if(m_mapOfEdgeTrackers.empty()) {
1262  throw vpException(vpTrackingException::initializationError, "There is no camera !");
1263  } else if(m_mapOfEdgeTrackers.size() > 1) {
1264  throw vpException(vpTrackingException::initializationError, "There is more than one camera !");
1265  } else {
1266  //Get the vpMbEdgeTracker object for the reference camera name
1267  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1268  if(it != m_mapOfEdgeTrackers.end()) {
1269  it->second->initClick(I, points3D_list, displayFile);
1270  it->second->getPose(cMo);
1271  } else {
1272  std::stringstream ss;
1273  ss << "Cannot initClick as the reference camera: " << m_referenceCameraName << " does not exist !";
1275  }
1276  }
1277 }
1278 
1299 void vpMbEdgeMultiTracker::initClick(const vpImage<unsigned char>& I, const std::string& initFile, const bool displayHelp) {
1300  if(m_mapOfEdgeTrackers.empty()) {
1301  throw vpException(vpTrackingException::initializationError, "There is no camera !");
1302  } else if(m_mapOfEdgeTrackers.size() > 1) {
1303  throw vpException(vpTrackingException::initializationError, "There is more than one camera !");
1304  } else {
1305  //Get the vpMbEdgeTracker object for the reference camera name
1306  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1307  if(it != m_mapOfEdgeTrackers.end()) {
1308  it->second->initClick(I, initFile, displayHelp);
1309  it->second->getPose(cMo);
1310  } else {
1311  std::stringstream ss;
1312  ss << "Cannot initClick as the reference camera: " << m_referenceCameraName << " does not exist !";
1314  }
1315  }
1316 }
1317 
1342  const std::string& initFile1, const std::string& initFile2, const bool displayHelp, const bool firstCameraIsReference) {
1343  if(m_mapOfEdgeTrackers.size() == 2) {
1344  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
1345  it->second->initClick(I1, initFile1, displayHelp);
1346 
1347  if(firstCameraIsReference) {
1348  //Set the reference cMo
1349  it->second->getPose(cMo);
1350 
1351  //Set the reference camera parameters
1352  it->second->getCameraParameters(this->cam);
1353  }
1354 
1355  ++it;
1356 
1357  it->second->initClick(I2, initFile2, displayHelp);
1358 
1359  if(!firstCameraIsReference) {
1360  //Set the reference cMo
1361  it->second->getPose(cMo);
1362 
1363  //Set the reference camera parameters
1364  it->second->getCameraParameters(this->cam);
1365  }
1366  } else {
1367  std::stringstream ss;
1368  ss << "Cannot init click ! Require two cameras but there are " << m_mapOfEdgeTrackers.size() << " cameras !";
1370  }
1371 }
1372 
1394 void vpMbEdgeMultiTracker::initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1395  const std::string &initFile, const bool displayHelp) {
1396  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1397  if(it_edge != m_mapOfEdgeTrackers.end()) {
1398  std::map<std::string, const vpImage<unsigned char> *>::const_iterator it_img = mapOfImages.find(m_referenceCameraName);
1399 
1400  if(it_img != mapOfImages.end()) {
1401  //Init click on reference camera
1402  it_edge->second->initClick(*it_img->second, initFile, displayHelp);
1403 
1404  //Set the reference cMo
1405  it_edge->second->getPose(cMo);
1406 
1407  //Set the pose for the others cameras
1408  for(it_edge = m_mapOfEdgeTrackers.begin(); it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
1409  if(it_edge->first != m_referenceCameraName) {
1410  it_img = mapOfImages.find(it_edge->first);
1411  std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camTrans =
1412  m_mapOfCameraTransformationMatrix.find(it_edge->first);
1413 
1414  if(it_img != mapOfImages.end() && it_camTrans != m_mapOfCameraTransformationMatrix.end()) {
1415  vpHomogeneousMatrix cCurrentMo = it_camTrans->second * cMo;
1416  it_edge->second->setPose(*it_img->second, cCurrentMo);
1417  } else {
1418  std::stringstream ss;
1419  ss << "Cannot init click ! Missing image for camera: " << m_referenceCameraName << " !";
1421  }
1422  }
1423  }
1424  } else {
1425  std::stringstream ss;
1426  ss << "Cannot init click ! Missing image for camera: " << m_referenceCameraName << " !";
1428  }
1429  } else {
1430  std::stringstream ss;
1431  ss << "Cannot init click ! The reference camera: " << m_referenceCameraName << " does not exist !";
1433  }
1434 }
1435 
1458 void vpMbEdgeMultiTracker::initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1459  const std::map<std::string, std::string> &mapOfInitFiles, const bool displayHelp) {
1460  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1461  std::map<std::string, const vpImage<unsigned char>* >::const_iterator it_img = mapOfImages.find(m_referenceCameraName);
1462  std::map<std::string, std::string>::const_iterator it_initFile = mapOfInitFiles.find(m_referenceCameraName);
1463 
1464  if(it_edge != m_mapOfEdgeTrackers.end() && it_img != mapOfImages.end() && it_initFile != mapOfInitFiles.end()) {
1465  //InitClick for the reference camera
1466  it_edge->second->initClick(*it_img->second, it_initFile->second, displayHelp);
1467 
1468  //Get reference camera pose
1469  it_edge->second->getPose(cMo);
1470  } else {
1471  throw vpException(vpTrackingException::initializationError, "Cannot initClick for the reference camera !");
1472  }
1473 
1474  //Vector of missing pose matrices for cameras
1475  std::vector<std::string> vectorOfMissingCameraPoses;
1476 
1477  //InitClick for all the cameras that have an initFile
1478  for(it_edge = m_mapOfEdgeTrackers.begin(); it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
1479  if(it_edge->first != m_referenceCameraName) {
1480  it_img = mapOfImages.find(it_edge->first);
1481  it_initFile = mapOfInitFiles.find(it_edge->first);
1482 
1483  if(it_img != mapOfImages.end() && it_initFile != mapOfInitFiles.end()) {
1484  it_edge->second->initClick(*it_img->second, it_initFile->second, displayHelp);
1485  } else {
1486  vectorOfMissingCameraPoses.push_back(it_edge->first);
1487  }
1488  }
1489  }
1490 
1491  //SetPose for cameras that do not have an initFile
1492  for(std::vector<std::string>::const_iterator it1 = vectorOfMissingCameraPoses.begin();
1493  it1 != vectorOfMissingCameraPoses.end(); ++it1) {
1494  it_img = mapOfImages.find(*it1);
1495  std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camTrans = m_mapOfCameraTransformationMatrix.find(*it1);
1496 
1497  if(it_img != mapOfImages.end() && it_camTrans != m_mapOfCameraTransformationMatrix.end()) {
1498  vpHomogeneousMatrix cCurrentMo = it_camTrans->second * cMo;
1499  m_mapOfEdgeTrackers[*it1]->setPose(*it_img->second, cCurrentMo);
1500  } else {
1501  std::stringstream ss;
1502  ss << "Missing image or missing camera transformation matrix ! Cannot set the pose for camera: " << (*it1) << " !";
1504  }
1505  }
1506 }
1507 #endif //#ifdef VISP_HAVE_MODULE_GUI
1508 
1527 void vpMbEdgeMultiTracker::initFromPose(const vpImage<unsigned char>& I, const std::string &initFile) {
1528  //Monocular case only !
1529  if(m_mapOfEdgeTrackers.size() > 1) {
1530  throw vpException(vpTrackingException::initializationError, "This method can only be used for the monocular case !");
1531  }
1532 
1533  char s[FILENAME_MAX];
1534  std::fstream finit ;
1535  vpPoseVector init_pos;
1536 
1537  std::string ext = ".pos";
1538  size_t pos = initFile.rfind(ext);
1539 
1540  if( pos == initFile.size()-ext.size() && pos != 0)
1541  sprintf(s,"%s", initFile.c_str());
1542  else
1543  sprintf(s,"%s.pos", initFile.c_str());
1544 
1545  finit.open(s,std::ios::in) ;
1546  if (finit.fail()){
1547  std::cerr << "cannot read " << s << std::endl;
1548  throw vpException(vpException::ioError, "cannot read init file");
1549  }
1550 
1551  for (unsigned int i = 0; i < 6; i += 1){
1552  finit >> init_pos[i];
1553  }
1554 
1555  //Set the new pose for the reference camera
1556  cMo.buildFrom(init_pos);
1557 
1558  //Init for the reference camera
1559  std::map<std::string, vpMbEdgeTracker *>::iterator it_ref = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1560  if(it_ref == m_mapOfEdgeTrackers.end()) {
1561  throw vpException(vpTrackingException::initializationError, "Cannot find the reference camera !");
1562  }
1563 
1564  it_ref->second->cMo = cMo;
1565  it_ref->second->init(I);
1566 }
1567 
1575  if(m_mapOfEdgeTrackers.size() != 1) {
1576  std::stringstream ss;
1577  ss << "This method requires exactly one camera, there are " << m_mapOfEdgeTrackers.size() << " cameras !";
1579  }
1580 
1581  this->cMo = cMo_;
1582 
1583  //Init for the reference camera
1584  std::map<std::string, vpMbEdgeTracker *>::iterator it_ref = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1585  if(it_ref == m_mapOfEdgeTrackers.end()) {
1586  throw vpException(vpTrackingException::initializationError, "Cannot find the reference camera !");
1587  }
1588 
1589  it_ref->second->cMo = cMo;
1590  it_ref->second->init(I);
1591 }
1592 
1600  vpHomogeneousMatrix _cMo(cPo);
1602 }
1603 
1614  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const bool firstCameraIsReference) {
1615  //For Edge, initFromPose has the same behavior than setPose
1616  //So, for convenience we call setPose
1617  vpMbEdgeMultiTracker::setPose(I1, I2, c1Mo, c2Mo, firstCameraIsReference);
1618 }
1619 
1626 void vpMbEdgeMultiTracker::initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1627  const vpHomogeneousMatrix &cMo_) {
1628  //For Edge, initFromPose has the same behavior than setPose
1629  //So, for convenience we call setPose
1630  vpMbEdgeMultiTracker::setPose(mapOfImages, cMo_);
1631 }
1632 
1639 void vpMbEdgeMultiTracker::initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1640  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) {
1641  //For Edge, initFromPose has the same behavior than setPose
1642  //So, for convenience we call setPose
1643  vpMbEdgeMultiTracker::setPose(mapOfImages, mapOfCameraPoses);
1644 }
1645 
1646 void vpMbEdgeMultiTracker::initPyramid(const std::map<std::string, const vpImage<unsigned char> * >& mapOfImages,
1647  std::map<std::string, std::vector<const vpImage<unsigned char>* > >& pyramid)
1648 {
1649  for(std::map<std::string, const vpImage<unsigned char> * >::const_iterator it = mapOfImages.begin();
1650  it != mapOfImages.end(); ++it) {
1651  pyramid[it->first].resize(scales.size());
1652 
1653  vpMbEdgeTracker::initPyramid(*it->second, pyramid[it->first]);
1654  }
1655 }
1656 
1707 void vpMbEdgeMultiTracker::loadConfigFile(const std::string &configFile) {
1708  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1709  if(it != m_mapOfEdgeTrackers.end()) {
1710  //Load ConfigFile for reference camera
1711  it->second->loadConfigFile(configFile);
1712  it->second->getCameraParameters(cam);
1713 
1714  //Set Moving Edge parameters
1715  this->me = it->second->getMovingEdge();
1716 
1717  //Set clipping
1718  this->clippingFlag = it->second->getClipping();
1719  this->angleAppears = it->second->getAngleAppear();
1720  this->angleDisappears = it->second->getAngleDisappear();
1721  } else {
1722  std::stringstream ss;
1723  ss << "The reference camera: " << m_referenceCameraName << " does not exist !";
1725  }
1726 }
1727 
1743 void vpMbEdgeMultiTracker::loadConfigFile(const std::string &configFile1, const std::string &configFile2,
1744  const bool firstCameraIsReference) {
1745  if(m_mapOfEdgeTrackers.size() == 2) {
1746  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
1747  it->second->loadConfigFile(configFile1);
1748 
1749  if(firstCameraIsReference) {
1750  it->second->getCameraParameters(cam);
1751 
1752  //Set Moving Edge parameters
1753  this->me = it->second->getMovingEdge();
1754 
1755  //Set clipping
1756  this->clippingFlag = it->second->getClipping();
1757  this->angleAppears = it->second->getAngleAppear();
1758  this->angleDisappears = it->second->getAngleDisappear();
1759  }
1760  ++it;
1761 
1762  it->second->loadConfigFile(configFile2);
1763 
1764  if(!firstCameraIsReference) {
1765  it->second->getCameraParameters(cam);
1766 
1767  //Set Moving Edge parameters
1768  this->me = it->second->getMovingEdge();
1769 
1770  //Set clipping
1771  this->clippingFlag = it->second->getClipping();
1772  this->angleAppears = it->second->getAngleAppear();
1773  this->angleDisappears = it->second->getAngleDisappear();
1774  }
1775  } else {
1776  std::stringstream ss;
1777  ss << "Cannot loadConfigFile. Require two cameras ! There are " << m_mapOfEdgeTrackers.size() << " cameras !";
1779  }
1780 }
1781 
1795 void vpMbEdgeMultiTracker::loadConfigFile(const std::map<std::string, std::string> &mapOfConfigFiles) {
1796  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it_edge = m_mapOfEdgeTrackers.begin();
1797  it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
1798  std::map<std::string, std::string>::const_iterator it_config = mapOfConfigFiles.find(it_edge->first);
1799  if(it_config != mapOfConfigFiles.end()) {
1800  it_edge->second->loadConfigFile(it_config->second);
1801  } else {
1802  std::stringstream ss;
1803  ss << "Missing configuration file for camera: " << it_edge->first << " !";
1805  }
1806  }
1807 
1808  //Set the reference camera parameters
1809  std::map<std::string, vpMbEdgeTracker *>::iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1810  if(it != m_mapOfEdgeTrackers.end()) {
1811  it->second->getCameraParameters(cam);
1812 
1813  //Set Moving Edge parameters
1814  this->me = it->second->getMovingEdge();
1815 
1816  //Set clipping
1817  this->clippingFlag = it->second->getClipping();
1818  this->angleAppears = it->second->getAngleAppear();
1819  this->angleDisappears = it->second->getAngleDisappear();
1820  } else {
1821  std::stringstream ss;
1822  ss << "The reference camera: " << m_referenceCameraName << " does not exist !";
1824  }
1825 }
1826 
1852 void vpMbEdgeMultiTracker::loadModel(const std::string &modelFile, const bool verbose) {
1853  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
1854  it != m_mapOfEdgeTrackers.end(); ++it) {
1855  it->second->loadModel(modelFile, verbose);
1856  }
1857 
1858  modelInitialised = true;
1859 }
1860 
1870 void vpMbEdgeMultiTracker::reInitModel(const vpImage<unsigned char>& I, const std::string &cad_name,
1871  const vpHomogeneousMatrix& cMo_, const bool verbose) {
1872  if(m_mapOfEdgeTrackers.size() != 1) {
1873  std::stringstream ss;
1874  ss << "This method requires exactly one camera, there are " << m_mapOfEdgeTrackers.size() << " cameras !";
1876  }
1877 
1878  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1879  if(it_edge != m_mapOfEdgeTrackers.end()) {
1880  it_edge->second->reInitModel(I, cad_name, cMo_, verbose);
1881 
1882  //Set reference pose
1883  it_edge->second->getPose(cMo);
1884 
1885  modelInitialised = true;
1886  }
1887 }
1888 
1902  const std::string &cad_name, const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
1903  const bool verbose, const bool firstCameraIsReference) {
1904  if(m_mapOfEdgeTrackers.size() == 2) {
1905  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.begin();
1906 
1907  it_edge->second->reInitModel(I1, cad_name, c1Mo, verbose);
1908 
1909  if(firstCameraIsReference) {
1910  //Set reference pose
1911  it_edge->second->getPose(cMo);
1912  }
1913 
1914  ++it_edge;
1915 
1916  it_edge->second->reInitModel(I2, cad_name, c2Mo, verbose);
1917 
1918  if(!firstCameraIsReference) {
1919  //Set reference pose
1920  it_edge->second->getPose(cMo);
1921  }
1922  } else {
1923  throw vpException(vpTrackingException::fatalError, "This method requires exactly two cameras !");
1924  }
1925 }
1926 
1936 void vpMbEdgeMultiTracker::reInitModel(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
1937  const std::string &cad_name, const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
1938  const bool verbose) {
1939  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
1940  std::map<std::string, const vpImage<unsigned char> *>::const_iterator it_img = mapOfImages.find(m_referenceCameraName);
1941  std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camPose = mapOfCameraPoses.find(m_referenceCameraName);
1942 
1943  if(it_edge != m_mapOfEdgeTrackers.end() && it_img != mapOfImages.end() && it_camPose != mapOfCameraPoses.end()) {
1944  it_edge->second->reInitModel(*it_img->second, cad_name, it_camPose->second, verbose);
1945  modelInitialised = true;
1946 
1947  //Set reference pose
1948  it_edge->second->getPose(cMo);
1949  } else {
1950  throw vpException(vpTrackingException::fatalError, "Cannot reInitModel for reference camera !");
1951  }
1952 
1953  std::vector<std::string> vectorOfMissingCameras;
1954  for(it_edge = m_mapOfEdgeTrackers.begin(); it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
1955  if(it_edge->first != m_referenceCameraName) {
1956  it_img = mapOfImages.find(it_edge->first);
1957  it_camPose = mapOfCameraPoses.find(it_edge->first);
1958 
1959  if(it_img != mapOfImages.end() && it_camPose != mapOfCameraPoses.end()) {
1960  it_edge->second->reInitModel(*it_img->second, cad_name, it_camPose->second, verbose);
1961  } else {
1962  vectorOfMissingCameras.push_back(it_edge->first);
1963  }
1964  }
1965  }
1966 
1967  for(std::vector<std::string>::const_iterator it = vectorOfMissingCameras.begin();
1968  it != vectorOfMissingCameras.end(); ++it) {
1969  it_img = mapOfImages.find(*it);
1970  std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camTrans = m_mapOfCameraTransformationMatrix.find(*it);
1971 
1972  if(it_img != mapOfImages.end() && it_camTrans != m_mapOfCameraTransformationMatrix.end()) {
1973  vpHomogeneousMatrix cCurrentMo = it_camTrans->second * cMo;
1974  m_mapOfEdgeTrackers[*it]->reInitModel(*it_img->second, cad_name, cCurrentMo, verbose);
1975  }
1976  }
1977 }
1978 
1984  this->cMo.eye();
1985 
1986  //Reset all internal trackers
1987  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
1988  it != m_mapOfEdgeTrackers.end(); ++it) {
1989  it->second->resetTracker();
1990  }
1991 
1992  useScanLine = false;
1993 
1994 #ifdef VISP_HAVE_OGRE
1995  useOgre = false;
1996 #endif
1997 
1998  compute_interaction = 1;
1999 // nline = 0; //Not used in vpMbEdgeMultiTracker class
2000 // ncylinder = 0; //Not used in vpMbEdgeMultiTracker class
2001  lambda = 1;
2002 // nbvisiblepolygone = 0; //Not used in vpMbEdgeMultiTracker class
2003  percentageGdPt = 0.4;
2004 
2005  angleAppears = vpMath::rad(89);
2008 
2010 
2011  // reinitialization of the scales.
2012  this->setScales(scales);
2013 }
2014 
2026 
2027  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2028  it != m_mapOfEdgeTrackers.end(); ++it) {
2029  it->second->setAngleAppear(a);
2030  }
2031 }
2032 
2044 
2045  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2046  it != m_mapOfEdgeTrackers.end(); ++it) {
2047  it->second->setAngleDisappear(a);
2048  }
2049 }
2050 
2057  if(m_mapOfEdgeTrackers.empty()) {
2058  throw vpException(vpTrackingException::fatalError, "There is no camera !");
2059  } else if(m_mapOfEdgeTrackers.size() > 1) {
2060  throw vpException(vpTrackingException::fatalError, "There is more than one camera !");
2061  } else {
2062  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
2063  if(it != m_mapOfEdgeTrackers.end()) {
2064  it->second->setCameraParameters(camera);
2065 
2066  //Set reference camera parameters
2067  this->cam = camera;
2068  } else {
2069  std::stringstream ss;
2070  ss << "The reference camera: " << m_referenceCameraName << " does not exist !";
2072  }
2073  }
2074 }
2075 
2084  const bool firstCameraIsReference) {
2085  if(m_mapOfEdgeTrackers.empty()) {
2086  throw vpException(vpTrackingException::fatalError, "There is no camera !");
2087  } else if(m_mapOfEdgeTrackers.size() == 2) {
2088  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2089  it->second->setCameraParameters(camera1);
2090 
2091  ++it;
2092  it->second->setCameraParameters(camera2);
2093 
2094  if(firstCameraIsReference) {
2095  this->cam = camera1;
2096  } else {
2097  this->cam = camera2;
2098  }
2099  } else {
2100  std::stringstream ss;
2101  ss << "Require two cameras ! There are " << m_mapOfEdgeTrackers.size() << " cameras !";
2103  }
2104 }
2105 
2112 void vpMbEdgeMultiTracker::setCameraParameters(const std::string &cameraName, const vpCameraParameters& camera) {
2113  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
2114  if(it != m_mapOfEdgeTrackers.end()) {
2115  it->second->setCameraParameters(camera);
2116 
2117  if(it->first == m_referenceCameraName) {
2118  this->cam = camera;
2119  }
2120  } else {
2121  std::stringstream ss;
2122  ss << "The camera: " << cameraName << " does not exist !";
2124  }
2125 }
2126 
2132 void vpMbEdgeMultiTracker::setCameraParameters(const std::map<std::string, vpCameraParameters> &mapOfCameraParameters) {
2133  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it_edge = m_mapOfEdgeTrackers.begin();
2134  it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
2135  std::map<std::string, vpCameraParameters>::const_iterator it_cam = mapOfCameraParameters.find(it_edge->first);
2136  if(it_cam != mapOfCameraParameters.end()) {
2137  it_edge->second->setCameraParameters(it_cam->second);
2138 
2139  if(it_edge->first == m_referenceCameraName) {
2140  this->cam = it_cam->second;
2141  }
2142  } else {
2143  std::stringstream ss;
2144  ss << "Missing camera parameters for camera: " << it_edge->first << " !";
2146  }
2147  }
2148 }
2149 
2156 void vpMbEdgeMultiTracker::setCameraTransformationMatrix(const std::string &cameraName,
2157  const vpHomogeneousMatrix &cameraTransformationMatrix) {
2158  std::map<std::string, vpHomogeneousMatrix>::iterator it = m_mapOfCameraTransformationMatrix.find(cameraName);
2159  if(it != m_mapOfCameraTransformationMatrix.end()) {
2160  it->second = cameraTransformationMatrix;
2161  } else {
2162  std::stringstream ss;
2163  ss << "Cannot find camera: " << cameraName << " !";
2165  }
2166 }
2167 
2175  const std::map<std::string, vpHomogeneousMatrix> &mapOfTransformationMatrix) {
2176  //Check if all cameras have a transformation matrix
2177  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it_edge = m_mapOfEdgeTrackers.begin();
2178  it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
2179  std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camTrans = mapOfTransformationMatrix.find(it_edge->first);
2180 
2181  if(it_camTrans == mapOfTransformationMatrix.end()) {
2182  throw vpException(vpTrackingException::initializationError, "Missing camera transformation matrix !");
2183  }
2184  }
2185 
2186  m_mapOfCameraTransformationMatrix = mapOfTransformationMatrix;
2187 }
2188 
2196 void vpMbEdgeMultiTracker::setClipping(const unsigned int &flags) {
2197  //Set clipping for vpMbEdgeMultiTracker class
2198  vpMbTracker::setClipping(flags);
2199 
2200  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2201  it != m_mapOfEdgeTrackers.end(); ++it) {
2202  it->second->setClipping(flags);
2203  }
2204 }
2205 
2214 void vpMbEdgeMultiTracker::setClipping(const std::string &cameraName, const unsigned int &flags) {
2215  //Set clipping for the given camera, do not change the clipping for vpMbEdgeMultiTracker class
2216  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
2217  if(it != m_mapOfEdgeTrackers.end()) {
2218  it->second->setClipping(flags);
2219  } else {
2220  std::cerr << "Camera: " << cameraName << " does not exist !" << std::endl;
2221  }
2222 }
2223 
2231 
2232  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2233  it != m_mapOfEdgeTrackers.end(); ++it) {
2234  it->second->setCovarianceComputation(flag);
2235  }
2236 }
2237 
2249 void vpMbEdgeMultiTracker::setDisplayFeatures(const bool displayF) {
2250  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
2251  it != m_mapOfEdgeTrackers.end(); ++it) {
2252  it->second->setDisplayFeatures(displayF);
2253  }
2254 
2255  displayFeatures = displayF;
2256 }
2257 
2265 
2266  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2267  it != m_mapOfEdgeTrackers.end(); ++it) {
2268  it->second->setFarClippingDistance(dist);
2269  }
2270 }
2271 
2278 void vpMbEdgeMultiTracker::setFarClippingDistance(const std::string &cameraName, const double &dist) {
2279  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
2280  if(it != m_mapOfEdgeTrackers.end()) {
2281  it->second->setFarClippingDistance(dist);
2282  } else {
2283  std::cerr << "Camera: " << cameraName << " does not exist !" << std::endl;
2284  }
2285 }
2286 
2300  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2301  it != m_mapOfEdgeTrackers.end(); ++it) {
2302  it->second->setGoodMovingEdgesRatioThreshold(threshold);
2303  }
2304 
2305  percentageGdPt = threshold;
2306 }
2307 
2308 #ifdef VISP_HAVE_OGRE
2309 
2317  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2318  it != m_mapOfEdgeTrackers.end(); ++it) {
2319  it->second->setGoodNbRayCastingAttemptsRatio(ratio);
2320  }
2321  }
2322 
2332  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2333  it != m_mapOfEdgeTrackers.end(); ++it) {
2334  it->second->setNbRayCastingAttemptsForVisibility(attempts);
2335  }
2336  }
2337 #endif
2338 
2348 void vpMbEdgeMultiTracker::setLod(const bool useLod, const std::string &name) {
2349  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2350  it != m_mapOfEdgeTrackers.end(); ++it) {
2351  it->second->setLod(useLod, name);
2352  }
2353 }
2354 
2365 void vpMbEdgeMultiTracker::setLod(const bool useLod, const std::string &cameraName, const std::string &name) {
2366  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(cameraName);
2367 
2368  if(it_edge != m_mapOfEdgeTrackers.end()) {
2369  it_edge->second->setLod(useLod, name);
2370  } else {
2371  std::cerr << "The camera: " << cameraName << " cannot be found !" << std::endl;
2372  }
2373 }
2374 
2383 void vpMbEdgeMultiTracker::setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name) {
2384  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2385  it != m_mapOfEdgeTrackers.end(); ++it) {
2386  it->second->setMinLineLengthThresh(minLineLengthThresh, name);
2387  }
2388 }
2389 
2399 void vpMbEdgeMultiTracker::setMinLineLengthThresh(const double minLineLengthThresh, const std::string &cameraName,
2400  const std::string &name) {
2401  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(cameraName);
2402 
2403  if(it_edge != m_mapOfEdgeTrackers.end()) {
2404  it_edge->second->setMinLineLengthThresh(minLineLengthThresh, name);
2405  } else {
2406  std::cerr << "The camera: " << cameraName << " cannot be found !" << std::endl;
2407  }
2408 }
2409 
2418 void vpMbEdgeMultiTracker::setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name) {
2419  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2420  it != m_mapOfEdgeTrackers.end(); ++it) {
2421  it->second->setMinPolygonAreaThresh(minPolygonAreaThresh, name);
2422  }
2423 }
2424 
2434 void vpMbEdgeMultiTracker::setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &cameraName,
2435  const std::string &name) {
2436  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(cameraName);
2437 
2438  if(it_edge != m_mapOfEdgeTrackers.end()) {
2439  it_edge->second->setMinPolygonAreaThresh(minPolygonAreaThresh, name);
2440  } else {
2441  std::cerr << "The camera: " << cameraName << " cannot be found !" << std::endl;
2442  }
2443 }
2444 
2451  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2452  it != m_mapOfEdgeTrackers.end(); ++it) {
2453  it->second->setMovingEdge(me);
2454  }
2455 }
2456 
2463 void vpMbEdgeMultiTracker::setMovingEdge(const std::string &cameraName, const vpMe &me) {
2464  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
2465  if(it != m_mapOfEdgeTrackers.end()) {
2466  it->second->setMovingEdge(me);
2467  } else {
2468  std::cerr << "Camera: " << cameraName << " does not exist !" << std::endl;
2469  }
2470 }
2471 
2479 
2480  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2481  it != m_mapOfEdgeTrackers.end(); ++it) {
2482  it->second->setNearClippingDistance(dist);
2483  }
2484 }
2485 
2492 void vpMbEdgeMultiTracker::setNearClippingDistance(const std::string &cameraName, const double &dist) {
2493  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(cameraName);
2494  if(it != m_mapOfEdgeTrackers.end()) {
2495  it->second->setNearClippingDistance(dist);
2496  } else {
2497  std::cerr << "Camera: " << cameraName << " does not exist !" << std::endl;
2498  }
2499 }
2500 
2511 void vpMbEdgeMultiTracker::setOgreShowConfigDialog(const bool showConfigDialog) {
2512  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2513  it != m_mapOfEdgeTrackers.end(); ++it) {
2514  it->second->setOgreShowConfigDialog(showConfigDialog);
2515  }
2516 }
2517 
2526  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2527  it != m_mapOfEdgeTrackers.end(); ++it) {
2528  it->second->setOgreVisibilityTest(v);
2529  }
2530 
2531 #ifdef VISP_HAVE_OGRE
2532  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2533  it != m_mapOfEdgeTrackers.end(); ++it) {
2534  it->second->faces.getOgreContext()->setWindowName("Multi MBT Edge (" + it->first + ")");
2535  }
2536 #endif
2537 
2538  useOgre = v;
2539 }
2540 
2547  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
2548  it != m_mapOfEdgeTrackers.end(); ++it) {
2549  it->second->setOptimizationMethod(opt);
2550  }
2551 
2552  m_optimizationMethod = opt;
2553 }
2554 
2563  if(m_mapOfEdgeTrackers.size() == 1) {
2564  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
2565  if(it != m_mapOfEdgeTrackers.end()) {
2566  it->second->setPose(I, cMo_);
2567  this->cMo = cMo_;
2568  } else {
2569  std::stringstream ss;
2570  ss << "Cannot find the reference camera: " << m_referenceCameraName << " !";
2572  }
2573  } else {
2574  std::stringstream ss;
2575  ss << "You are trying to set the pose with only one image and cMo but there are multiple cameras !";
2577  }
2578 }
2579 
2591  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix c2Mo, const bool firstCameraIsReference) {
2592  if(m_mapOfEdgeTrackers.size() == 2) {
2593  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2594  it->second->setPose(I1, c1Mo);
2595 
2596  ++it;
2597 
2598  it->second->setPose(I2, c2Mo);
2599 
2600  if(firstCameraIsReference) {
2601  this->cMo = c1Mo;
2602  } else {
2603  this->cMo = c2Mo;
2604  }
2605  } else {
2606  std::stringstream ss;
2607  ss << "This method requires 2 cameras but there are " << m_mapOfEdgeTrackers.size() << " cameras !";
2609  }
2610 }
2611 
2620 void vpMbEdgeMultiTracker::setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
2621  const vpHomogeneousMatrix &cMo_) {
2622  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
2623  if(it_edge != m_mapOfEdgeTrackers.end()) {
2624  std::map<std::string, const vpImage<unsigned char> *>::const_iterator it_img = mapOfImages.find(m_referenceCameraName);
2625 
2626  if(it_img != mapOfImages.end()) {
2627  //Set pose on reference camera
2628  it_edge->second->setPose(*it_img->second, cMo_);
2629 
2630  //Set the reference cMo
2631  cMo = cMo_;
2632 
2633  //Set the pose for the others cameras
2634  for(it_edge = m_mapOfEdgeTrackers.begin(); it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
2635  if(it_edge->first != m_referenceCameraName) {
2636  it_img = mapOfImages.find(it_edge->first);
2637  std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camTrans =
2638  m_mapOfCameraTransformationMatrix.find(it_edge->first);
2639 
2640  if(it_img != mapOfImages.end() && it_camTrans != m_mapOfCameraTransformationMatrix.end()) {
2641  vpHomogeneousMatrix cCurrentMo = it_camTrans->second * cMo;
2642  it_edge->second->setPose(*it_img->second, cCurrentMo);
2643  } else {
2644  throw vpException(vpTrackingException::fatalError, "Missing image or camera transformation matrix !");
2645  }
2646  }
2647  }
2648  } else {
2649  std::stringstream ss;
2650  ss << "Missing image for camera: " << m_referenceCameraName << " !";
2652  }
2653  } else {
2654  std::stringstream ss;
2655  ss << "The reference camera: " << m_referenceCameraName << " does not exist !";
2657  }
2658 }
2659 
2669 void vpMbEdgeMultiTracker::setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
2670  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) {
2671  //Set the reference cMo
2672  std::map<std::string, vpMbEdgeTracker *>::const_iterator it_edge = m_mapOfEdgeTrackers.find(m_referenceCameraName);
2673  std::map<std::string, const vpImage<unsigned char>* >::const_iterator it_img = mapOfImages.find(m_referenceCameraName);
2674  std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camPose = mapOfCameraPoses.find(m_referenceCameraName);
2675 
2676  if(it_edge != m_mapOfEdgeTrackers.end() && it_img != mapOfImages.end() && it_camPose != mapOfCameraPoses.end()) {
2677  it_edge->second->setPose(*it_img->second, it_camPose->second);
2678  it_edge->second->getPose(cMo);
2679  } else {
2680  throw vpException(vpTrackingException::fatalError, "Cannot set pose for the reference camera !");
2681  }
2682 
2683  //Vector of missing pose matrices for cameras
2684  std::vector<std::string> vectorOfMissingCameraPoses;
2685 
2686  //Set pose for the specified cameras
2687  for(it_edge = m_mapOfEdgeTrackers.begin(); it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
2688  if(it_edge->first != m_referenceCameraName) {
2689  it_img = mapOfImages.find(it_edge->first);
2690  it_camPose = mapOfCameraPoses.find(it_edge->first);
2691 
2692  if(it_img != mapOfImages.end() && it_camPose != mapOfCameraPoses.end()) {
2693  //Set pose
2694  it_edge->second->setPose(*it_img->second, it_camPose->second);
2695  } else {
2696  vectorOfMissingCameraPoses.push_back(it_edge->first);
2697  }
2698  }
2699  }
2700 
2701  for(std::vector<std::string>::const_iterator it1 = vectorOfMissingCameraPoses.begin();
2702  it1 != vectorOfMissingCameraPoses.end(); ++it1) {
2703  it_img = mapOfImages.find(*it1);
2704  std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camTrans = m_mapOfCameraTransformationMatrix.find(*it1);
2705 
2706  if(it_img != mapOfImages.end() && it_camTrans != m_mapOfCameraTransformationMatrix.end()) {
2707  vpHomogeneousMatrix cCurrentMo = it_camTrans->second * cMo;
2708  m_mapOfEdgeTrackers[*it1]->setPose(*it_img->second, cCurrentMo);
2709  } else {
2710  std::stringstream ss;
2711  ss << "Missing image or missing camera transformation matrix ! Cannot set the pose for camera: " << (*it1) << " !";
2713  }
2714  }
2715 }
2716 
2723  //Set the flag in the current class
2725 
2726  //Set the flag for each camera
2727  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2728  it != m_mapOfEdgeTrackers.end(); ++it) {
2729  it->second->setProjectionErrorComputation(flag);
2730  }
2731 }
2732 
2738 void vpMbEdgeMultiTracker::setReferenceCameraName(const std::string &referenceCameraName) {
2739  std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.find(referenceCameraName);
2740  if(it != m_mapOfEdgeTrackers.end()) {
2741  m_referenceCameraName = referenceCameraName;
2742  } else {
2743  std::stringstream ss;
2744  ss << "The reference camera: " << referenceCameraName << " does not exist !";
2746  }
2747 }
2748 
2769 void vpMbEdgeMultiTracker::setScales(const std::vector<bool>& scale) {
2771  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2772  it != m_mapOfEdgeTrackers.end(); ++it) {
2773  it->second->setScales(scale);
2774  }
2775 }
2776 
2783  //Set general setScanLineVisibilityTest
2785 
2786  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2787  it != m_mapOfEdgeTrackers.end(); ++it) {
2788  it->second->setScanLineVisibilityTest(v);
2789  }
2790 }
2791 
2798 void vpMbEdgeMultiTracker::setUseEdgeTracking(const std::string &name, const bool &useEdgeTracking) {
2799  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2800  it != m_mapOfEdgeTrackers.end(); ++it) {
2801  it->second->setUseEdgeTracking(name, useEdgeTracking);
2802  }
2803 }
2804 
2813  //Track only with reference camera
2814  //Get the reference camera parameters
2815  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.find(m_referenceCameraName);
2816 
2817  if(it != m_mapOfEdgeTrackers.end()) {
2818  it->second->track(I);
2819  it->second->getPose(cMo);
2820  } else {
2821  std::stringstream ss;
2822  ss << "The reference camera: " << m_referenceCameraName << " does not exist !";
2824  }
2825 
2826  if(computeProjError) {
2827  //Use the projection error computed by the single vpMbEdgeTracker in m_mapOfEdgeTrackers
2828  projectionError = it->second->getProjectionError();
2829  }
2830 }
2831 
2841  //Track with the special case of stereo cameras
2842  if(m_mapOfEdgeTrackers.size() == 2) {
2843  std::map<std::string, vpMbEdgeTracker *>::const_iterator it = m_mapOfEdgeTrackers.begin();
2844  std::map<std::string, const vpImage<unsigned char> *> mapOfImages;
2845  mapOfImages[it->first] = &I1;
2846  ++it;
2847 
2848  mapOfImages[it->first] = &I2;
2849  track(mapOfImages);
2850  } else {
2851  std::stringstream ss;
2852  ss << "Require two cameras ! There are " << m_mapOfEdgeTrackers.size() << " cameras !";
2854  }
2855 }
2856 
2864 void vpMbEdgeMultiTracker::track(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages) {
2865  //Check if there is an image for each camera
2866  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it_edge = m_mapOfEdgeTrackers.begin();
2867  it_edge != m_mapOfEdgeTrackers.end(); ++it_edge) {
2868  std::map<std::string, const vpImage<unsigned char>* >::const_iterator it_img = mapOfImages.find(it_edge->first);
2869 
2870  if(it_img == mapOfImages.end()) {
2871  throw vpException(vpTrackingException::fatalError, "Missing images !");
2872  }
2873  }
2874 
2875 
2876  initPyramid(mapOfImages, m_mapOfPyramidalImages);
2877 
2878  unsigned int lvl = (unsigned int) scales.size();
2879  do {
2880  lvl--;
2881 
2882  projectionError = 90.0;
2883 
2884  if(scales[lvl]) {
2885  vpHomogeneousMatrix cMo_1 = cMo;
2886  try
2887  {
2888  downScale(lvl);
2889  for(std::map<std::string, vpMbEdgeTracker *>::const_iterator it1 = m_mapOfEdgeTrackers.begin();
2890  it1 != m_mapOfEdgeTrackers.end(); ++it1) {
2891  //Downscale for each camera
2892  it1->second->downScale(lvl);
2893 
2894  //Track moving edges
2895  try {
2896  it1->second->trackMovingEdge(*m_mapOfPyramidalImages[it1->first][lvl]);
2897  } catch(...) {
2898  vpTRACE("Error in moving edge tracking") ;
2899  throw ;
2900  }
2901  }
2902 
2903  try {
2904  std::map<std::string, const vpImage<unsigned char> *> mapOfPyramidImages;
2905  for(std::map<std::string, std::vector<const vpImage<unsigned char>* > >::const_iterator
2906  it = m_mapOfPyramidalImages.begin(); it != m_mapOfPyramidalImages.end(); ++it) {
2907  mapOfPyramidImages[it->first] = it->second[lvl];
2908  }
2909 
2910  computeVVS(mapOfPyramidImages, lvl);
2911  } catch(...) {
2912  covarianceMatrix = -1;
2913  throw; // throw the original exception
2914  }
2915 
2916 
2917  //Test tracking failed only if all testTracking failed
2918  bool isOneTestTrackingOk = false;
2919  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
2920  it != m_mapOfEdgeTrackers.end(); ++it) {
2921  //Set the camera pose
2922  it->second->cMo = m_mapOfCameraTransformationMatrix[it->first]*cMo;
2923 
2924  try {
2925  it->second->testTracking();
2926  isOneTestTrackingOk = true;
2927  } catch(/*vpException &e*/...) {
2928  // throw e;
2929  }
2930  }
2931 
2932  if(!isOneTestTrackingOk) {
2933  std::ostringstream oss;
2934  oss << "Not enough moving edges to track the object. Try to reduce the threshold="
2935  << percentageGdPt << " using setGoodMovingEdgesRatioThreshold()";
2937  }
2938 
2939 
2940  if(displayFeatures) {
2941  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
2942  it != m_mapOfEdgeTrackers.end(); ++it) {
2943  it->second->displayFeaturesOnImage(*mapOfImages[it->first], lvl);
2944  }
2945  }
2946 
2947  // Looking for new visible face
2948  bool newvisibleface = false;
2949  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
2950  it != m_mapOfEdgeTrackers.end(); ++it) {
2951  it->second->visibleFace(*mapOfImages[it->first], it->second->cMo, newvisibleface);
2952  }
2953 
2954  if(useScanLine) {
2955  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
2956  it != m_mapOfEdgeTrackers.end(); ++it) {
2957  it->second->faces.computeClippedPolygons(it->second->cMo, it->second->cam);
2958  it->second->faces.computeScanLineRender(it->second->cam, mapOfImages[it->first]->getWidth(),
2959  mapOfImages[it->first]->getHeight());
2960  }
2961  }
2962 
2963  try {
2964  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
2965  it != m_mapOfEdgeTrackers.end(); ++it) {
2966  it->second->updateMovingEdge(*mapOfImages[it->first]);
2967  }
2968  } catch(...) {
2969  throw; // throw the original exception
2970  }
2971 
2972  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
2973  it != m_mapOfEdgeTrackers.end(); ++it) {
2974  it->second->initMovingEdge(*mapOfImages[it->first], it->second->cMo);
2975 
2976  // Reinit the moving edge for the lines which need it.
2977  it->second->reinitMovingEdge(*mapOfImages[it->first], it->second->cMo);
2978 
2979  if(computeProjError) {
2980  //Compute the projection error
2981  it->second->computeProjectionError(*mapOfImages[it->first]);
2982  }
2983  }
2984 
2986 
2987  upScale(lvl);
2988  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
2989  it != m_mapOfEdgeTrackers.end(); ++it) {
2990  it->second->upScale(lvl);
2991  }
2992  }
2993  catch(vpException &e)
2994  {
2995  if(lvl != 0){
2996  cMo = cMo_1;
2997  reInitLevel(lvl);
2998  upScale(lvl);
2999 
3000  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
3001  it != m_mapOfEdgeTrackers.end(); ++it) {
3002  it->second->cMo = cMo_1;
3003  it->second->reInitLevel(lvl);
3004  it->second->upScale(lvl);
3005  }
3006  }
3007  else{
3008  upScale(lvl);
3009  for(std::map<std::string, vpMbEdgeTracker*>::const_iterator it = m_mapOfEdgeTrackers.begin();
3010  it != m_mapOfEdgeTrackers.end(); ++it) {
3011  it->second->upScale(lvl);
3012  }
3013  throw(e) ;
3014  }
3015  }
3016  }
3017  } while(lvl != 0);
3018 
3020 }
bool computeProjError
Flag used to specify if the gradient error criteria has to be computed or not.
Definition: vpMbTracker.h:131
std::string m_referenceCameraName
Name of the reference camera.
virtual void setCovarianceComputation(const bool &flag)
Definition: vpMbTracker.h:398
void computeVVSFirstPhasePoseEstimation(const unsigned int nerror, const unsigned int iter, const vpColVector &factor, vpColVector &weighted_error, vpMatrix &L, bool &isoJoIdentity_)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
virtual void setUseEdgeTracking(const std::string &name, const bool &useEdgeTracking)
vpMatrix covarianceMatrix
Covariance matrix.
Definition: vpMbTracker.h:129
virtual void loadModel(const std::string &modelFile, const bool verbose=false)
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
virtual void setFarClippingDistance(const double &dist)
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="")
void upScale(const unsigned int _scale)
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:208
void stack(const double &d)
virtual void setAngleDisappear(const double &a)
Definition: vpMbTracker.h:382
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
Definition: vpMbTracker.h:144
virtual void computeProjectionError()
void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
virtual void setDisplayFeatures(const bool displayF)
Implementation of an homogeneous matrix and operations on such kind of matrices.
double lambda
The gain of the virtual visual servoing stage.
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 track(const vpImage< unsigned char > &I)
vpHomogeneousMatrix cMo
The current pose.
Definition: vpMbTracker.h:115
void stack(const vpMatrix &A)
Definition: vpMatrix.cpp:2981
virtual void setProjectionErrorComputation(const bool &flag)
virtual void loadConfigFile(const std::string &configFile)
bool modelInitialised
Flag used to ensure that the CAD model is loaded before the initialisation.
Definition: vpMbTracker.h:123
virtual void cleanPyramid(std::map< std::string, std::vector< const vpImage< unsigned char > * > > &pyramid)
error that can be emited by ViSP classes.
Definition: vpException.h:73
void reInitLevel(const unsigned int _lvl)
virtual vpMe getMovingEdge() const
virtual void setClipping(const unsigned int &flags)
Definition: vpMe.h:59
virtual void setOgreShowConfigDialog(const bool showConfigDialog)
bool useOgre
Use Ogre3d for visibility tests.
Definition: vpMbTracker.h:156
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
Definition: vpMbTracker.h:127
vpMe me
The moving edges parameters.
virtual unsigned int getNbPolygon() const
virtual void setReferenceCameraName(const std::string &referenceCameraName)
virtual void setNearClippingDistance(const double &dist)
void downScale(const unsigned int _scale)
void computeVVSSecondPhasePoseEstimation(const unsigned int nerror, vpMatrix &L, vpMatrix &L_true, vpMatrix &LVJ_true, vpColVector &W_true, const vpColVector &factor, const unsigned int iter, const bool isoJoIdentity_, vpColVector &weighted_error, double &mu, vpColVector &m_error_prev, vpColVector &m_w_prev, vpHomogeneousMatrix &cMoPrev, double &residu_1, double &r)
vpCameraParameters cam
The camera parameters.
Definition: vpMbTracker.h:113
double projectionError
Error angle between the gradient direction of the model features projected at the resulting pose and ...
Definition: vpMbTracker.h:133
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)
void setGoodNbRayCastingAttemptsRatio(const double &ratio)
std::vector< bool > scales
Vector of scale level to use for the multi-scale tracking.
virtual void initClick(const vpImage< unsigned char > &I, const std::vector< vpPoint > &points3D_list, const std::string &displayFile="")
std::map< std::string, vpHomogeneousMatrix > m_mapOfCameraTransformationMatrix
Map of camera transformation matrix between the current camera frame to the reference camera frame (c...
Error that can be emited by the vpTracker class and its derivates.
void init(const vpImage< unsigned char > &I)
vp_deprecated void init()
virtual vpHomogeneousMatrix getPose() const
Definition: vpMbTracker.h:342
virtual void setOgreVisibilityTest(const bool &v)
void diag(const double &val=1.0)
Definition: vpMatrix.cpp:524
bool useScanLine
Use Scanline for visibility tests.
Definition: vpMbTracker.h:159
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
virtual void computeVVS(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, const unsigned int lvl)
#define vpTRACE
Definition: vpDebug.h:414
static double sqr(double x)
Definition: vpMath.h:110
void computeVVSSecondPhaseCheckLevenbergMarquardt(const unsigned int iter, const unsigned int nbrow, const vpColVector &m_error_prev, const vpColVector &m_w_prev, const vpHomogeneousMatrix &cMoPrev, double &mu, bool &reStartFromLastIncrement)
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
unsigned int nbFeaturesForProjErrorComputation
Number of features used in the computation of the projection error.
void getLcircle(std::list< vpMbtDistanceCircle * > &circlesList, const unsigned int level=0) const
Generic class defining intrinsic camera parameters.
virtual void setCameraTransformationMatrix(const std::string &cameraName, const vpHomogeneousMatrix &cameraTransformationMatrix)
double percentageGdPt
Percentage of good points over total number of points below which tracking is supposed to have failed...
void initPyramid(const vpImage< unsigned char > &_I, std::vector< const vpImage< unsigned char > * > &_pyramid)
void getLline(std::list< vpMbtDistanceLine * > &linesList, const unsigned int level=0) const
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
virtual void setAngleAppear(const double &a)
Definition: vpMbTracker.h:371
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
double angleAppears
Angle used to detect a face appearance.
Definition: vpMbTracker.h:146
virtual void setCovarianceComputation(const bool &flag)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
double get_px() const
static double rad(double deg)
Definition: vpMath.h:104
virtual void setMovingEdge(const vpMe &me)
virtual void setScales(const std::vector< bool > &scales)
void setScales(const std::vector< bool > &_scales)
std::map< std::string, std::vector< const vpImage< unsigned char > * > > m_mapOfPyramidalImages
Map of pyramidal images for each camera.
static double deg(double rad)
Definition: vpMath.h:97
bool displayFeatures
If true, the features are displayed.
Definition: vpMbTracker.h:135
virtual void getCameraParameters(vpCameraParameters &camera) const
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:93
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
Contains an M-Estimator and various influence function.
Definition: vpRobust.h:60
double angleDisappears
Angle used to detect a face disappearance.
Definition: vpMbTracker.h:148
void getLcylinder(std::list< vpMbtDistanceCylinder * > &cylindersList, const unsigned int level=0) const
virtual std::vector< std::string > getCameraNames() const
virtual unsigned int getNbPoints(const unsigned int level=0) const
virtual void setScanLineVisibilityTest(const bool &v)
Definition: vpMbTracker.h:439
virtual void setClipping(const unsigned int &flags)
virtual void setAngleDisappear(const double &a)
virtual void setGoodMovingEdgesRatioThreshold(const double threshold)
unsigned int clippingFlag
Flags specifying which clipping to used.
Definition: vpMbTracker.h:154
virtual void setFarClippingDistance(const double &dist)
std::map< std::string, vpMbEdgeTracker * > m_mapOfEdgeTrackers
Map of Model-based edge trackers.
virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt)
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
bool isoJoIdentity
Boolean to know if oJo is identity (for fast computation)
Definition: vpMbTracker.h:119
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 initPyramid(const std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, std::map< std::string, std::vector< const vpImage< unsigned char > * > > &pyramid)
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
virtual void setNearClippingDistance(const double &dist)