47 #include <visp3/core/vpConfig.h>
49 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
51 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && \
52 defined(VISP_HAVE_DISPLAY) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
54 #include <visp3/core/vpDebug.h>
55 #include <visp3/core/vpHomogeneousMatrix.h>
56 #include <visp3/core/vpIoTools.h>
57 #include <visp3/core/vpMath.h>
58 #include <visp3/gui/vpDisplayD3D.h>
59 #include <visp3/gui/vpDisplayGDI.h>
60 #include <visp3/gui/vpDisplayGTK.h>
61 #include <visp3/gui/vpDisplayOpenCV.h>
62 #include <visp3/gui/vpDisplayX.h>
63 #include <visp3/io/vpImageIo.h>
64 #include <visp3/io/vpParseArgv.h>
65 #include <visp3/io/vpVideoReader.h>
66 #include <visp3/mbt/vpMbKltMultiTracker.h>
68 #define GETOPTARGS "x:m:i:n:de:chtfolwv"
70 void usage(
const char *name,
const char *badparam)
73 Example of tracking based on the 3D model.\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] [-o] [-w] [-l] [-v]\n", name);
82 -i <input image path> \n\
83 Set image input path.\n\
84 From this path read images \n\
85 \"mbt/cube/image%%04d.ppm\". 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\
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\
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\
100 -e <last frame index> \n\
101 Specify the index of the last frame. Once reached, the tracking is stopped\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\
109 -n <initialisation file base name> \n\
110 Base name of the initialisation file. The file will be 'base_name'.init .\n\
111 This base name is also used for the optional picture specifying where to \n\
112 click (a .ppm picture).\n\
115 Turn off the display of the the klt points. \n\
118 Turn off the display.\n\
121 Disable the mouse click. Useful to automate the \n\
122 execution of this program without human intervention.\n\
125 Use Ogre3D for visibility tests\n\
128 When Ogre3D is enable [-o] show Ogre3D configuration dialog that allows to set the renderer.\n\
131 Use the scanline for visibility tests.\n\
134 Compute covariance matrix.\n\
137 Print the help.\n\n");
140 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
143 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
144 std::string &initFile,
long &lastFrame,
bool &displayKltPoints,
bool &click_allowed,
bool &display,
145 bool &cao3DModel,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
bool &computeCovariance)
153 lastFrame = atol(optarg_);
159 configFile = optarg_;
168 displayKltPoints =
false;
174 click_allowed =
false;
186 showOgreConfigDialog =
true;
189 computeCovariance =
true;
192 usage(argv[0], NULL);
197 usage(argv[0], optarg_);
203 if ((c == 1) || (c == -1)) {
205 usage(argv[0], NULL);
206 std::cerr <<
"ERROR: " << std::endl;
207 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
214 int main(
int argc,
const char **argv)
217 std::string env_ipath;
218 std::string opt_ipath;
220 std::string opt_configFile;
221 std::string configFile;
222 std::string opt_modelFile;
223 std::string modelFile;
224 std::string opt_initFile;
225 std::string initFile;
226 long opt_lastFrame = -1;
227 bool displayKltPoints =
true;
228 bool opt_click_allowed =
true;
229 bool opt_display =
true;
230 bool cao3DModel =
false;
231 bool useOgre =
false;
232 bool showOgreConfigDialog =
false;
233 bool useScanline =
false;
234 bool computeCovariance =
false;
242 if (!env_ipath.empty())
246 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayKltPoints,
247 opt_click_allowed, opt_display, cao3DModel, useOgre, showOgreConfigDialog, useScanline,
248 computeCovariance)) {
253 if (opt_ipath.empty() && env_ipath.empty()) {
254 usage(argv[0], NULL);
255 std::cerr << std::endl <<
"ERROR:" << std::endl;
256 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
257 <<
" environment variable to specify the location of the " << std::endl
258 <<
" image path where test images are located." << std::endl
265 if (!opt_ipath.empty())
270 if (!opt_configFile.empty())
271 configFile = opt_configFile;
272 else if (!opt_ipath.empty())
277 if (!opt_modelFile.empty()) {
278 modelFile = opt_modelFile;
280 std::string modelFileCao =
"mbt/cube.cao";
281 std::string modelFileWrl =
"mbt/cube.wrl";
283 if (!opt_ipath.empty()) {
287 #ifdef VISP_HAVE_COIN3D
290 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
298 #ifdef VISP_HAVE_COIN3D
301 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
308 if (!opt_initFile.empty())
309 initFile = opt_initFile;
310 else if (!opt_ipath.empty())
323 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
334 #if defined VISP_HAVE_X11
336 #elif defined VISP_HAVE_GDI
338 #elif defined VISP_HAVE_OPENCV
340 #elif defined VISP_HAVE_D3D9
342 #elif defined VISP_HAVE_GTK
348 #if defined(VISP_HAVE_DISPLAY)
351 display1.
init(I1, 100, 100,
"Test tracking (Left)");
365 #if defined(VISP_HAVE_PUGIXML)
367 tracker.loadConfigFile(configFile, configFile);
382 tracker.setCameraParameters(cam1, cam2);
383 tracker.setKltOpencv(klt);
384 tracker.setKltMaskBorder(5);
389 tracker.setNearClippingDistance(0.01);
390 tracker.setFarClippingDistance(0.90);
398 tracker.setDisplayFeatures(displayKltPoints);
401 tracker.setOgreVisibilityTest(useOgre);
403 tracker.setOgreShowConfigDialog(showOgreConfigDialog);
406 tracker.setScanLineVisibilityTest(useScanline);
409 tracker.setCovarianceComputation(computeCovariance);
412 tracker.getCameraParameters(cam1, cam2);
415 if (opt_display && opt_click_allowed) {
425 tracker.loadModel(modelFile);
433 if (opt_display && opt_click_allowed) {
434 tracker.initClick(I1, I2, initFile, initFile,
true);
435 tracker.getPose(c1Mo, c2Mo);
437 tracker.display(I1, I2, c1Mo, c2Mo, cam1, cam2,
vpColor::red);
439 vpHomogeneousMatrix c1Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
440 vpHomogeneousMatrix c2Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
441 tracker.initFromPose(I1, I2, c1Moi, c2Moi);
445 tracker.track(I1, I2);
446 tracker.getPose(c1Mo, c2Mo);
453 while (!reader.
end()) {
465 std::cout <<
"----------Test reset tracker----------" << std::endl;
470 tracker.resetTracker();
471 #if defined(VISP_HAVE_PUGIXML)
472 tracker.loadConfigFile(configFile, configFile);
487 tracker.setCameraParameters(cam1, cam2);
488 tracker.setKltOpencv(klt);
489 tracker.setKltMaskBorder(5);
494 tracker.setNearClippingDistance(0.01);
495 tracker.setFarClippingDistance(0.90);
501 tracker.loadModel(modelFile);
502 tracker.setCameraParameters(cam1, cam2);
503 tracker.setOgreVisibilityTest(useOgre);
504 tracker.setScanLineVisibilityTest(useScanline);
505 tracker.setCovarianceComputation(computeCovariance);
506 tracker.initFromPose(I1, I2, c1Mo, c2Mo);
511 c1Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
512 c2Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
513 std::cout <<
"Test set pose" << std::endl;
514 tracker.setPose(I1, I2, c1Mo, c2Mo);
520 tracker.track(I1, I2);
521 tracker.getPose(c1Mo, c2Mo);
531 if (opt_click_allowed) {
539 if (computeCovariance) {
540 std::cout <<
"Covariance matrix: \n" << tracker.getCovarianceMatrix() << std::endl << std::endl;
549 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
551 if (opt_click_allowed && !quit) {
557 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION >= 2)
566 std::cout <<
"Catch an exception: " << e << std::endl;
574 std::cout <<
"visp_mbt, visp_gui modules and OpenCV are required to run "
583 std::cout <<
"Nothing to run, deprecated example." << std::endl;
586 #endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)