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/vpMbKltTracker.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:dchtfo"
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]",
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\
106 -n <initialisation file base name> \n\
107 Base name of the initialisation file. The file will be 'base_name'.init .\n\
108 This base name is also used for the optionnal picture specifying where to \n\
109 click (a .ppm picture).\
112 Turn off the display of the the klt points. \n\
115 Turn off the display.\n\
118 Disable the mouse click. Useful to automaze the \n\
119 execution of this program without humain intervention.\n\
122 Use Ogre3D for visibility tests\n\
125 Print the help.\n\n");
128 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
132 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile, std::string &initFile,
bool &displayKltPoints,
bool &click_allowed,
bool &display,
bool& cao3DModel,
bool &useOgre)
139 case 'i': ipath = optarg;
break;
140 case 'x': configFile = optarg;
break;
141 case 'm': modelFile = optarg;
break;
142 case 'n': initFile = optarg;
break;
143 case 't': displayKltPoints =
false;
break;
144 case 'f': cao3DModel =
true;
break;
145 case 'c': click_allowed =
false;
break;
146 case 'd': display =
false;
break;
147 case 'o' : useOgre =
true;
break;
148 case 'h': usage(argv[0], NULL);
return false;
break;
151 usage(argv[0], optarg);
156 if ((c == 1) || (c == -1)) {
158 usage(argv[0], NULL);
159 std::cerr <<
"ERROR: " << std::endl;
160 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
168 main(
int argc,
const char ** argv)
170 std::string env_ipath;
171 std::string opt_ipath;
173 std::string opt_configFile;
174 std::string configFile;
175 std::string opt_modelFile;
176 std::string modelFile;
177 std::string opt_initFile;
178 std::string initFile;
179 bool displayKltPoints =
true;
180 bool opt_click_allowed =
true;
181 bool opt_display =
true;
182 bool cao3DModel =
false;
183 bool useOgre =
false;
186 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
191 if (! env_ipath.empty())
196 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayKltPoints, opt_click_allowed, opt_display, cao3DModel, useOgre)) {
201 if (opt_ipath.empty() && env_ipath.empty() ){
202 usage(argv[0], NULL);
203 std::cerr << std::endl
204 <<
"ERROR:" << std::endl;
205 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
207 <<
" environment variable to specify the location of the " << std::endl
208 <<
" image path where test images are located." << std::endl
215 if (!opt_ipath.empty())
216 ipath = opt_ipath +
vpIoTools::path(
"/ViSP-images/mbt/cube/image%04d.pgm");
218 ipath = env_ipath +
vpIoTools::path(
"/ViSP-images/mbt/cube/image%04d.pgm");
220 if (!opt_configFile.empty())
221 configFile = opt_configFile;
222 else if (!opt_ipath.empty())
227 if (!opt_modelFile.empty()){
228 modelFile = opt_modelFile;
230 std::string modelFileCao =
"/ViSP-images/mbt/cube.cao";
231 std::string modelFileWrl =
"/ViSP-images/mbt/cube.wrl";
233 if(!opt_ipath.empty()){
238 #ifdef VISP_HAVE_COIN
241 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
251 #ifdef VISP_HAVE_COIN
254 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
261 if (!opt_initFile.empty())
262 initFile = opt_initFile;
263 else if (!opt_ipath.empty())
275 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
282 #if defined VISP_HAVE_X11
284 #elif defined VISP_HAVE_GDI
286 #elif defined VISP_HAVE_OPENCV
288 #elif defined VISP_HAVE_D3D9
290 #elif defined VISP_HAVE_GTK
297 #if (defined VISP_HAVE_DISPLAY)
298 display.
init(I, 100, 100,
"Test tracking") ;
309 #if defined (VISP_HAVE_XML2)
348 if (opt_display && opt_click_allowed)
353 "click after positioning the object",
371 if (opt_display && opt_click_allowed)
373 tracker.
initClick(I, initFile.c_str(),
true);
380 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
394 while (!reader.
end())
421 std::cout <<
"error caught" << std::endl;
428 #if defined (VISP_HAVE_XML2)
433 #ifdef VISP_HAVE_COIN
445 std::cout <<
"OpenCV and display are required." << std::endl;