48 #include <visp/vpConfig.h>
49 #include <visp/vpDebug.h>
50 #include <visp/vpDisplayD3D.h>
51 #include <visp/vpDisplayGTK.h>
52 #include <visp/vpDisplayGDI.h>
53 #include <visp/vpDisplayOpenCV.h>
54 #include <visp/vpDisplayX.h>
55 #include <visp/vpHomogeneousMatrix.h>
56 #include <visp/vpImageIo.h>
57 #include <visp/vpIoTools.h>
58 #include <visp/vpMath.h>
59 #include <visp/vpMbEdgeKltTracker.h>
60 #include <visp/vpVideoReader.h>
61 #include <visp/vpParseArgv.h>
63 #if defined (VISP_HAVE_OPENCV) && defined (VISP_HAVE_DISPLAY)
66 #define GETOPTARGS "x:m:i:n:dchtfCo"
69 void usage(
const char *name,
const char *badparam)
72 Example of tracking based on the 3D model.\n\
75 %s [-i <test image path>] [-x <config file>]\n\
76 [-m <model name>] [-n <initialisation file base name>]\n\
77 [-t] [-c] [-d] [-h] [-f] [-C]",
82 -i <input image path> \n\
83 Set image input path.\n\
84 From this path read images \n\
85 \"ViSP-images/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 behaviour 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\
101 Do not use the vrml model, use the .cao one. These two models are \n\
102 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
103 website. However, the .cao model allows to use the 3d model based tracker \n\
107 Track only the cube (not the cylinder). In this case the models files are\n\
108 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
109 cube_and_cylinder.wrl.\n\
111 -n <initialisation file base name> \n\
112 Base name of the initialisation file. The file will be 'base_name'.init .\n\
113 This base name is also used for the optionnal picture specifying where to \n\
114 click (a .ppm picture).\
117 Turn off the display of the the moving edges and Klt points. \n\
120 Turn off the display.\n\
123 Disable the mouse click. Useful to automaze the \n\
124 execution of this program without humain intervention.\n\
127 Use Ogre3D for visibility tests\n\
130 Print the help.\n\n");
133 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
137 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile, std::string &initFile,
bool &displayFeatures,
bool &click_allowed,
bool &display,
bool& cao3DModel,
bool& trackCylinder,
bool &useOgre)
144 case 'i': ipath = optarg;
break;
145 case 'x': configFile = optarg;
break;
146 case 'm': modelFile = optarg;
break;
147 case 'n': initFile = optarg;
break;
148 case 't': displayFeatures =
false;
break;
149 case 'f': cao3DModel =
true;
break;
150 case 'c': click_allowed =
false;
break;
151 case 'd': display =
false;
break;
152 case 'C': trackCylinder =
false;
break;
153 case 'o' : useOgre =
true;
break;
154 case 'h': usage(argv[0], NULL);
return false;
break;
157 usage(argv[0], optarg);
162 if ((c == 1) || (c == -1)) {
164 usage(argv[0], NULL);
165 std::cerr <<
"ERROR: " << std::endl;
166 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
174 main(
int argc,
const char ** argv)
176 std::string env_ipath;
177 std::string opt_ipath;
179 std::string opt_configFile;
180 std::string configFile;
181 std::string opt_modelFile;
182 std::string modelFile;
183 std::string opt_initFile;
184 std::string initFile;
185 bool displayFeatures =
true;
186 bool opt_click_allowed =
true;
187 bool opt_display =
true;
188 bool cao3DModel =
false;
189 bool trackCylinder =
true;
190 bool useOgre =
false;
193 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
198 if (! env_ipath.empty())
203 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayFeatures, opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre)) {
208 if (opt_ipath.empty() && env_ipath.empty() ){
209 usage(argv[0], NULL);
210 std::cerr << std::endl
211 <<
"ERROR:" << std::endl;
212 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
214 <<
" environment variable to specify the location of the " << std::endl
215 <<
" image path where test images are located." << std::endl
222 if (!opt_ipath.empty())
223 ipath = opt_ipath +
vpIoTools::path(
"/ViSP-images/mbt/cube/image%04d.pgm");
225 ipath = env_ipath +
vpIoTools::path(
"/ViSP-images/mbt/cube/image%04d.pgm");
227 if (!opt_configFile.empty())
228 configFile = opt_configFile;
229 else if (!opt_ipath.empty())
234 if (!opt_modelFile.empty()){
235 modelFile = opt_modelFile;
237 std::string modelFileCao;
238 std::string modelFileWrl;
240 modelFileCao =
"/ViSP-images/mbt/cube_and_cylinder.cao";
241 modelFileWrl =
"/ViSP-images/mbt/cube_and_cylinder.wrl";
243 modelFileCao =
"/ViSP-images/mbt/cube.cao";
244 modelFileWrl =
"/ViSP-images/mbt/cube.wrl";
247 if(!opt_ipath.empty()){
252 #ifdef VISP_HAVE_COIN
255 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
265 #ifdef VISP_HAVE_COIN
268 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
275 if (!opt_initFile.empty())
276 initFile = opt_initFile;
277 else if (!opt_ipath.empty())
289 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
296 #if defined VISP_HAVE_X11
298 #elif defined VISP_HAVE_GDI
300 #elif defined VISP_HAVE_OPENCV
302 #elif defined VISP_HAVE_D3D9
304 #elif defined VISP_HAVE_GTK
311 #if (defined VISP_HAVE_DISPLAY)
312 display.
init(I, 100, 100,
"Test tracking") ;
323 #if defined (VISP_HAVE_XML2)
373 if (opt_display && opt_click_allowed)
378 "click after positioning the object",
396 if (opt_display && opt_click_allowed)
398 tracker.
initClick(I, initFile.c_str(),
true);
405 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
419 while (!reader.
end())
446 std::cout <<
"error caught" << std::endl;
453 #if defined (VISP_HAVE_XML2)
458 #ifdef VISP_HAVE_COIN
470 std::cout <<
"OpenCV and display are required." << std::endl;
void setKltOpencv(const vpKltOpencv &t)
void setMovingEdge(const vpMe &me)
void setQuality(double input)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void setMaskNumber(const unsigned int &a)
static const vpColor darkRed
Display for windows using GDI (available on any windows 32 platform).
void setMu2(const double &mu2)
void setNbTotalSample(const int &nb)
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 init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Contains predetermined masks for sites and holds moving edges tracking parameters.
void setPyramidLevels(const int input)
virtual void setClipping(const unsigned int &flags)
void setBlockSize(const int input)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
static void flush(const vpImage< unsigned char > &I)
virtual void setFarClippingDistance(const double &dist)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
void open(vpImage< vpRGBa > &I)
virtual void setOgreVisibilityTest(const bool &v)
Display for windows using Direct3D.
void setMaskSize(const unsigned int &a)
void setWindowSize(const int input)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void track(const vpImage< unsigned char > &I)
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)
Generic class defining intrinsic camera parameters.
virtual void setAngleAppear(const double &a)
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 setAngleDisappear(const double &a)
void loadConfigFile(const char *configFile)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, const bool displayHelp=false)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness=1)
static double rad(double deg)
virtual void setCameraParameters(const vpCameraParameters &cam)
virtual void getCameraParameters(vpCameraParameters &cam) const
Hybrid tracker based on moving-edges and keypoints tracked using KLT tracker.
virtual unsigned int getClipping() const
void setMaskBorder(const unsigned int &e)
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV.
void setThreshold(const double &t)
virtual bool getClick(bool blocking=true)=0
void setDisplayFeatures(const bool displayF)
void setRange(const unsigned int &r)
void setMaxFeatures(const int input)
void getPose(vpHomogeneousMatrix &cMo) const
void setMinDistance(double input)
void setMinSampleStep(const double &min)
void setMu1(const double &mu1)
virtual void loadModel(const std::string &modelFile)
static const vpColor blue
void setHarrisFreeParameter(double input)
virtual void setNearClippingDistance(const double &dist)