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