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