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