46 #include <visp3/core/vpConfig.h>
48 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && \
49 defined(VISP_HAVE_DISPLAY) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
51 #include <visp3/core/vpDebug.h>
52 #include <visp3/core/vpHomogeneousMatrix.h>
53 #include <visp3/core/vpIoTools.h>
54 #include <visp3/core/vpMath.h>
55 #include <visp3/gui/vpDisplayD3D.h>
56 #include <visp3/gui/vpDisplayGDI.h>
57 #include <visp3/gui/vpDisplayGTK.h>
58 #include <visp3/gui/vpDisplayOpenCV.h>
59 #include <visp3/gui/vpDisplayX.h>
60 #include <visp3/io/vpImageIo.h>
61 #include <visp3/io/vpParseArgv.h>
62 #include <visp3/io/vpVideoReader.h>
63 #include <visp3/mbt/vpMbKltTracker.h>
65 #define GETOPTARGS "x:m:i:n:de:chtfolwv"
67 void usage(
const char *name,
const char *badparam)
70 Example of tracking based on the 3D model.\n\
73 %s [-i <test image path>] [-x <config file>]\n\
74 [-m <model name>] [-n <initialisation file base name>] [-e <last frame index>]\n\
75 [-t] [-c] [-d] [-h] [-f] [-o] [-w] [-l] [-v]\n",
80 -i <input image path> \n\
81 Set image input path.\n\
82 From this path read images \n\
83 \"mbt/cube/image%%04d.ppm\". These \n\
84 images come from ViSP-images-x.y.z.tar.gz available \n\
85 on the ViSP website.\n\
86 Setting the VISP_INPUT_IMAGE_PATH environment\n\
87 variable produces the same behaviour than using\n\
91 Set the config file (the xml file) to use.\n\
92 The config file is used to specify the parameters of the tracker.\n\
95 Specify the name of the file of the model\n\
96 The model can either be a vrml model (.wrl) or a .cao file.\n\
98 -e <last frame index> \n\
99 Specify the index of the last frame. Once reached, the tracking is stopped\n\
102 Do not use the vrml model, use the .cao one. These two models are \n\
103 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
104 website. However, the .cao model allows to use the 3d model based tracker \n\
107 -n <initialisation file base name> \n\
108 Base name of the initialisation file. The file will be 'base_name'.init .\n\
109 This base name is also used for the optionnal picture specifying where to \n\
110 click (a .ppm picture).\n\
113 Turn off the display of the the klt points. \n\
116 Turn off the display.\n\
119 Disable the mouse click. Useful to automaze the \n\
120 execution of this program without humain intervention.\n\
123 Use Ogre3D for visibility tests\n\
126 When Ogre3D is enable [-o] show Ogre3D configuration dialog thatallows to set the renderer.\n\
129 Use the scanline for visibility tests.\n\
132 Compute covariance matrix.\n\
135 Print the help.\n\n");
138 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
141 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
142 std::string &initFile,
long &lastFrame,
bool &displayKltPoints,
bool &click_allowed,
bool &display,
143 bool &cao3DModel,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
bool &computeCovariance)
151 lastFrame = atol(optarg_);
157 configFile = optarg_;
166 displayKltPoints =
false;
172 click_allowed =
false;
184 showOgreConfigDialog =
true;
187 computeCovariance =
true;
190 usage(argv[0], NULL);
195 usage(argv[0], optarg_);
201 if ((c == 1) || (c == -1)) {
203 usage(argv[0], NULL);
204 std::cerr <<
"ERROR: " << std::endl;
205 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
212 int main(
int argc,
const char **argv)
215 std::string env_ipath;
216 std::string opt_ipath;
218 std::string opt_configFile;
219 std::string configFile;
220 std::string opt_modelFile;
221 std::string modelFile;
222 std::string opt_initFile;
223 std::string initFile;
224 long opt_lastFrame = -1;
225 bool displayKltPoints =
true;
226 bool opt_click_allowed =
true;
227 bool opt_display =
true;
228 bool cao3DModel =
false;
229 bool useOgre =
false;
230 bool showOgreConfigDialog =
false;
231 bool useScanline =
false;
232 bool computeCovariance =
false;
240 if (!env_ipath.empty())
244 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayKltPoints,
245 opt_click_allowed, opt_display, cao3DModel, useOgre, showOgreConfigDialog, useScanline,
246 computeCovariance)) {
251 if (opt_ipath.empty() && env_ipath.empty()) {
252 usage(argv[0], NULL);
253 std::cerr << std::endl <<
"ERROR:" << std::endl;
254 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
255 <<
" environment variable to specify the location of the " << std::endl
256 <<
" image path where test images are located." << std::endl
263 if (!opt_ipath.empty())
268 if (!opt_configFile.empty())
269 configFile = opt_configFile;
270 else if (!opt_ipath.empty())
275 if (!opt_modelFile.empty()) {
276 modelFile = opt_modelFile;
278 std::string modelFileCao =
"mbt/cube.cao";
279 std::string modelFileWrl =
"mbt/cube.wrl";
281 if (!opt_ipath.empty()) {
285 #ifdef VISP_HAVE_COIN3D
288 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
296 #ifdef VISP_HAVE_COIN3D
299 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
306 if (!opt_initFile.empty())
307 initFile = opt_initFile;
308 else if (!opt_ipath.empty())
320 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
330 #if defined VISP_HAVE_X11
332 #elif defined VISP_HAVE_GDI
334 #elif defined VISP_HAVE_OPENCV
336 #elif defined VISP_HAVE_D3D9
338 #elif defined VISP_HAVE_GTK
344 #if defined(VISP_HAVE_DISPLAY)
345 display.init(I, 100, 100,
"Test tracking");
405 if (opt_display && opt_click_allowed) {
422 if (opt_display && opt_click_allowed) {
428 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
439 while (!reader.
end()) {
491 cMo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
519 if (opt_click_allowed) {
527 if (computeCovariance) {
528 std::cout <<
"Covariance matrix: \n" << tracker.
getCovarianceMatrix() << std::endl << std::endl;
535 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
537 if (opt_click_allowed && !quit) {
545 std::cout <<
"Catch an exception: " << e << std::endl;
554 std::cout <<
"visp_mbt, visp_gui modules and OpenCV are required to run "
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
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 flush(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))
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emited by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
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.
virtual void setScanLineVisibilityTest(const bool &v)
virtual void track(const vpImage< unsigned char > &I)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
virtual void setKltOpencv(const vpKltOpencv &t)
virtual void loadConfigFile(const std::string &configFile, bool verbose=true)
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
virtual void setOgreVisibilityTest(const bool &v)
void setCameraParameters(const vpCameraParameters &cam)
void setKltMaskBorder(const unsigned int &e)
virtual void setOgreShowConfigDialog(bool showConfigDialog)
virtual void getCameraParameters(vpCameraParameters &cam) const
virtual void setDisplayFeatures(bool displayF)
virtual void getPose(vpHomogeneousMatrix &cMo) const
virtual void setAngleDisappear(const double &a)
virtual void setCovarianceComputation(const bool &flag)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual vpMatrix getCovarianceMatrix() const
virtual void setNearClippingDistance(const double &dist)
virtual void setFarClippingDistance(const double &dist)
virtual void setClipping(const unsigned int &flags)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setAngleAppear(const double &a)
virtual unsigned int getClipping() const
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 acquire(vpImage< vpRGBa > &I)
void setLastFrameIndex(const long last_frame)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
long getFirstFrameIndex()
long getFrameIndex() const