Visual Servoing Platform  version 3.4.0
mbtGenericTracking.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
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  * Description:
32  * Example of Hybrid Tracking of MBT and MBT KTL.
33  *
34  * Authors:
35  * Aurelien Yol
36  * Souriya Trinh
37  *
38  *****************************************************************************/
39 
47 #include <iostream>
48 #include <visp3/core/vpConfig.h>
49 
50 #if (defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY)) \
51  && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
52 
53 #include <visp3/core/vpDebug.h>
54 #include <visp3/core/vpHomogeneousMatrix.h>
55 #include <visp3/core/vpIoTools.h>
56 #include <visp3/core/vpMath.h>
57 #include <visp3/gui/vpDisplayD3D.h>
58 #include <visp3/gui/vpDisplayGDI.h>
59 #include <visp3/gui/vpDisplayGTK.h>
60 #include <visp3/gui/vpDisplayOpenCV.h>
61 #include <visp3/gui/vpDisplayX.h>
62 #include <visp3/io/vpImageIo.h>
63 #include <visp3/io/vpParseArgv.h>
64 #include <visp3/io/vpVideoReader.h>
65 #include <visp3/mbt/vpMbGenericTracker.h>
66 
67 #define GETOPTARGS "x:m:i:n:de:chtfColwvpT:"
68 
69 #define USE_XML 0
70 
71 void usage(const char *name, const char *badparam)
72 {
73  fprintf(stdout, "\n\
74 Example of tracking based on the 3D model.\n\
75 \n\
76 SYNOPSIS\n\
77  %s [-i <test image path>] [-x <config file>]\n\
78  [-m <model name>] [-n <initialisation file base name>] [-e <last frame index>]\n\
79  [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]\n\
80  [-T <tracker type>]\n", name);
81 
82  fprintf(stdout, "\n\
83 OPTIONS: \n\
84  -i <input image path> \n\
85  Set image input path.\n\
86  From this path read images \n\
87  \"mbt/cube/image%%04d.ppm\". These \n\
88  images come from ViSP-images-x.y.z.tar.gz available \n\
89  on the ViSP website.\n\
90  Setting the VISP_INPUT_IMAGE_PATH environment\n\
91  variable produces the same behavior than using\n\
92  this option.\n\
93 \n\
94  -x <config file> \n\
95  Set the config file (the xml file) to use.\n\
96  The config file is used to specify the parameters of the tracker.\n\
97 \n\
98  -m <model name> \n\
99  Specify the name of the file of the model\n\
100  The model can either be a vrml model (.wrl) or a .cao file.\n\
101 \n\
102  -e <last frame index> \n\
103  Specify the index of the last frame. Once reached, the tracking is stopped\n\
104 \n\
105  -f \n\
106  Do not use the vrml model, use the .cao one. These two models are \n\
107  equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
108  website. However, the .cao model allows to use the 3d model based tracker \n\
109  without Coin.\n\
110 \n\
111  -C \n\
112  Track only the cube (not the cylinder). In this case the models files are\n\
113  cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
114  cube_and_cylinder.wrl.\n\
115 \n\
116  -n <initialisation file base name> \n\
117  Base name of the initialisation file. The file will be 'base_name'.init .\n\
118  This base name is also used for the optional picture specifying where to \n\
119  click (a .ppm picture).\n\
120 \n\
121  -t \n\
122  Turn off the display of the the moving edges and Klt points. \n\
123 \n\
124  -d \n\
125  Turn off the display.\n\
126 \n\
127  -c\n\
128  Disable the mouse click. Useful to automate the \n\
129  execution of this program without human intervention.\n\
130 \n\
131  -o\n\
132  Use Ogre3D for visibility tests\n\
133 \n\
134  -w\n\
135  When Ogre3D is enable [-o] show Ogre3D configuration dialog that allows to set the renderer.\n\
136 \n\
137  -l\n\
138  Use the scanline for visibility tests.\n\
139 \n\
140  -v\n\
141  Compute covariance matrix.\n\
142 \n\
143  -p\n\
144  Compute gradient projection error.\n\
145 \n\
146  -T <tracker type>\n\
147  Set tracker type (<1 (Edge)>, <2 (KLT)>, <3 (EdgeKlt)>).\n\
148 \n\
149  -h \n\
150  Print the help.\n\n");
151 
152  if (badparam)
153  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
154 }
155 
156 bool getOptions(int argc, const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
157  std::string &initFile, long &lastFrame, bool &displayFeatures, bool &click_allowed, bool &display,
158  bool &cao3DModel, bool &trackCylinder, bool &useOgre, bool &showOgreConfigDialog, bool &useScanline,
159  bool &computeCovariance, bool &projectionError, int &trackerType)
160 {
161  const char *optarg_;
162  int c;
163  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
164 
165  switch (c) {
166  case 'e':
167  lastFrame = atol(optarg_);
168  break;
169  case 'i':
170  ipath = optarg_;
171  break;
172  case 'x':
173  configFile = optarg_;
174  break;
175  case 'm':
176  modelFile = optarg_;
177  break;
178  case 'n':
179  initFile = optarg_;
180  break;
181  case 't':
182  displayFeatures = false;
183  break;
184  case 'f':
185  cao3DModel = true;
186  break;
187  case 'c':
188  click_allowed = false;
189  break;
190  case 'd':
191  display = false;
192  break;
193  case 'C':
194  trackCylinder = false;
195  break;
196  case 'o':
197  useOgre = true;
198  break;
199  case 'l':
200  useScanline = true;
201  break;
202  case 'w':
203  showOgreConfigDialog = true;
204  break;
205  case 'v':
206  computeCovariance = true;
207  break;
208  case 'p':
209  projectionError = true;
210  break;
211  case 'T':
212  trackerType = atoi(optarg_);
213  break;
214  case 'h':
215  usage(argv[0], NULL);
216  return false;
217  break;
218 
219  default:
220  usage(argv[0], optarg_);
221  return false;
222  break;
223  }
224  }
225 
226  if ((c == 1) || (c == -1)) {
227  // standalone param or error
228  usage(argv[0], NULL);
229  std::cerr << "ERROR: " << std::endl;
230  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
231  return false;
232  }
233 
234  return true;
235 }
236 
237 int main(int argc, const char **argv)
238 {
239  try {
240  std::string env_ipath;
241  std::string opt_ipath;
242  std::string ipath;
243  std::string opt_configFile;
244  std::string opt_modelFile;
245  std::string modelFile;
246  std::string opt_initFile;
247  std::string initFile;
248  long opt_lastFrame = -1;
249  bool displayFeatures = true;
250  bool opt_click_allowed = true;
251  bool opt_display = true;
252  bool cao3DModel = false;
253  bool trackCylinder = true;
254  bool useOgre = false;
255  bool showOgreConfigDialog = false;
256  bool useScanline = false;
257  bool computeCovariance = false;
258  bool projectionError = false;
259  int trackerType = vpMbGenericTracker::EDGE_TRACKER;
260 
261  // Get the visp-images-data package path or VISP_INPUT_IMAGE_PATH
262  // environment variable value
263  env_ipath = vpIoTools::getViSPImagesDataPath();
264 
265  // Set the default input path
266  if (!env_ipath.empty())
267  ipath = env_ipath;
268 
269  // Read the command line options
270  if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayFeatures,
271  opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
272  useScanline, computeCovariance, projectionError, trackerType)) {
273  return EXIT_FAILURE;
274  }
275 
276  // Test if an input path is set
277  if (opt_ipath.empty() && env_ipath.empty()) {
278  usage(argv[0], NULL);
279  std::cerr << std::endl << "ERROR:" << std::endl;
280  std::cerr << " Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
281  << " environment variable to specify the location of the " << std::endl
282  << " image path where test images are located." << std::endl
283  << std::endl;
284 
285  return EXIT_FAILURE;
286  }
287 
288  // Get the option values
289  if (!opt_ipath.empty())
290  ipath = vpIoTools::createFilePath(opt_ipath, "mbt/cube/image%04d.pgm");
291  else
292  ipath = vpIoTools::createFilePath(env_ipath, "mbt/cube/image%04d.pgm");
293 
294 #if USE_XML
295  std::string configFile;
296  if (!opt_configFile.empty())
297  configFile = opt_configFile;
298  else if (!opt_ipath.empty())
299  configFile = vpIoTools::createFilePath(opt_ipath, "mbt/cube.xml");
300  else
301  configFile = vpIoTools::createFilePath(env_ipath, "mbt/cube.xml");
302 #endif
303 
304  if (!opt_modelFile.empty()) {
305  modelFile = opt_modelFile;
306  } else {
307  std::string modelFileCao;
308  std::string modelFileWrl;
309  if (trackCylinder) {
310  modelFileCao = "mbt/cube_and_cylinder.cao";
311  modelFileWrl = "mbt/cube_and_cylinder.wrl";
312  } else {
313  modelFileCao = "mbt/cube.cao";
314  modelFileWrl = "mbt/cube.wrl";
315  }
316 
317  if (!opt_ipath.empty()) {
318  if (cao3DModel) {
319  modelFile = vpIoTools::createFilePath(opt_ipath, modelFileCao);
320  } else {
321 #ifdef VISP_HAVE_COIN3D
322  modelFile = vpIoTools::createFilePath(opt_ipath, modelFileWrl);
323 #else
324  std::cerr << "Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
325  modelFile = vpIoTools::createFilePath(opt_ipath, modelFileCao);
326 #endif
327  }
328  } else {
329  if (cao3DModel) {
330  modelFile = vpIoTools::createFilePath(env_ipath, modelFileCao);
331  } else {
332 #ifdef VISP_HAVE_COIN3D
333  modelFile = vpIoTools::createFilePath(env_ipath, modelFileWrl);
334 #else
335  std::cerr << "Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
336  modelFile = vpIoTools::createFilePath(env_ipath, modelFileCao);
337 #endif
338  }
339  }
340  }
341 
342  if (!opt_initFile.empty())
343  initFile = opt_initFile;
344  else if (!opt_ipath.empty())
345  initFile = vpIoTools::createFilePath(opt_ipath, "mbt/cube");
346  else
347  initFile = vpIoTools::createFilePath(env_ipath, "mbt/cube");
348 
349  vpImage<unsigned char> I1, I2;
350  vpVideoReader reader;
351 
352  reader.setFileName(ipath);
353  try {
354  reader.open(I1);
355  I2 = I1;
356  } catch (...) {
357  std::cerr << "Cannot open sequence: " << ipath << std::endl;
358  return EXIT_FAILURE;
359  }
360 
361  if (opt_lastFrame > 1 && opt_lastFrame < reader.getLastFrameIndex())
362  reader.setLastFrameIndex(opt_lastFrame);
363 
364  reader.acquire(I1);
365  I2 = I1;
366 
367 // initialise a display
368 #if defined VISP_HAVE_X11
369  vpDisplayX display1, display2;
370 #elif defined VISP_HAVE_GDI
371  vpDisplayGDI display1, display2;
372 #elif defined VISP_HAVE_OPENCV
373  vpDisplayOpenCV display1, display2;
374 #elif defined VISP_HAVE_D3D9
375  vpDisplayD3D display1, display2;
376 #elif defined VISP_HAVE_GTK
377  vpDisplayGTK display1, display2;
378 #else
379  opt_display = false;
380 #endif
381  if (opt_display) {
382 #if defined(VISP_HAVE_DISPLAY)
385  display1.init(I1, 100, 100, "Test tracking (Left)");
386  display2.init(I2, (int)(I1.getWidth() / vpDisplay::getDownScalingFactor(I1)) + 110, 100, "Test tracking (Right)");
387 #endif
388  vpDisplay::display(I1);
389  vpDisplay::display(I2);
390  vpDisplay::flush(I1);
391  vpDisplay::flush(I2);
392  }
393 
394  // Object pointer to check that inheritance is ok
395  vpMbTracker *tracker = new vpMbGenericTracker(2, trackerType);
396  vpHomogeneousMatrix c1Mo, c2Mo;
397  vpCameraParameters cam1, cam2;
398 
399 // Initialise the tracker: camera parameters, moving edge and KLT settings
400 #if USE_XML
401  // From the xml file
402  dynamic_cast<vpMbGenericTracker *>(tracker)->loadConfigFile(configFile, configFile);
403 #else
404  // By setting the parameters:
405  cam1.initPersProjWithoutDistortion(547, 542, 338, 234);
406  cam2.initPersProjWithoutDistortion(547, 542, 338, 234);
407 
408  vpMe me;
409  me.setMaskSize(5);
410  me.setMaskNumber(180);
411  me.setRange(7);
412  me.setThreshold(5000);
413  me.setMu1(0.5);
414  me.setMu2(0.5);
415  me.setSampleStep(4);
416 
417 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
418  vpKltOpencv klt;
419  klt.setMaxFeatures(10000);
420  klt.setWindowSize(5);
421  klt.setQuality(0.01);
422  klt.setMinDistance(5);
423  klt.setHarrisFreeParameter(0.01);
424  klt.setBlockSize(3);
425  klt.setPyramidLevels(3);
426 
427  dynamic_cast<vpMbGenericTracker *>(tracker)->setKltOpencv(klt);
428  dynamic_cast<vpMbGenericTracker *>(tracker)->setKltMaskBorder(5);
429 #endif
430 
431  dynamic_cast<vpMbGenericTracker *>(tracker)->setCameraParameters(cam1, cam2);
432  dynamic_cast<vpMbGenericTracker *>(tracker)->setMovingEdge(me);
433 
434  tracker->setAngleAppear(vpMath::rad(65));
435  tracker->setAngleDisappear(vpMath::rad(75));
436 
437  // Specify the clipping to
438  tracker->setNearClippingDistance(0.01);
439  tracker->setFarClippingDistance(0.90);
440  tracker->setClipping(tracker->getClipping() | vpMbtPolygon::FOV_CLIPPING);
441 // tracker->setClipping(tracker->getClipping() | vpMbtPolygon::LEFT_CLIPPING
442 // | vpMbtPolygon::RIGHT_CLIPPING | vpMbtPolygon::UP_CLIPPING |
443 // vpMbtPolygon::DOWN_CLIPPING); // Equivalent to FOV_CLIPPING
444 #endif
445 
446  // Display the moving edges, and the Klt points
447  tracker->setDisplayFeatures(displayFeatures);
448 
449  // Tells if the tracker has to use Ogre3D for visibility tests
450  tracker->setOgreVisibilityTest(useOgre);
451  if (useOgre)
452  tracker->setOgreShowConfigDialog(showOgreConfigDialog);
453 
454  // Tells if the tracker has to use the scanline visibility tests
455  tracker->setScanLineVisibilityTest(useScanline);
456 
457  // Tells if the tracker has to compute the covariance matrix
458  tracker->setCovarianceComputation(computeCovariance);
459 
460  // Tells if the tracker has to compute the projection error
461  tracker->setProjectionErrorComputation(projectionError);
462 
463  // Retrieve the camera parameters from the tracker
464  dynamic_cast<vpMbGenericTracker *>(tracker)->getCameraParameters(cam1, cam2);
465 
466  // Loop to position the cube
467  if (opt_display && opt_click_allowed) {
468  while (!vpDisplay::getClick(I1, false)) {
469  vpDisplay::display(I1);
470  vpDisplay::displayText(I1, 15, 10, "click after positioning the object", vpColor::red);
471  vpDisplay::flush(I1);
472  }
473  }
474 
475  // Load the 3D model (either a vrml file or a .cao file)
476  tracker->loadModel(modelFile);
477 
478  // Initialise the tracker by clicking on the image
479  // This function looks for
480  // - a ./cube/cube.init file that defines the 3d coordinates (in meter,
481  // in the object basis) of the points used for the initialisation
482  // - a ./cube/cube.ppm file to display where the user have to click
483  // (optionnal, set by the third parameter)
484  if (opt_display && opt_click_allowed) {
485  dynamic_cast<vpMbGenericTracker *>(tracker)->initClick(I1, I2, initFile, initFile, true);
486  dynamic_cast<vpMbGenericTracker *>(tracker)->getPose(c1Mo, c2Mo);
487  // display the 3D model at the given pose
488  dynamic_cast<vpMbGenericTracker *>(tracker)->display(I1, I2, c1Mo, c2Mo, cam1, cam2, vpColor::red);
489  } else {
490  vpHomogeneousMatrix c1Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
491  vpHomogeneousMatrix c2Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
492  dynamic_cast<vpMbGenericTracker *>(tracker)->initFromPose(I1, I2, c1Moi, c2Moi);
493  }
494 
495  // track the model
496  dynamic_cast<vpMbGenericTracker *>(tracker)->track(I1, I2);
497  dynamic_cast<vpMbGenericTracker *>(tracker)->getPose(c1Mo, c2Mo);
498 
499  if (opt_display) {
500  vpDisplay::flush(I1);
501  vpDisplay::flush(I2);
502  }
503 
504  bool quit = false, click = false;
505  while (!reader.end() && !quit) {
506  // acquire a new image
507  reader.acquire(I1);
508  I2 = I1;
509  // display the image
510  if (opt_display) {
511  vpDisplay::display(I1);
512  vpDisplay::display(I2);
513 
514  std::stringstream ss;
515  ss << "Num frame: " << reader.getFrameIndex() << "/" << reader.getLastFrameIndex();
516  vpDisplay::displayText(I1, 40, 20, ss.str(), vpColor::red);
517  }
518 
519  // Test to reset the tracker
520  if (reader.getFrameIndex() == reader.getFirstFrameIndex() + 10) {
521  std::cout << "----------Test reset tracker----------" << std::endl;
522  if (opt_display) {
523  vpDisplay::display(I1);
524  vpDisplay::display(I2);
525  }
526 
527  tracker->resetTracker();
528 #if USE_XML
529  dynamic_cast<vpMbGenericTracker *>(tracker)->loadConfigFile(configFile, configFile);
530 #else
531  // By setting the parameters:
532  cam1.initPersProjWithoutDistortion(547, 542, 338, 234);
533  cam2.initPersProjWithoutDistortion(547, 542, 338, 234);
534 
535  me.setMaskSize(5);
536  me.setMaskNumber(180);
537  me.setRange(7);
538  me.setThreshold(5000);
539  me.setMu1(0.5);
540  me.setMu2(0.5);
541  me.setSampleStep(4);
542 
543 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
544  klt.setMaxFeatures(10000);
545  klt.setWindowSize(5);
546  klt.setQuality(0.01);
547  klt.setMinDistance(5);
548  klt.setHarrisFreeParameter(0.01);
549  klt.setBlockSize(3);
550  klt.setPyramidLevels(3);
551 
552  dynamic_cast<vpMbGenericTracker *>(tracker)->setKltOpencv(klt);
553  dynamic_cast<vpMbGenericTracker *>(tracker)->setKltMaskBorder(5);
554 #endif
555 
556  dynamic_cast<vpMbGenericTracker *>(tracker)->setCameraParameters(cam1, cam2);
557  dynamic_cast<vpMbGenericTracker *>(tracker)->setMovingEdge(me);
558  tracker->setAngleAppear(vpMath::rad(65));
559  tracker->setAngleDisappear(vpMath::rad(75));
560 
561  // Specify the clipping to
562  tracker->setNearClippingDistance(0.01);
563  tracker->setFarClippingDistance(0.90);
564  tracker->setClipping(tracker->getClipping() | vpMbtPolygon::FOV_CLIPPING);
565 // tracker->setClipping(tracker->getClipping() | vpMbtPolygon::LEFT_CLIPPING
566 // | vpMbtPolygon::RIGHT_CLIPPING | vpMbtPolygon::UP_CLIPPING |
567 // vpMbtPolygon::DOWN_CLIPPING); // Equivalent to FOV_CLIPPING
568 #endif
569  tracker->loadModel(modelFile);
570  dynamic_cast<vpMbGenericTracker *>(tracker)->setCameraParameters(cam1, cam2);
571  tracker->setOgreVisibilityTest(useOgre);
572  tracker->setScanLineVisibilityTest(useScanline);
573  tracker->setCovarianceComputation(computeCovariance);
574  tracker->setProjectionErrorComputation(projectionError);
575  dynamic_cast<vpMbGenericTracker *>(tracker)->initFromPose(I1, I2, c1Mo, c2Mo);
576  }
577 
578  // Test to set an initial pose
579  if (reader.getFrameIndex() == reader.getFirstFrameIndex() + 50) {
580  c1Mo.buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
581  c2Mo.buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
582  std::cout << "Test set pose" << std::endl;
583  dynamic_cast<vpMbGenericTracker *>(tracker)->setPose(I1, I2, c1Mo, c2Mo);
584  }
585 
586  // track the object: stop tracking from frame 40 to 50
587  if (reader.getFrameIndex() - reader.getFirstFrameIndex() < 40 ||
588  reader.getFrameIndex() - reader.getFirstFrameIndex() >= 50) {
589  dynamic_cast<vpMbGenericTracker *>(tracker)->track(I1, I2);
590  dynamic_cast<vpMbGenericTracker *>(tracker)->getPose(c1Mo, c2Mo);
591  if (opt_display) {
592  // display the 3D model
593  dynamic_cast<vpMbGenericTracker *>(tracker)->display(I1, I2, c1Mo, c2Mo, cam1, cam2, vpColor::darkRed);
594  // display the frame
595  vpDisplay::displayFrame(I1, c1Mo, cam1, 0.05);
596  vpDisplay::displayFrame(I2, c2Mo, cam2, 0.05);
597  }
598  }
599 
600  if (opt_click_allowed && opt_display) {
601  vpDisplay::displayText(I1, 10, 10, "Click to quit", vpColor::red);
603  if (vpDisplay::getClick(I1, button, click)) {
604  switch (button) {
606  quit = !click;
607  break;
608 
610  click = !click;
611  break;
612 
613  default:
614  break;
615  }
616  }
617  }
618 
619  if (computeCovariance) {
620  std::cout << "Covariance matrix: \n" << tracker->getCovarianceMatrix() << std::endl << std::endl;
621  }
622 
623  if (projectionError) {
624  std::cout << "Projection error: " << tracker->getProjectionError() << std::endl << std::endl;
625  }
626 
627  if (opt_display) {
628  vpDisplay::flush(I1);
629  vpDisplay::flush(I2);
630  }
631  }
632 
633  std::cout << "Reached last frame: " << reader.getFrameIndex() << std::endl;
634  std::cout << "\nFinal poses, c1Mo:\n" << c1Mo << "\nc2Mo:\n" << c2Mo << std::endl;
635 
636  if (opt_click_allowed && !quit) {
638  }
639  reader.close();
640 
641  delete tracker;
642  tracker = NULL;
643 
644  return EXIT_SUCCESS;
645  } catch (const vpException &e) {
646  std::cout << "Catch an exception: " << e << std::endl;
647  return EXIT_FAILURE;
648  }
649 }
650 
651 #elif !(defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY))
652 int main()
653 {
654  std::cout << "Cannot run this example: visp_mbt, visp_gui modules are required."
655  << std::endl;
656  return EXIT_SUCCESS;
657 }
658 #else
659 int main()
660 {
661  std::cout << "Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
662  return EXIT_SUCCESS;
663 }
664 #endif
virtual void setCovarianceComputation(const bool &flag)
Definition: vpMbTracker.h:499
void setMaxFeatures(int maxCount)
long getFrameIndex() const
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1202
void setHarrisFreeParameter(double harris_k)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
unsigned int getWidth() const
Definition: vpImage.h:246
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:256
virtual void setAngleDisappear(const double &a)
Definition: vpMbTracker.h:480
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setMaskNumber(const unsigned int &a)
Definition: vpMe.cpp:452
virtual void setDownScalingFactor(unsigned int scale)
Definition: vpDisplay.cpp:231
static const vpColor darkRed
Definition: vpColor.h:218
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
void setSampleStep(const double &s)
Definition: vpMe.h:278
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:150
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
virtual void setOgreShowConfigDialog(bool showConfigDialog)
Definition: vpMbTracker.h:643
void setMinDistance(double minDistance)
error that can be emited by ViSP classes.
Definition: vpException.h:71
Definition: vpMe.h:60
Real-time 6D object pose tracking using its CAD model.
virtual void resetTracker()=0
static void flush(const vpImage< unsigned char > &I)
long getFirstFrameIndex()
void setMu1(const double &mu_1)
Definition: vpMe.h:241
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:69
static const vpColor red
Definition: vpColor.h:217
void setQuality(double qualityLevel)
void open(vpImage< vpRGBa > &I)
long getLastFrameIndex()
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
Definition: vpDisplayD3D.h:106
static std::string createFilePath(const std::string &parent, const std::string &child)
Definition: vpIoTools.cpp:1446
void setMaskSize(const unsigned int &a)
Definition: vpMe.cpp:459
void setPyramidLevels(int pyrMaxLevel)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
virtual double getProjectionError() const
Definition: vpMbTracker.h:310
Generic class defining intrinsic camera parameters.
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
Main methods for a model-based tracker.
Definition: vpMbTracker.h:104
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:134
void acquire(vpImage< vpRGBa > &I)
void setWindowSize(int winSize)
virtual void setAngleAppear(const double &a)
Definition: vpMbTracker.h:469
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
Definition: vpMath.h:110
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
void setMu2(const double &mu_2)
Definition: vpMe.h:248
virtual void setOgreVisibilityTest(const bool &v)
void setLastFrameIndex(const long last_frame)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0))
unsigned int getDownScalingFactor()
Definition: vpDisplay.h:235
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
Definition: vpKltOpencv.h:78
void setThreshold(const double &t)
Definition: vpMe.h:300
void setFileName(const std::string &filename)
virtual void setScanLineVisibilityTest(const bool &v)
Definition: vpMbTracker.h:601
virtual void setClipping(const unsigned int &flags)
void setRange(const unsigned int &r)
Definition: vpMe.h:271
virtual void setFarClippingDistance(const double &dist)
void setBlockSize(int blockSize)
virtual void setDisplayFeatures(bool displayF)
Definition: vpMbTracker.h:517
virtual void setProjectionErrorComputation(const bool &flag)
Definition: vpMbTracker.h:584
virtual void setNearClippingDistance(const double &dist)
virtual vpMatrix getCovarianceMatrix() const
Definition: vpMbTracker.h:265