Visual Servoing Platform  version 3.6.1 under development (2025-02-18)
mbtGenericTracking.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Example of Hybrid Tracking of MBT and MBT KTL.
32  */
33 
41 #include <iostream>
42 #include <visp3/core/vpConfig.h>
43 
44 #if (defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY)) && \
45  (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
46 
47 #include <visp3/core/vpDebug.h>
48 #include <visp3/core/vpHomogeneousMatrix.h>
49 #include <visp3/core/vpIoTools.h>
50 #include <visp3/core/vpMath.h>
51 #include <visp3/gui/vpDisplayFactory.h>
52 #include <visp3/io/vpImageIo.h>
53 #include <visp3/io/vpParseArgv.h>
54 #include <visp3/io/vpVideoReader.h>
55 #include <visp3/mbt/vpMbGenericTracker.h>
56 
57 #define GETOPTARGS "x:m:i:n:de:chtfColwvpT:"
58 
59 #ifdef ENABLE_VISP_NAMESPACE
60 using namespace VISP_NAMESPACE_NAME;
61 #endif
62 
63 void usage(const char *name, const char *badparam)
64 {
65 #if VISP_HAVE_DATASET_VERSION >= 0x030600
66  std::string ext("png");
67 #else
68  std::string ext("pgm");
69 #endif
70  fprintf(stdout, "\n\
71 Example of tracking based on the 3D model.\n\
72 \n\
73 SYNOPSIS\n\
74  %s [-i <test image path>] [-x <config file>]\n\
75  [-m <model name>] [-n <initialisation file base name>] [-e <last frame index>]\n\
76  [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]\n\
77  [-T <tracker type>]\n",
78  name);
79 
80  fprintf(stdout, "\n\
81 OPTIONS: \n\
82  -i <input image path> \n\
83  Set image input path.\n\
84  From this path read images \n\
85  \"mbt/cube/image%%04d.%s\". These \n\
86  images come from visp-images-x.y.z.tar.gz available \n\
87  on the ViSP website.\n\
88  Setting the VISP_INPUT_IMAGE_PATH environment\n\
89  variable produces the same behavior than using\n\
90  this option.\n\
91 \n\
92  -x <config file> \n\
93  Set the config file (the xml file) to use.\n\
94  The config file is used to specify the parameters of the tracker.\n\
95 \n\
96  -m <model name> \n\
97  Specify the name of the file of the model\n\
98  The model can either be a vrml model (.wrl) or a .cao file.\n\
99 \n\
100  -e <last frame index> \n\
101  Specify the index of the last frame. Once reached, the tracking is stopped\n\
102 \n\
103  -f \n\
104  Do not use the vrml model, use the .cao one. These two models are \n\
105  equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
106  website. However, the .cao model allows to use the 3d model based tracker \n\
107  without Coin.\n\
108 \n\
109  -C \n\
110  Track only the cube (not the cylinder). In this case the models files are\n\
111  cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
112  cube_and_cylinder.wrl.\n\
113 \n\
114  -n <initialisation file base name> \n\
115  Base name of the initialisation file. The file will be 'base_name'.init .\n\
116  This base name is also used for the optional picture specifying where to \n\
117  click (a .ppm picture).\n\
118 \n\
119  -t \n\
120  Turn off the display of the the moving edges and Klt points. \n\
121 \n\
122  -d \n\
123  Turn off the display.\n\
124 \n\
125  -c\n\
126  Disable the mouse click. Useful to automate the \n\
127  execution of this program without human intervention.\n\
128 \n\
129  -o\n\
130  Use Ogre3D for visibility tests\n\
131 \n\
132  -w\n\
133  When Ogre3D is enable [-o] show Ogre3D configuration dialog that allows to set the renderer.\n\
134 \n\
135  -l\n\
136  Use the scanline for visibility tests.\n\
137 \n\
138  -v\n\
139  Compute covariance matrix.\n\
140 \n\
141  -p\n\
142  Compute gradient projection error.\n\
143 \n\
144  -T <tracker type>\n\
145  Set tracker type (<1 (Edge)>, <2 (KLT)>, <3 (EdgeKlt)>).\n\
146 \n\
147  -h \n\
148  Print the help.\n\n", ext.c_str());
149 
150  if (badparam)
151  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
152 }
153 
154 bool getOptions(int argc, const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
155  std::string &initFile, long &lastFrame, bool &displayFeatures, bool &click_allowed, bool &display,
156  bool &cao3DModel, bool &trackCylinder, bool &useOgre, bool &showOgreConfigDialog, bool &useScanline,
157  bool &computeCovariance, bool &projectionError, int &trackerType)
158 {
159  const char *optarg_;
160  int c;
161  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
162 
163  switch (c) {
164  case 'e':
165  lastFrame = atol(optarg_);
166  break;
167  case 'i':
168  ipath = optarg_;
169  break;
170  case 'x':
171  configFile = optarg_;
172  break;
173  case 'm':
174  modelFile = optarg_;
175  break;
176  case 'n':
177  initFile = optarg_;
178  break;
179  case 't':
180  displayFeatures = false;
181  break;
182  case 'f':
183  cao3DModel = true;
184  break;
185  case 'c':
186  click_allowed = false;
187  break;
188  case 'd':
189  display = false;
190  break;
191  case 'C':
192  trackCylinder = false;
193  break;
194  case 'o':
195  useOgre = true;
196  break;
197  case 'l':
198  useScanline = true;
199  break;
200  case 'w':
201  showOgreConfigDialog = true;
202  break;
203  case 'v':
204  computeCovariance = true;
205  break;
206  case 'p':
207  projectionError = true;
208  break;
209  case 'T':
210  trackerType = atoi(optarg_);
211  break;
212  case 'h':
213  usage(argv[0], nullptr);
214  return false;
215  break;
216 
217  default:
218  usage(argv[0], optarg_);
219  return false;
220  break;
221  }
222  }
223 
224  if ((c == 1) || (c == -1)) {
225  // standalone param or error
226  usage(argv[0], nullptr);
227  std::cerr << "ERROR: " << std::endl;
228  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
229  return false;
230  }
231 
232  return true;
233 }
234 
235 int main(int argc, const char **argv)
236 {
237  try {
238  std::string env_ipath;
239  std::string opt_ipath;
240  std::string ipath;
241  std::string opt_configFile;
242  std::string opt_modelFile;
243  std::string modelFile;
244  std::string opt_initFile;
245  std::string initFile;
246  long opt_lastFrame = -1;
247  bool displayFeatures = true;
248  bool opt_click_allowed = true;
249  bool opt_display = true;
250  bool cao3DModel = false;
251  bool trackCylinder = true;
252  bool useOgre = false;
253  bool showOgreConfigDialog = false;
254  bool useScanline = false;
255  bool computeCovariance = false;
256  bool projectionError = false;
257  int trackerType = vpMbGenericTracker::EDGE_TRACKER;
258 
259 #if VISP_HAVE_DATASET_VERSION >= 0x030600
260  std::string ext("png");
261 #else
262  std::string ext("pgm");
263 #endif
264 
265  // Get the visp-images-data package path or VISP_INPUT_IMAGE_PATH
266  // environment variable value
267  env_ipath = vpIoTools::getViSPImagesDataPath();
268 
269  // Set the default input path
270  if (!env_ipath.empty())
271  ipath = env_ipath;
272 
273  // Read the command line options
274  if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayFeatures,
275  opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
276  useScanline, computeCovariance, projectionError, trackerType)) {
277  return EXIT_FAILURE;
278  }
279 
280  // Test if an input path is set
281  if (opt_ipath.empty() && env_ipath.empty()) {
282  usage(argv[0], nullptr);
283  std::cerr << std::endl << "ERROR:" << std::endl;
284  std::cerr << " Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
285  << " environment variable to specify the location of the " << std::endl
286  << " image path where test images are located." << std::endl
287  << std::endl;
288 
289  return EXIT_FAILURE;
290  }
291 
292  // Get the option values
293  if (!opt_ipath.empty())
294  ipath = vpIoTools::createFilePath(opt_ipath, "mbt/cube/image%04d." + ext);
295  else
296  ipath = vpIoTools::createFilePath(env_ipath, "mbt/cube/image%04d." + ext);
297 
298 #if defined(VISP_HAVE_PUGIXML)
299  std::string configFile;
300  if (!opt_configFile.empty())
301  configFile = opt_configFile;
302  else if (!opt_ipath.empty())
303  configFile = vpIoTools::createFilePath(opt_ipath, "mbt/cube.xml");
304  else
305  configFile = vpIoTools::createFilePath(env_ipath, "mbt/cube.xml");
306 #endif
307 
308  if (!opt_modelFile.empty()) {
309  modelFile = opt_modelFile;
310  }
311  else {
312  std::string modelFileCao;
313  std::string modelFileWrl;
314  if (trackCylinder) {
315  modelFileCao = "mbt/cube_and_cylinder.cao";
316  modelFileWrl = "mbt/cube_and_cylinder.wrl";
317  }
318  else {
319  modelFileCao = "mbt/cube.cao";
320  modelFileWrl = "mbt/cube.wrl";
321  }
322 
323  if (!opt_ipath.empty()) {
324  if (cao3DModel) {
325  modelFile = vpIoTools::createFilePath(opt_ipath, modelFileCao);
326  }
327  else {
328 #ifdef VISP_HAVE_COIN3D
329  modelFile = vpIoTools::createFilePath(opt_ipath, modelFileWrl);
330 #else
331  std::cerr << "Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
332  modelFile = vpIoTools::createFilePath(opt_ipath, modelFileCao);
333 #endif
334  }
335  }
336  else {
337  if (cao3DModel) {
338  modelFile = vpIoTools::createFilePath(env_ipath, modelFileCao);
339  }
340  else {
341 #ifdef VISP_HAVE_COIN3D
342  modelFile = vpIoTools::createFilePath(env_ipath, modelFileWrl);
343 #else
344  std::cerr << "Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
345  modelFile = vpIoTools::createFilePath(env_ipath, modelFileCao);
346 #endif
347  }
348  }
349  }
350 
351  if (!opt_initFile.empty())
352  initFile = opt_initFile;
353  else if (!opt_ipath.empty())
354  initFile = vpIoTools::createFilePath(opt_ipath, "mbt/cube");
355  else
356  initFile = vpIoTools::createFilePath(env_ipath, "mbt/cube");
357 
358  vpImage<unsigned char> I1, I2;
359  vpDisplay *display1 = nullptr, *display2 = nullptr;
360  vpVideoReader reader;
361 
362  reader.setFileName(ipath);
363  try {
364  reader.open(I1);
365  I2 = I1;
366  }
367  catch (...) {
368  std::cerr << "Cannot open sequence: " << ipath << std::endl;
369  return EXIT_FAILURE;
370  }
371 
372  if (opt_lastFrame > 1 && opt_lastFrame < reader.getLastFrameIndex())
373  reader.setLastFrameIndex(opt_lastFrame);
374 
375  reader.acquire(I1);
376  I2 = I1;
377 
378  if (opt_display) {
379  // We open a window using either X11, GTK, OpenCV or GDI
383  display2->setDownScalingFactor(vpDisplay::SCALE_AUTO);
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 
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)
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);
412  me.setThreshold(10);
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) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
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  // (Optional, 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  }
490  else {
491  vpHomogeneousMatrix c1Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
492  vpHomogeneousMatrix c2Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
493  dynamic_cast<vpMbGenericTracker *>(tracker)->initFromPose(I1, I2, c1Moi, c2Moi);
494  }
495 
496  // track the model
497  dynamic_cast<vpMbGenericTracker *>(tracker)->track(I1, I2);
498  dynamic_cast<vpMbGenericTracker *>(tracker)->getPose(c1Mo, c2Mo);
499 
500  if (opt_display) {
501  vpDisplay::flush(I1);
502  vpDisplay::flush(I2);
503  }
504 
505  bool quit = false, click = false;
506  while (!reader.end() && !quit) {
507  // acquire a new image
508  reader.acquire(I1);
509  I2 = I1;
510  // display the image
511  if (opt_display) {
512  vpDisplay::display(I1);
513  vpDisplay::display(I2);
514 
515  std::stringstream ss;
516  ss << "Num frame: " << reader.getFrameIndex() << "/" << reader.getLastFrameIndex();
517  vpDisplay::displayText(I1, 40, 20, ss.str(), vpColor::red);
518  }
519 
520  // Test to reset the tracker
521  if (reader.getFrameIndex() == reader.getFirstFrameIndex() + 10) {
522  std::cout << "----------Test reset tracker----------" << std::endl;
523  if (opt_display) {
524  vpDisplay::display(I1);
525  vpDisplay::display(I2);
526  }
527 
528  tracker->resetTracker();
529 #if defined(VISP_HAVE_PUGIXML)
530  dynamic_cast<vpMbGenericTracker *>(tracker)->loadConfigFile(configFile, configFile);
531 #else
532  // By setting the parameters:
533  cam1.initPersProjWithoutDistortion(547, 542, 338, 234);
534  cam2.initPersProjWithoutDistortion(547, 542, 338, 234);
535 
536  me.setMaskSize(5);
537  me.setMaskNumber(180);
538  me.setRange(7);
540  me.setThreshold(10);
541  me.setMu1(0.5);
542  me.setMu2(0.5);
543  me.setSampleStep(4);
544 
545 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
546  klt.setMaxFeatures(10000);
547  klt.setWindowSize(5);
548  klt.setQuality(0.01);
549  klt.setMinDistance(5);
550  klt.setHarrisFreeParameter(0.01);
551  klt.setBlockSize(3);
552  klt.setPyramidLevels(3);
553 
554  dynamic_cast<vpMbGenericTracker *>(tracker)->setKltOpencv(klt);
555  dynamic_cast<vpMbGenericTracker *>(tracker)->setKltMaskBorder(5);
556 #endif
557 
558  dynamic_cast<vpMbGenericTracker *>(tracker)->setCameraParameters(cam1, cam2);
559  dynamic_cast<vpMbGenericTracker *>(tracker)->setMovingEdge(me);
560  tracker->setAngleAppear(vpMath::rad(65));
561  tracker->setAngleDisappear(vpMath::rad(75));
562 
563  // Specify the clipping to
564  tracker->setNearClippingDistance(0.01);
565  tracker->setFarClippingDistance(0.90);
566  tracker->setClipping(tracker->getClipping() | vpMbtPolygon::FOV_CLIPPING);
567  // tracker->setClipping(tracker->getClipping() | vpMbtPolygon::LEFT_CLIPPING
568  // | vpMbtPolygon::RIGHT_CLIPPING | vpMbtPolygon::UP_CLIPPING |
569  // vpMbtPolygon::DOWN_CLIPPING); // Equivalent to FOV_CLIPPING
570 #endif
571  tracker->loadModel(modelFile);
572  dynamic_cast<vpMbGenericTracker *>(tracker)->setCameraParameters(cam1, cam2);
573  tracker->setOgreVisibilityTest(useOgre);
574  tracker->setScanLineVisibilityTest(useScanline);
575  tracker->setCovarianceComputation(computeCovariance);
576  tracker->setProjectionErrorComputation(projectionError);
577  dynamic_cast<vpMbGenericTracker *>(tracker)->initFromPose(I1, I2, c1Mo, c2Mo);
578  }
579 
580  // Test to set an initial pose
581  if (reader.getFrameIndex() == reader.getFirstFrameIndex() + 50) {
582  c1Mo.buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
583  c2Mo.buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
584  std::cout << "Test set pose" << std::endl;
585  dynamic_cast<vpMbGenericTracker *>(tracker)->setPose(I1, I2, c1Mo, c2Mo);
586  }
587 
588  // track the object: stop tracking from frame 40 to 50
589  if (reader.getFrameIndex() - reader.getFirstFrameIndex() < 40 ||
590  reader.getFrameIndex() - reader.getFirstFrameIndex() >= 50) {
591  dynamic_cast<vpMbGenericTracker *>(tracker)->track(I1, I2);
592  dynamic_cast<vpMbGenericTracker *>(tracker)->getPose(c1Mo, c2Mo);
593  if (opt_display) {
594  // display the 3D model
595  dynamic_cast<vpMbGenericTracker *>(tracker)->display(I1, I2, c1Mo, c2Mo, cam1, cam2, vpColor::darkRed);
596  // display the frame
597  vpDisplay::displayFrame(I1, c1Mo, cam1, 0.05);
598  vpDisplay::displayFrame(I2, c2Mo, cam2, 0.05);
599  }
600  }
601 
602  if (opt_click_allowed && opt_display) {
603  vpDisplay::displayText(I1, 20, 20, "Click to quit", vpColor::red);
605  if (vpDisplay::getClick(I1, button, click)) {
606  switch (button) {
608  quit = !click;
609  break;
610 
612  click = !click;
613  break;
614 
615  default:
616  break;
617  }
618  }
619  }
620 
621  if (computeCovariance) {
622  std::cout << "Covariance matrix: \n" << tracker->getCovarianceMatrix() << std::endl << std::endl;
623  }
624 
625  if (projectionError) {
626  std::cout << "Projection error: " << tracker->getProjectionError() << std::endl << std::endl;
627  }
628 
629  if (opt_display) {
630  vpDisplay::flush(I1);
631  vpDisplay::flush(I2);
632  }
633  }
634 
635  std::cout << "Reached last frame: " << reader.getFrameIndex() << std::endl;
636  std::cout << "\nFinal poses, c1Mo:\n" << c1Mo << "\nc2Mo:\n" << c2Mo << std::endl;
637 
638  if (opt_click_allowed && !quit) {
640  }
641  reader.close();
642 
643  delete tracker;
644  tracker = nullptr;
645 
646  if (display1) {
647  delete display1;
648  }
649  if (display2) {
650  delete display2;
651  }
652  return EXIT_SUCCESS;
653  }
654  catch (const vpException &e) {
655  std::cout << "Catch an exception: " << e << std::endl;
656  return EXIT_FAILURE;
657  }
658 }
659 
660 #elif !(defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY))
661 int main()
662 {
663  std::cout << "Cannot run this example: visp_mbt, visp_gui modules are required." << std::endl;
664  return EXIT_SUCCESS;
665 }
666 #else
667 int main()
668 {
669  std::cout << "Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
670  return EXIT_SUCCESS;
671 }
672 #endif
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
static const vpColor red
Definition: vpColor.h:198
static const vpColor darkRed
Definition: vpColor.h:199
Class that defines generic functionalities for display.
Definition: vpDisplay.h:178
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:79
void setBlockSize(int blockSize)
Definition: vpKltOpencv.h:272
void setQuality(double qualityLevel)
Definition: vpKltOpencv.h:361
void setHarrisFreeParameter(double harris_k)
Definition: vpKltOpencv.h:280
void setMaxFeatures(int maxCount)
Definition: vpKltOpencv.h:320
void setMinDistance(double minDistance)
Definition: vpKltOpencv.h:329
void setWindowSize(int winSize)
Definition: vpKltOpencv.h:382
void setPyramidLevels(int pyrMaxLevel)
Definition: vpKltOpencv.h:348
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
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.