66 #include <visp/vpDebug.h>
67 #include <visp/vpConfig.h>
72 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
74 #include <visp/vpImage.h>
75 #include <visp/vpImageIo.h>
76 #include <visp/vpImagePoint.h>
78 #include <visp/vpDisplayX.h>
79 #include <visp/vpDisplayGTK.h>
80 #include <visp/vpDisplayGDI.h>
82 #include <visp/vpPose.h>
83 #include <visp/vpDot.h>
84 #include <visp/vpPixelMeterConversion.h>
85 #include <visp/vpParseArgv.h>
86 #include <visp/vpIoTools.h>
90 #define GETOPTARGS "cdi:p:hf:n:s:"
105 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
106 unsigned first,
unsigned nimages,
unsigned step)
109 Test dot tracking.\n\
112 %s [-i <input image path>] [-p <personal image path>]\n\
113 [-f <first image>] [-n <number of images>] [-s <step>][-c] [-d] [-h]\n", name);
117 -i <input image path> %s\n\
118 Set image input path.\n\
119 From this path read images \n\
120 \"ViSP-images/cube/image.%%04d.pgm\"\n\
121 Setting the VISP_INPUT_IMAGE_PATH environment\n\
122 variable produces the same behaviour than using\n\
125 -p <personal image path> %s\n\
126 Specify a personal sequence containing images \n\
128 By image sequence, we mean one file per image.\n\
129 The following image file formats PNM (PGM P5, PPM P6)\n\
130 are supported. The format is selected by analysing \n\
131 the filename extension.\n\
132 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
133 %%04d is for the image numbering.\n\
135 -f <first image> %u\n\
136 First image number of the sequence.\n\
138 -n <number of images> %u\n\
139 Number of images to load from the sequence.\n\
142 Step between two images.\n\
145 Disable the mouse click. Useful to automaze the \n\
146 execution of this program without humain intervention.\n\
149 Turn off the display.\n\
153 ipath.c_str(),ppath.c_str(), first, nimages, step);
156 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
178 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
179 unsigned &first,
unsigned &nimages,
unsigned &step,
180 bool &click_allowed,
bool &display)
187 case 'c': click_allowed =
false;
break;
188 case 'd': display =
false;
break;
189 case 'i': ipath = optarg;
break;
190 case 'p': ppath = optarg;
break;
191 case 'f': first = (unsigned) atoi(optarg);
break;
192 case 'n': nimages = (unsigned) atoi(optarg);
break;
193 case 's': step = (unsigned) atoi(optarg);
break;
194 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step);
return false;
break;
197 usage(argv[0], optarg, ipath, ppath, first, nimages, step);
202 if ((c == 1) || (c == -1)) {
204 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
205 std::cerr <<
"ERROR: " << std::endl;
206 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
217 main(
int argc,
const char** argv)
219 std::string env_ipath;
220 std::string opt_ipath;
222 std::string opt_ppath;
224 std::string filename;
225 unsigned opt_first = 0;
226 unsigned opt_nimages = 80;
227 unsigned opt_step = 1;
228 bool opt_click_allowed =
true;
229 bool opt_display =
true;
234 std::cout <<
"-------------------------------------------------------" << std::endl ;
235 std::cout <<
" poseVirtualVS.cpp" <<std::endl << std::endl ;
237 std::cout <<
" Example of dots tracking in an image sequence and pose computation" << std::endl ;
238 std::cout <<
"-------------------------------------------------------" << std::endl ;
239 std::cout << std::endl ;
242 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
247 if (! env_ipath.empty())
252 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_click_allowed, opt_display) ==
false) {
257 if (!opt_ipath.empty())
262 if (opt_ipath.empty() && opt_ppath.empty()) {
263 if (ipath != env_ipath) {
264 std::cout << std::endl
265 <<
"WARNING: " << std::endl;
266 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
267 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
268 <<
" we skip the environment variable." << std::endl;
272 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()){
273 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
274 std::cerr << std::endl
275 <<
"ERROR:" << std::endl;
276 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
278 <<
" environment variable to specify the location of the " << std::endl
279 <<
" image path where test images are located." << std::endl
280 <<
" Use -p <personal image path> option if you want to "<< std::endl
281 <<
" use personal images" <<std::endl << std::endl;
293 unsigned iter = opt_first ;
294 std::ostringstream s;
295 char cfilename[FILENAME_MAX];
297 if (opt_ppath.empty()){
316 s.setf(std::ios::right, std::ios::adjustfield);
317 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
318 filename = dirname + s.str();
322 sprintf(cfilename, opt_ppath.c_str(), iter) ;
323 filename = cfilename;
329 for (i=0 ; i < 4 ; i++)
359 if (opt_ppath.empty()) {
360 std::cerr << std::endl
361 <<
"ERROR:" << std::endl;
362 std::cerr <<
" Cannot read " << filename << std::endl;
363 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
364 <<
" or VISP_INPUT_IMAGE_PATH environment variable"
368 std::cerr << std::endl
369 <<
"ERROR:" << std::endl;
370 std::cerr <<
" Cannot read " << filename << std::endl;
371 std::cerr <<
" or your -p " << opt_ppath <<
" option " <<std::endl
381 #if defined VISP_HAVE_X11
383 #elif defined VISP_HAVE_GTK
385 #elif defined VISP_HAVE_GDI
391 display.
init(I,100,100,
"tracking using vpDot");
411 if (opt_display && opt_click_allowed) {
413 std::cout <<
"Click the four white dots on the object corner clockwise"
415 for (i=0 ; i < 4 ; i++)
434 d[i].
track(I, cog[i]) ;
442 d[0].
track(I, cog[0]);
448 d[1].
track(I, cog[1]);
454 d[2].
track(I, cog[2]);
460 d[3].
track(I, cog[3]);
487 for (i=0 ; i < 4 ; i++)
529 for (i=0 ; i < 4 ; i++)
545 for (i=0 ; i < 4 ; i++)
570 while (iter < opt_nimages)
575 if (opt_ppath.empty()){
577 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
578 filename = dirname + s.str();
581 sprintf( cfilename, opt_ppath.c_str(), iter) ;
582 filename = cfilename ;
598 for (i=0 ; i < 4 ; i++)
601 d[i].
track(I, cog[i]) ;
649 vpERROR_TRACE(
"You do not have X11 or GTK functionalities to display images...");