Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
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_PUGIXML) && 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_PUGIXML) && 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_PUGIXML) && 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  me.setMaskSize(5);
535  me.setMaskNumber(180);
536  me.setRange(7);
537  me.setThreshold(5000);
538  me.setMu1(0.5);
539  me.setMu2(0.5);
540  me.setSampleStep(4);
541 
542 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
543  klt.setMaxFeatures(10000);
544  klt.setWindowSize(5);
545  klt.setQuality(0.01);
546  klt.setMinDistance(5);
547  klt.setHarrisFreeParameter(0.01);
548  klt.setBlockSize(3);
549  klt.setPyramidLevels(3);
550 
551  dynamic_cast<vpMbGenericTracker *>(tracker)->setKltOpencv(klt);
552  dynamic_cast<vpMbGenericTracker *>(tracker)->setKltMaskBorder(5);
553 #endif
554 
555  dynamic_cast<vpMbGenericTracker *>(tracker)->setCameraParameters(cam1, cam2);
556  dynamic_cast<vpMbGenericTracker *>(tracker)->setMovingEdge(me);
557  tracker->setAngleAppear(vpMath::rad(65));
558  tracker->setAngleDisappear(vpMath::rad(75));
559 
560  // Specify the clipping to
561  tracker->setNearClippingDistance(0.01);
562  tracker->setFarClippingDistance(0.90);
563  tracker->setClipping(tracker->getClipping() | vpMbtPolygon::FOV_CLIPPING);
564 // tracker->setClipping(tracker->getClipping() | vpMbtPolygon::LEFT_CLIPPING
565 // | vpMbtPolygon::RIGHT_CLIPPING | vpMbtPolygon::UP_CLIPPING |
566 // vpMbtPolygon::DOWN_CLIPPING); // Equivalent to FOV_CLIPPING
567 #endif
568  tracker->loadModel(modelFile);
569  dynamic_cast<vpMbGenericTracker *>(tracker)->setCameraParameters(cam1, cam2);
570  tracker->setOgreVisibilityTest(useOgre);
571  tracker->setScanLineVisibilityTest(useScanline);
572  tracker->setCovarianceComputation(computeCovariance);
573  tracker->setProjectionErrorComputation(projectionError);
574  dynamic_cast<vpMbGenericTracker *>(tracker)->initFromPose(I1, I2, c1Mo, c2Mo);
575  }
576 
577  // Test to set an initial pose
578  if (reader.getFrameIndex() == reader.getFirstFrameIndex() + 50) {
579  c1Mo.buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
580  c2Mo.buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
581  std::cout << "Test set pose" << std::endl;
582  dynamic_cast<vpMbGenericTracker *>(tracker)->setPose(I1, I2, c1Mo, c2Mo);
583  }
584 
585  // track the object: stop tracking from frame 40 to 50
586  if (reader.getFrameIndex() - reader.getFirstFrameIndex() < 40 ||
587  reader.getFrameIndex() - reader.getFirstFrameIndex() >= 50) {
588  dynamic_cast<vpMbGenericTracker *>(tracker)->track(I1, I2);
589  dynamic_cast<vpMbGenericTracker *>(tracker)->getPose(c1Mo, c2Mo);
590  if (opt_display) {
591  // display the 3D model
592  dynamic_cast<vpMbGenericTracker *>(tracker)->display(I1, I2, c1Mo, c2Mo, cam1, cam2, vpColor::darkRed);
593  // display the frame
594  vpDisplay::displayFrame(I1, c1Mo, cam1, 0.05);
595  vpDisplay::displayFrame(I2, c2Mo, cam2, 0.05);
596  }
597  }
598 
599  if (opt_click_allowed && opt_display) {
600  vpDisplay::displayText(I1, 10, 10, "Click to quit", vpColor::red);
602  if (vpDisplay::getClick(I1, button, click)) {
603  switch (button) {
605  quit = !click;
606  break;
607 
609  click = !click;
610  break;
611 
612  default:
613  break;
614  }
615  }
616  }
617 
618  if (computeCovariance) {
619  std::cout << "Covariance matrix: \n" << tracker->getCovarianceMatrix() << std::endl << std::endl;
620  }
621 
622  if (projectionError) {
623  std::cout << "Projection error: " << tracker->getProjectionError() << std::endl << std::endl;
624  }
625 
626  if (opt_display) {
627  vpDisplay::flush(I1);
628  vpDisplay::flush(I2);
629  }
630  }
631 
632  std::cout << "Reached last frame: " << reader.getFrameIndex() << std::endl;
633  std::cout << "\nFinal poses, c1Mo:\n" << c1Mo << "\nc2Mo:\n" << c2Mo << std::endl;
634 
635  if (opt_click_allowed && !quit) {
637  }
638  reader.close();
639 
640  delete tracker;
641  tracker = NULL;
642 
643 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION >= 2)
644  // Cleanup memory allocated by Coin library used to load a vrml model in
645  // vpMbGenericTracker::loadModel() We clean only if Coin was used.
646  if (!cao3DModel)
647  SoDB::finish();
648 #endif
649 
650  return EXIT_SUCCESS;
651  } catch (const vpException &e) {
652  std::cout << "Catch an exception: " << e << std::endl;
653  return EXIT_FAILURE;
654  }
655 }
656 
657 #else
658 
659 int main()
660 {
661  std::cout << "visp_mbt, visp_gui modules and OpenCV are required to run "
662  "this example."
663  << std::endl;
664  return EXIT_SUCCESS;
665 }
666 
667 #endif
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:252
virtual void setCovarianceComputation(const bool &flag)
Definition: vpMbTracker.h:495
void setMaxFeatures(int maxCount)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1292
void setHarrisFreeParameter(double harris_k)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setAngleDisappear(const double &a)
Definition: vpMbTracker.h:476
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:231
static const vpColor darkRed
Definition: vpColor.h:180
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:639
virtual double getProjectionError() const
Definition: vpMbTracker.h:306
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:179
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:1537
void setMaskSize(const unsigned int &a)
Definition: vpMe.cpp:461
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...
Generic class defining intrinsic camera parameters.
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:137
void acquire(vpImage< vpRGBa > &I)
void setWindowSize(int winSize)
virtual void setAngleAppear(const double &a)
Definition: vpMbTracker.h:465
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
Definition: vpMath.h:108
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void setMu2(const double &mu_2)
Definition: vpMe.h:248
long getFrameIndex() const
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
virtual vpMatrix getCovarianceMatrix() const
Definition: vpMbTracker.h:261
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:597
virtual void setClipping(const unsigned int &flags)
void setRange(const unsigned int &r)
Definition: vpMe.h:271
virtual void setFarClippingDistance(const double &dist)
unsigned int getWidth() const
Definition: vpImage.h:244
void setBlockSize(int blockSize)
virtual void setDisplayFeatures(bool displayF)
Definition: vpMbTracker.h:513
virtual void setProjectionErrorComputation(const bool &flag)
Definition: vpMbTracker.h:580
virtual void setNearClippingDistance(const double &dist)