50 #include <visp/vpConfig.h>
51 #include <visp/vpDebug.h>
52 #include <visp/vpDisplayD3D.h>
53 #include <visp/vpDisplayGTK.h>
54 #include <visp/vpDisplayGDI.h>
55 #include <visp/vpDisplayOpenCV.h>
56 #include <visp/vpDisplayX.h>
57 #include <visp/vpHomogeneousMatrix.h>
58 #include <visp/vpImageIo.h>
59 #include <visp/vpIoTools.h>
60 #include <visp/vpMath.h>
61 #include <visp/vpMbEdgeTracker.h>
62 #include <visp/vpVideoReader.h>
63 #include <visp/vpParseArgv.h>
65 #if defined (VISP_HAVE_DISPLAY)
67 #define GETOPTARGS "x:m:i:n:dchtfCo"
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] [-C]",
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\
108 Track only the cube (not the cylinder). In this case the models files are\n\
109 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
110 cube_and_cylinder.wrl.\n\
112 -n <initialisation file base name> \n\
113 Base name of the initialisation file. The file will be 'base_name'.init .\n\
114 This base name is also used for the optionnal picture specifying where to \n\
115 click (a .ppm picture).\
118 Turn off the display of the the moving edges. \n\
121 Turn off the display.\n\
124 Disable the mouse click. Useful to automaze the \n\
125 execution of this program without humain intervention.\n\
128 Use Ogre3D for visibility tests\n\
131 Print the help.\n\n");
134 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
138 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile, std::string &initFile,
bool &displayMovingEdge,
bool &click_allowed,
bool &display,
bool& cao3DModel,
bool& trackCylinder,
bool &useOgre)
145 case 'i': ipath = optarg;
break;
146 case 'x': configFile = optarg;
break;
147 case 'm': modelFile = optarg;
break;
148 case 'n': initFile = optarg;
break;
149 case 't': displayMovingEdge =
false;
break;
150 case 'f': cao3DModel =
true;
break;
151 case 'c': click_allowed =
false;
break;
152 case 'd': display =
false;
break;
153 case 'C': trackCylinder =
false;
break;
154 case 'o' : useOgre =
true;
break;
155 case 'h': usage(argv[0], NULL);
return false;
break;
158 usage(argv[0], optarg);
163 if ((c == 1) || (c == -1)) {
165 usage(argv[0], NULL);
166 std::cerr <<
"ERROR: " << std::endl;
167 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
175 main(
int argc,
const char ** argv)
177 std::string env_ipath;
178 std::string opt_ipath;
180 std::string opt_configFile;
181 std::string configFile;
182 std::string opt_modelFile;
183 std::string modelFile;
184 std::string opt_initFile;
185 std::string initFile;
186 bool displayMovingEdge =
true;
187 bool opt_click_allowed =
true;
188 bool opt_display =
true;
189 bool cao3DModel =
false;
190 bool trackCylinder =
true;
191 bool useOgre =
false;
194 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
199 if (! env_ipath.empty())
204 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayMovingEdge, opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre)) {
209 if (opt_ipath.empty() && env_ipath.empty() ){
210 usage(argv[0], NULL);
211 std::cerr << std::endl
212 <<
"ERROR:" << std::endl;
213 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
215 <<
" environment variable to specify the location of the " << std::endl
216 <<
" image path where test images are located." << std::endl
223 if (!opt_ipath.empty())
224 ipath = opt_ipath +
vpIoTools::path(
"/ViSP-images/mbt/cube/image%04d.pgm");
226 ipath = env_ipath +
vpIoTools::path(
"/ViSP-images/mbt/cube/image%04d.pgm");
228 if (!opt_configFile.empty())
229 configFile = opt_configFile;
230 else if (!opt_ipath.empty())
235 if (!opt_modelFile.empty()){
236 modelFile = opt_modelFile;
238 std::string modelFileCao;
239 std::string modelFileWrl;
241 modelFileCao =
"/ViSP-images/mbt/cube_and_cylinder.cao";
242 modelFileWrl =
"/ViSP-images/mbt/cube_and_cylinder.wrl";
244 modelFileCao =
"/ViSP-images/mbt/cube.cao";
245 modelFileWrl =
"/ViSP-images/mbt/cube.wrl";
248 if(!opt_ipath.empty()){
253 #ifdef VISP_HAVE_COIN
256 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
266 #ifdef VISP_HAVE_COIN
269 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
276 if (!opt_initFile.empty())
277 initFile = opt_initFile;
278 else if (!opt_ipath.empty())
290 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
297 #if defined VISP_HAVE_X11
299 #elif defined VISP_HAVE_GDI
301 #elif defined VISP_HAVE_OPENCV
303 #elif defined VISP_HAVE_D3D9
305 #elif defined VISP_HAVE_GTK
312 #if (defined VISP_HAVE_DISPLAY)
313 display.
init(I, 100, 100,
"Test tracking") ;
324 #if defined (VISP_HAVE_XML2)
361 if (opt_display && opt_click_allowed)
366 "click after positioning the object",
384 if (opt_display && opt_click_allowed)
386 tracker.
initClick(I, initFile.c_str(),
true);
393 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
407 while (!reader.
end())
434 std::cout <<
"error caught" << std::endl;
441 #if defined (VISP_HAVE_XML2)
446 #ifdef VISP_HAVE_COIN
458 std::cout <<
"Display is required to run this example." << std::endl;
void setDisplayMovingEdges(const bool displayMe)
void setMovingEdge(const vpMe &me)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void track(const vpImage< unsigned char > &I)
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.
Make the complete tracking of an object by using its CAD model.
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
void loadConfigFile(const std::string &configFile)
static void flush(const vpImage< unsigned char > &I)
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)
virtual void setNearClippingDistance(const double &dist)
void open(vpImage< vpRGBa > &I)
Display for windows using Direct3D.
void setMaskSize(const unsigned int &a)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void acquire(vpImage< vpRGBa > &I)
virtual void setFarClippingDistance(const double &dist)
void setFileName(const char *filename)
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)
virtual void setOgreVisibilityTest(const bool &v)
virtual void getCameraParameters(vpCameraParameters &cam) const
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
void setThreshold(const double &t)
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 unsigned int getClipping() const
virtual bool getClick(bool blocking=true)=0
virtual void setCameraParameters(const vpCameraParameters &cam)
void loadModel(const std::string &cad_name)
void setRange(const unsigned int &r)
virtual void setClipping(const unsigned int &flags)
void getPose(vpHomogeneousMatrix &cMo) const
void setMinSampleStep(const double &min)
void setMu1(const double &mu1)
static const vpColor blue