42#include <visp3/core/vpConfig.h>
44#if (defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY)) && \
45 (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
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/vpMbEdgeTracker.h>
57#define GETOPTARGS "cCde:fhi:lm:n:opstvwx:"
59#ifdef ENABLE_VISP_NAMESPACE
63void usage(
const char *name,
const char *badparam)
65#if defined(VISP_HAVE_DATASET)
66#if VISP_HAVE_DATASET_VERSION >= 0x030600
67 std::string ext(
"png");
69 std::string ext(
"pgm");
73 std::string ext(
"png");
77Example of tracking based on the 3D model.\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] [-s]\n",
87 -i <input image path> \n\
88 Set image input path.\n\
89 From this path read images \n\
90 \"mbt/cube/image%%04d.%s\". These \n\
91 images come from visp-images-x.y.z.tar.gz available \n\
92 on the ViSP website.\n\
93 Setting the VISP_INPUT_IMAGE_PATH environment\n\
94 variable produces the same behaviour than using\n\
98 Set the config file (the xml file) to use.\n\
99 The config file is used to specify the parameters of the tracker.\n\
102 Specify the name of the file of the model\n\
103 The model can either be a vrml model (.wrl) or a .cao file.\n\
105 -e <last frame index> \n\
106 Specify the index of the last frame. Once reached, the tracking is stopped\n\
109 Enable step-by-step mode when click is allowed.\n\
112 Do not use the vrml model, use the .cao one. These two models are \n\
113 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
114 website. However, the .cao model allows to use the 3d model based tracker \n\
118 Track only the cube (not the cylinder). In this case the models files are\n\
119 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
120 cube_and_cylinder.wrl.\n\
122 -n <initialisation file base name> \n\
123 Base name of the initialisation file. The file will be 'base_name'.init .\n\
124 This base name is also used for the Optional picture specifying where to \n\
125 click (a .ppm picture).\n\
128 Turn off the display of the the moving edges. \n\
131 Turn off the display.\n\
134 Disable the mouse click. Useful to automate the \n\
135 execution of this program without human intervention.\n\
138 Use Ogre3D for visibility tests.\n\
141 When Ogre3D is enable [-o] show Ogre3D configuration dialog thatallows to set the renderer.\n\
144 Use the scanline for visibility tests.\n\
147 Compute covariance matrix.\n\
150 Compute gradient projection error.\n\
153 Print the help.\n\n",
157 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
160bool 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,
bool &step_by_step)
174 lastFrame = atol(optarg_);
180 configFile = optarg_;
189 displayFeatures =
false;
195 click_allowed =
false;
201 trackCylinder =
false;
210 showOgreConfigDialog =
true;
213 computeCovariance =
true;
216 projectionError =
true;
219 usage(argv[0],
nullptr);
223 usage(argv[0], optarg_);
228 if ((c == 1) || (c == -1)) {
230 usage(argv[0],
nullptr);
231 std::cerr <<
"ERROR: " << std::endl;
232 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
239int main(
int argc,
const char **argv)
241#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
242 std::shared_ptr<vpDisplay> display;
249 std::string env_ipath;
250 std::string opt_ipath;
252 std::string opt_configFile;
253 std::string configFile;
254 std::string opt_modelFile;
255 std::string modelFile;
256 std::string opt_initFile;
257 std::string initFile;
258 long opt_lastFrame = -1;
259 bool displayFeatures =
true;
260 bool opt_click_allowed =
true;
261 bool opt_display =
true;
262 bool cao3DModel =
false;
263 bool trackCylinder =
true;
264 bool useOgre =
false;
265 bool showOgreConfigDialog =
false;
266 bool useScanline =
false;
267 bool computeCovariance =
false;
268 bool projectionError =
false;
269 bool opt_step_by_step =
false;
272#if defined(VISP_HAVE_DATASET)
273#if VISP_HAVE_DATASET_VERSION >= 0x030600
274 std::string ext(
"png");
276 std::string ext(
"pgm");
280 std::string ext(
"png");
288 if (!env_ipath.empty())
292 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayFeatures,
293 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
294 useScanline, computeCovariance, projectionError, opt_step_by_step)) {
299 if (opt_ipath.empty() && env_ipath.empty()) {
300 usage(argv[0],
nullptr);
301 std::cerr << std::endl <<
"ERROR:" << std::endl;
302 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
303 <<
" environment variable to specify the location of the " << std::endl
304 <<
" image path where test images are located." << std::endl
311 if (!opt_ipath.empty())
316 if (!opt_configFile.empty())
317 configFile = opt_configFile;
318 else if (!opt_ipath.empty())
323 if (!opt_modelFile.empty()) {
324 modelFile = opt_modelFile;
327 std::string modelFileCao;
328 std::string modelFileWrl;
330 modelFileCao =
"mbt/cube_and_cylinder.cao";
331 modelFileWrl =
"mbt/cube_and_cylinder.wrl";
334 modelFileCao =
"mbt/cube.cao";
335 modelFileWrl =
"mbt/cube.wrl";
338 if (!opt_ipath.empty()) {
343#ifdef VISP_HAVE_COIN3D
346 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
356#ifdef VISP_HAVE_COIN3D
359 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
366 if (!opt_initFile.empty())
367 initFile = opt_initFile;
368 else if (!opt_ipath.empty())
381 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
391#ifndef VISP_HAVE_DISPLAY
395#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
409#if defined(VISP_HAVE_PUGIXML)
411 tracker.loadConfigFile(configFile);
415 cam.initPersProjWithoutDistortion(547, 542, 338, 234);
427 tracker.setCameraParameters(cam);
431 tracker.setNearClippingDistance(0.01);
432 tracker.setFarClippingDistance(0.90);
441 tracker.setDisplayFeatures(displayFeatures);
444 tracker.setOgreVisibilityTest(useOgre);
446 tracker.setOgreShowConfigDialog(showOgreConfigDialog);
449 tracker.setScanLineVisibilityTest(useScanline);
452 tracker.setCovarianceComputation(computeCovariance);
455 tracker.setProjectionErrorComputation(projectionError);
458 tracker.getCameraParameters(cam);
461 if (opt_display && opt_click_allowed) {
478 if (opt_display && opt_click_allowed) {
479 tracker.initClick(I, initFile,
true);
485 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
496 while (!reader.
end()) {
510#if defined(VISP_HAVE_PUGIXML)
511 tracker.loadConfigFile(configFile);
515 cam.initPersProjWithoutDistortion(547, 542, 338, 234);
527 tracker.setCameraParameters(cam);
531 tracker.setNearClippingDistance(0.01);
532 tracker.setFarClippingDistance(0.90);
539 tracker.setCameraParameters(cam);
540 tracker.setOgreVisibilityTest(useOgre);
541 tracker.setScanLineVisibilityTest(useScanline);
542 tracker.setCovarianceComputation(computeCovariance);
543 tracker.setProjectionErrorComputation(projectionError);
549 cMo.buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
577 if (opt_click_allowed && opt_display) {
578 vpDisplay::displayText(I, 20, I.getWidth() - 150, std::string(
"Mode: ") + (opt_step_by_step ? std::string(
"step-by-step") : std::string(
"continuous")),
vpColor::red);
581 if (opt_step_by_step) {
590 opt_step_by_step = !opt_step_by_step;
595 if (computeCovariance) {
596 std::cout <<
"Covariance matrix: \n" <<
tracker.getCovarianceMatrix() << std::endl << std::endl;
599 if (projectionError) {
600 std::cout <<
"Projection error: " <<
tracker.getProjectionError() << std::endl << std::endl;
607 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
609 if (opt_click_allowed && !quit) {
613 return_status = EXIT_SUCCESS;
616 std::cout <<
"Catch an exception: " <<
e << std::endl;
617 return_status = EXIT_FAILURE;
619#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
625 return return_status;
628#elif !(defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY))
631 std::cout <<
"Cannot run this example: visp_mbt, visp_gui modules are required." << std::endl;
637 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
Generic class defining intrinsic camera parameters.
static const vpColor darkRed
Class that defines generic functionalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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)
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.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Make the complete tracking of an object by using its CAD model.
void setMu1(const double &mu_1)
void setRange(const unsigned int &range)
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
void setMaskNumber(const unsigned int &mask_number)
void setThreshold(const double &threshold)
void setSampleStep(const double &sample_step)
void setMaskSize(const unsigned int &mask_size)
void setMu2(const double &mu_2)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void setLastFrameIndex(const long last_frame)
void open(vpImage< vpRGBa > &I) VP_OVERRIDE
void setFileName(const std::string &filename)
long getFirstFrameIndex()
long getFrameIndex() const
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.