45 #include <visp3/core/vpConfig.h>
47 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(VISP_HAVE_DISPLAY) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
49 #include <visp3/core/vpDebug.h>
50 #include <visp3/gui/vpDisplayD3D.h>
51 #include <visp3/gui/vpDisplayGTK.h>
52 #include <visp3/gui/vpDisplayGDI.h>
53 #include <visp3/gui/vpDisplayOpenCV.h>
54 #include <visp3/gui/vpDisplayX.h>
55 #include <visp3/core/vpHomogeneousMatrix.h>
56 #include <visp3/io/vpImageIo.h>
57 #include <visp3/core/vpIoTools.h>
58 #include <visp3/core/vpMath.h>
59 #include <visp3/io/vpVideoReader.h>
60 #include <visp3/io/vpParseArgv.h>
61 #include <visp3/mbt/vpMbKltTracker.h>
63 #define GETOPTARGS "x:m:i:n:dchtfolw"
65 void usage(
const char *name,
const char *badparam);
66 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
67 std::string &initFile,
bool &displayKltPoints,
bool &click_allowed,
bool &display,
68 bool& cao3DModel,
bool &useOgre);
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>]\n\
78 [-t] [-c] [-d] [-h] [-f] [-o] [-w] [-l]",
83 -i <input image path> \n\
84 Set image input path.\n\
85 From this path read images \n\
86 \"ViSP-images/mbt/cube/image%%04d.ppm\". These \n\
87 images come from ViSP-images-x.y.z.tar.gz available \n\
88 on the ViSP website.\n\
89 Setting the VISP_INPUT_IMAGE_PATH environment\n\
90 variable produces the same behaviour than using\n\
94 Set the config file (the xml file) to use.\n\
95 The config file is used to specify the parameters of the tracker.\n\
98 Specify the name of the file of the model\n\
99 The model can either be a vrml model (.wrl) or a .cao file.\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).\
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 Print the help.\n\n");
135 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
139 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
140 std::string &initFile,
bool &displayKltPoints,
bool &click_allowed,
bool &display,
141 bool& cao3DModel,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline)
148 case 'i': ipath = optarg_;
break;
149 case 'x': configFile = optarg_;
break;
150 case 'm': modelFile = optarg_;
break;
151 case 'n': initFile = optarg_;
break;
152 case 't': displayKltPoints =
false;
break;
153 case 'f': cao3DModel =
true;
break;
154 case 'c': click_allowed =
false;
break;
155 case 'd': display =
false;
break;
156 case 'o': useOgre =
true;
break;
157 case 'l': useScanline =
true;
break;
158 case 'w': showOgreConfigDialog =
true;
break;
159 case 'h': usage(argv[0], NULL);
return false;
break;
162 usage(argv[0], optarg_);
167 if ((c == 1) || (c == -1)) {
169 usage(argv[0], NULL);
170 std::cerr <<
"ERROR: " << std::endl;
171 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
179 main(
int argc,
const char ** argv)
182 std::string env_ipath;
183 std::string opt_ipath;
185 std::string opt_configFile;
186 std::string configFile;
187 std::string opt_modelFile;
188 std::string modelFile;
189 std::string opt_initFile;
190 std::string initFile;
191 bool displayKltPoints =
true;
192 bool opt_click_allowed =
true;
193 bool opt_display =
true;
194 bool cao3DModel =
false;
195 bool useOgre =
false;
196 bool showOgreConfigDialog =
false;
197 bool useScanline =
false;
204 if (! env_ipath.empty())
208 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayKltPoints,
209 opt_click_allowed, opt_display, cao3DModel, useOgre, showOgreConfigDialog, useScanline)) {
214 if (opt_ipath.empty() && env_ipath.empty() ){
215 usage(argv[0], NULL);
216 std::cerr << std::endl
217 <<
"ERROR:" << std::endl;
218 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
220 <<
" environment variable to specify the location of the " << std::endl
221 <<
" image path where test images are located." << std::endl
228 if (!opt_ipath.empty())
233 if (!opt_configFile.empty())
234 configFile = opt_configFile;
235 else if (!opt_ipath.empty())
240 if (!opt_modelFile.empty()){
241 modelFile = opt_modelFile;
243 std::string modelFileCao =
"ViSP-images/mbt/cube.cao";
244 std::string modelFileWrl =
"ViSP-images/mbt/cube.wrl";
246 if(!opt_ipath.empty()){
251 #ifdef VISP_HAVE_COIN3D
254 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
264 #ifdef VISP_HAVE_COIN3D
267 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
274 if (!opt_initFile.empty())
275 initFile = opt_initFile;
276 else if (!opt_ipath.empty())
288 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
295 #if defined VISP_HAVE_X11
297 #elif defined VISP_HAVE_GDI
299 #elif defined VISP_HAVE_OPENCV
301 #elif defined VISP_HAVE_D3D9
303 #elif defined VISP_HAVE_GTK
310 #if (defined VISP_HAVE_DISPLAY)
311 display.
init(I, 100, 100,
"Test tracking") ;
322 #if defined (VISP_HAVE_XML2)
366 if (opt_display && opt_click_allowed)
382 if (opt_display && opt_click_allowed)
391 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
405 while (!reader.
end())
419 #if defined (VISP_HAVE_XML2)
455 cMo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
482 if (opt_click_allowed) {
496 if (opt_click_allowed && !quit) {
502 #if defined (VISP_HAVE_XML2)
507 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION == 3)
517 std::cout <<
"Catch an exception: " << e << std::endl;
526 std::cout <<
"visp_mbt, visp_gui modules and OpenCV are required to run this example." << std::endl;
void setKltOpencv(const vpKltOpencv &t)
virtual void track(const vpImage< unsigned char > &I)
long getFrameIndex() const
virtual void setScanLineVisibilityTest(const bool &v)
long getFirstFrameIndex() const
void setHarrisFreeParameter(double harris_k)
virtual unsigned int getClipping() const
virtual void setAngleDisappear(const double &a)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static const vpColor darkRed
Display for windows using GDI (available on any windows 32 platform).
void setMaxFeatures(const int maxCount)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Define the X11 console to display images.
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void setMinDistance(double minDistance)
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
virtual void loadConfigFile(const std::string &configFile)
void setQuality(double qualityLevel)
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
void setOgreShowConfigDialog(const bool showConfigDialog)
void open(vpImage< vpRGBa > &I)
Display for windows using Direct3D.
void getPose(vpHomogeneousMatrix &cMo_) const
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void getCameraParameters(vpCameraParameters &camera) const
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
virtual void setAngleAppear(const double &a)
Model based tracker using only KLT.
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, const bool displayHelp=false)
void setPyramidLevels(const int pyrMaxLevel)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
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, vpImagePoint offset=vpImagePoint(0, 0))
void setWindowSize(const int winSize)
void setMaskBorder(const unsigned int &e)
virtual void loadModel(const char *modelFile, const bool verbose=false)
void setCameraParameters(const vpCameraParameters &cam)
virtual void setOgreVisibilityTest(const bool &v)
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV.
void setBlockSize(const int blockSize)
virtual void setClipping(const unsigned int &flags)
virtual bool getClick(bool blocking=true)=0
void setDisplayFeatures(const bool displayF)
virtual void setFarClippingDistance(const double &dist)
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
virtual void setNearClippingDistance(const double &dist)