41#include <visp3/core/vpConfig.h>
43#if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && \
44 defined(VISP_HAVE_DISPLAY) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
46#include <visp3/core/vpDebug.h>
47#include <visp3/core/vpHomogeneousMatrix.h>
48#include <visp3/core/vpIoTools.h>
49#include <visp3/core/vpMath.h>
50#include <visp3/gui/vpDisplayD3D.h>
51#include <visp3/gui/vpDisplayGDI.h>
52#include <visp3/gui/vpDisplayGTK.h>
53#include <visp3/gui/vpDisplayOpenCV.h>
54#include <visp3/gui/vpDisplayX.h>
55#include <visp3/io/vpImageIo.h>
56#include <visp3/io/vpParseArgv.h>
57#include <visp3/io/vpVideoReader.h>
58#include <visp3/mbt/vpMbKltTracker.h>
60#define GETOPTARGS "x:m:i:n:de:chtfolwv"
62#ifdef ENABLE_VISP_NAMESPACE
66void usage(
const char *name,
const char *badparam)
68#if defined(VISP_HAVE_DATASET)
69#if VISP_HAVE_DATASET_VERSION >= 0x030600
70 std::string ext(
"png");
72 std::string ext(
"pgm");
76 std::string ext(
"png");
79Example of tracking based on the 3D model.\n\
82 %s [-i <test image path>] [-x <config file>]\n\
83 [-m <model name>] [-n <initialisation file base name>] [-e <last frame index>]\n\
84 [-t] [-c] [-d] [-h] [-f] [-o] [-w] [-l] [-v]\n",
89 -i <input image path> \n\
90 Set image input path.\n\
91 From this path read images \n\
92 \"mbt/cube/image%%04d.%s\". These \n\
93 images come from visp-images-x.y.z.tar.gz available \n\
94 on the ViSP website.\n\
95 Setting the VISP_INPUT_IMAGE_PATH environment\n\
96 variable produces the same behaviour than using\n\
100 Set the config file (the xml file) to use.\n\
101 The config file is used to specify the parameters of the tracker.\n\
104 Specify the name of the file of the model\n\
105 The model can either be a vrml model (.wrl) or a .cao file.\n\
107 -e <last frame index> \n\
108 Specify the index of the last frame. Once reached, the tracking is stopped\n\
111 Do not use the vrml model, use the .cao one. These two models are \n\
112 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
113 website. However, the .cao model allows to use the 3d model based tracker \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\
122 Turn off the display of the the klt points. \n\
125 Turn off the display.\n\
128 Disable the mouse click. Useful to automate the \n\
129 execution of this program without human intervention.\n\
132 Use Ogre3D for visibility tests\n\
135 When Ogre3D is enable [-o] show Ogre3D configuration dialog thatallows to set the renderer.\n\
138 Use the scanline for visibility tests.\n\
141 Compute covariance matrix.\n\
144 Print the help.\n\n",
148 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
151bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
152 std::string &initFile,
long &lastFrame,
bool &displayKltPoints,
bool &click_allowed,
bool &display,
153 bool &cao3DModel,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
bool &computeCovariance)
161 lastFrame = atol(optarg_);
167 configFile = optarg_;
176 displayKltPoints =
false;
182 click_allowed =
false;
194 showOgreConfigDialog =
true;
197 computeCovariance =
true;
200 usage(argv[0],
nullptr);
204 usage(argv[0], optarg_);
209 if ((c == 1) || (c == -1)) {
211 usage(argv[0],
nullptr);
212 std::cerr <<
"ERROR: " << std::endl;
213 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
220int main(
int argc,
const char **argv)
223 std::string env_ipath;
224 std::string opt_ipath;
226 std::string opt_configFile;
227 std::string configFile;
228 std::string opt_modelFile;
229 std::string modelFile;
230 std::string opt_initFile;
231 std::string initFile;
232 long opt_lastFrame = -1;
233 bool displayKltPoints =
true;
234 bool opt_click_allowed =
true;
235 bool opt_display =
true;
236 bool cao3DModel =
false;
237 bool useOgre =
false;
238 bool showOgreConfigDialog =
false;
239 bool useScanline =
false;
240 bool computeCovariance =
false;
243#if defined(VISP_HAVE_DATASET)
244#if VISP_HAVE_DATASET_VERSION >= 0x030600
245 std::string ext(
"png");
247 std::string ext(
"pgm");
251 std::string ext(
"png");
259 if (!env_ipath.empty())
263 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayKltPoints,
264 opt_click_allowed, opt_display, cao3DModel, useOgre, showOgreConfigDialog, useScanline,
265 computeCovariance)) {
270 if (opt_ipath.empty() && env_ipath.empty()) {
271 usage(argv[0],
nullptr);
272 std::cerr << std::endl <<
"ERROR:" << std::endl;
273 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
274 <<
" environment variable to specify the location of the " << std::endl
275 <<
" image path where test images are located." << std::endl
282 if (!opt_ipath.empty())
287 if (!opt_configFile.empty())
288 configFile = opt_configFile;
289 else if (!opt_ipath.empty())
294 if (!opt_modelFile.empty()) {
295 modelFile = opt_modelFile;
298 std::string modelFileCao =
"mbt/cube.cao";
299 std::string modelFileWrl =
"mbt/cube.wrl";
301 if (!opt_ipath.empty()) {
306#ifdef VISP_HAVE_COIN3D
309 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
319#ifdef VISP_HAVE_COIN3D
322 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
329 if (!opt_initFile.empty())
330 initFile = opt_initFile;
331 else if (!opt_ipath.empty())
344 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
354#if defined(VISP_HAVE_X11)
356#elif defined(VISP_HAVE_GDI)
358#elif defined(HAVE_OPENCV_HIGHGUI)
360#elif defined(VISP_HAVE_D3D9)
362#elif defined(VISP_HAVE_GTK)
368#if defined(VISP_HAVE_DISPLAY)
369 display.init(I, 100, 100,
"Test tracking");
381#if defined(VISP_HAVE_PUGIXML)
383 tracker.loadConfigFile(configFile);
387 cam.initPersProjWithoutDistortion(547, 542, 338, 234);
398 tracker.setCameraParameters(cam);
405 tracker.setNearClippingDistance(0.01);
406 tracker.setFarClippingDistance(0.90);
414 tracker.setDisplayFeatures(displayKltPoints);
417 tracker.setOgreVisibilityTest(useOgre);
419 tracker.setOgreShowConfigDialog(showOgreConfigDialog);
422 tracker.setScanLineVisibilityTest(useScanline);
425 tracker.setCovarianceComputation(computeCovariance);
428 tracker.getCameraParameters(cam);
431 if (opt_display && opt_click_allowed) {
448 if (opt_display && opt_click_allowed) {
449 tracker.initClick(I, initFile,
true);
455 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
466 while (!reader.
end()) {
480#if defined(VISP_HAVE_PUGIXML)
481 tracker.loadConfigFile(configFile);
485 cam.initPersProjWithoutDistortion(547, 542, 338, 234);
496 tracker.setCameraParameters(cam);
503 tracker.setNearClippingDistance(0.01);
504 tracker.setFarClippingDistance(0.90);
511 tracker.setCameraParameters(cam);
512 tracker.setOgreVisibilityTest(useOgre);
513 tracker.setScanLineVisibilityTest(useScanline);
514 tracker.setCovarianceComputation(computeCovariance);
520 cMo.buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
548 if (opt_click_allowed) {
556 if (computeCovariance) {
557 std::cout <<
"Covariance matrix: \n" <<
tracker.getCovarianceMatrix() << std::endl << std::endl;
564 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
566 if (opt_click_allowed && !quit) {
575 std::cout <<
"Catch an exception: " <<
e << std::endl;
584 std::cout <<
"visp_mbt, visp_gui modules and OpenCV are required to run "
Generic class defining intrinsic camera parameters.
static const vpColor darkRed
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
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...
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.
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
void setBlockSize(int blockSize)
void setQuality(double qualityLevel)
void setHarrisFreeParameter(double harris_k)
void setMaxFeatures(int maxCount)
void setMinDistance(double minDistance)
void setWindowSize(int winSize)
void setPyramidLevels(int pyrMaxLevel)
static double rad(double deg)
Model based tracker using only KLT.
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