52 #include <visp/vpDebug.h>
53 #include <visp/vpConfig.h>
54 #include <visp/vpParseArgv.h>
55 #include <visp/vpIoTools.h>
62 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9))
64 #include <visp/vpImage.h>
65 #include <visp/vpImageIo.h>
67 #include <visp/vpDisplayGTK.h>
68 #include <visp/vpDisplayX.h>
69 #include <visp/vpDisplayGDI.h>
70 #include <visp/vpDisplayD3D.h>
71 #include <visp/vpMouseButton.h>
73 #include <visp/vpTime.h>
86 #define GETOPTARGS "cdi:lp:ht:f:n:s:w"
108 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
109 unsigned first,
unsigned nimages,
unsigned step,
110 vpDisplayType &dtype)
113 Read an image sequence from the disk and display it.\n\
114 The sequence is made of separate images. Each image corresponds\n\
118 %s [-i <test image path>] [-p <personal image path>]\n\
119 [-f <first image>] [-n <number of images>] [-s <step>] \n\
120 [-t <type of video device>] [-l] [-w] [-c] [-d] [-h]\n \
125 case vpX11: display =
"X11";
break;
126 case vpGTK: display =
"GTK";
break;
127 case vpGDI: display =
"GDI";
break;
128 case vpD3D: display =
"D3D";
break;
133 -i <test image path> %s\n\
134 Set image input path.\n\
135 From this path read \"ViSP-images/cube/image.%%04d.pgm\"\n\
136 images. These images come from ViSP-images-x.y.z.tar.gz\n\
137 available on the ViSP website.\n\
138 Setting the VISP_INPUT_IMAGE_PATH environment\n\
139 variable produces the same behaviour than using\n\
142 -p <personal image path> %s\n\
143 Specify a personal sequence containing images \n\
145 By image sequence, we mean one file per image.\n\
146 The following image file formats PNM (PGM P5, PPM P6)\n\
147 are supported. The format is selected by analysing \n\
148 the filename extension.\n\
149 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
150 %%04d is for the image numbering.\n\
152 -f <first image> %u\n\
153 First image number of the sequence.\n\
155 -n <number of images> %u\n\
156 Number of images to load from the sequence.\n\
159 Step between two images.\n\
161 -t <type of video device> \"%s\"\n\
162 String specifying the video device to use.\n\
164 \"X11\": only on UNIX platforms,\n\
165 \"GTK\": on all plaforms,\n\
166 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
167 \"D3D\": only on Windows platform (Direct3D).\n\
170 Print the list of video-devices available and exit.\n\
173 Disable mouse click.\n\
176 Disable the image display. This can be useful \n\
177 for automatic tests using crontab under Unix or \n\
178 using the task manager under Windows.\n\
181 Wait for a mouse click between two images.\n\
182 If the image display is disabled (using -d)\n\
183 this option is without effect.\n\
186 Print the help.\n\n",
187 ipath.c_str(),ppath.c_str(), first, nimages, step, display.c_str());
190 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
216 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
217 unsigned &first,
unsigned &nimages,
unsigned &step,
218 vpDisplayType &dtype,
bool &list,
bool &display,
bool &click,
bool &wait)
222 std::string sDisplayType;
226 case 'c': click =
false;
break;
227 case 'd': display =
false;
break;
228 case 't': sDisplayType = optarg;
230 if (sDisplayType.compare(
"X11") == 0) {
233 else if (sDisplayType.compare(
"GTK") == 0) {
236 else if (sDisplayType.compare(
"GDI") == 0) {
239 else if (sDisplayType.compare(
"D3D") == 0) {
244 case 'i': ipath = optarg;
break;
245 case 'l': list =
true;
break;
246 case 'p': ppath = optarg;
break;
247 case 'f': first = (unsigned) atoi(optarg);
break;
248 case 'n': nimages = (unsigned) atoi(optarg);
break;
249 case 's': step = (unsigned) atoi(optarg);
break;
250 case 'w': wait =
true;
break;
251 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step, dtype);
255 usage(argv[0], optarg, ipath, ppath, first, nimages, step, dtype);
260 if ((c == 1) || (c == -1)) {
262 usage(argv[0], NULL, ipath, ppath, first, nimages, step, dtype);
263 std::cerr <<
"ERROR: " << std::endl;
264 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
272 main(
int argc,
const char ** argv)
274 std::string env_ipath;
275 std::string opt_ipath;
277 std::string opt_ppath;
279 std::string filename;
280 unsigned opt_first = 30;
281 unsigned opt_nimages = 10;
282 unsigned opt_step = 1;
283 vpDisplayType opt_dtype;
284 bool opt_list =
false;
285 bool opt_display =
true;
286 bool opt_click =
true;
287 bool opt_click_blocking =
false;
290 #if defined VISP_HAVE_GTK
292 #elif defined VISP_HAVE_X11
294 #elif defined VISP_HAVE_GDI
296 #elif defined VISP_HAVE_D3D9
301 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
306 if (! env_ipath.empty())
310 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
311 opt_step, opt_dtype, opt_list, opt_display, opt_click,
312 opt_click_blocking) ==
false) {
317 unsigned nbDevices = 0;
318 std::cout <<
"List of video-devices available: \n";
319 #if defined VISP_HAVE_GTK
320 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
323 #if defined VISP_HAVE_X11
324 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
327 #if defined VISP_HAVE_GDI
328 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
331 #if defined VISP_HAVE_D3D9
332 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
336 std::cout <<
" No display is available\n";
342 opt_click_blocking =
false;
345 if (!opt_ipath.empty())
350 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
351 if (ipath != env_ipath) {
352 std::cout << std::endl
353 <<
"WARNING: " << std::endl;
354 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
355 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
356 <<
" we skip the environment variable." << std::endl;
361 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
362 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step,opt_dtype);
363 std::cerr << std::endl
364 <<
"ERROR:" << std::endl;
365 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
367 <<
" environment variable to specify the location of the " << std::endl
368 <<
" image path where test images are located." << std::endl
369 <<
" Use -p <personal image path> option if you want to "<<std::endl
370 <<
" use personal images." << std::endl
381 unsigned iter = opt_first;
382 std::ostringstream s;
383 char cfilename[FILENAME_MAX];
385 if (opt_ppath.empty()){
405 s.setf(std::ios::right, std::ios::adjustfield);
406 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
407 filename = dirname + s.str();
411 sprintf(cfilename,opt_ppath.c_str(), iter) ;
412 filename = cfilename;
429 std::cerr << std::endl
430 <<
"ERROR:" << std::endl;
431 std::cerr <<
" Cannot read " << filename << std::endl;
432 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
433 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
434 <<
" or VISP_INPUT_IMAGE_PATH environment variable"
443 std::cout <<
"Requested X11 display functionnalities..." << std::endl;
444 #if defined VISP_HAVE_X11
447 std::cout <<
" Sorry, X11 video device is not available.\n";
448 std::cout <<
"Use \"" << argv[0]
449 <<
" -l\" to print the list of available devices.\n";
454 std::cout <<
"Requested GTK display functionnalities..." << std::endl;
455 #if defined VISP_HAVE_GTK
458 std::cout <<
" Sorry, GTK video device is not available.\n";
459 std::cout <<
"Use \"" << argv[0]
460 <<
" -l\" to print the list of available devices.\n";
465 std::cout <<
"Requested GDI display functionnalities..." << std::endl;
466 #if defined VISP_HAVE_GDI
469 std::cout <<
" Sorry, GDI video device is not available.\n";
470 std::cout <<
"Use \"" << argv[0]
471 <<
" -l\" to print the list of available devices.\n";
476 std::cout <<
"Requested D3D display functionnalities..." << std::endl;
477 #if defined VISP_HAVE_D3D9
480 std::cout <<
" Sorry, D3D video device is not available.\n";
481 std::cout <<
"Use \"" << argv[0]
482 <<
" -l\" to print the list of available devices.\n";
492 display->
init(I, 100, 100,
"Display...") ;
512 while (iter < opt_first + opt_nimages*opt_step) {
518 if (opt_ppath.empty()){
520 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
521 filename = dirname + s.str();
524 sprintf(cfilename, opt_ppath.c_str(), iter) ;
525 filename = cfilename;
528 std::cout <<
"read : " << filename << std::endl;
537 if (opt_click_blocking) {
538 std::cout <<
"A click in the image to continue..." << std::endl;
548 std::cout <<
"Left button was pressed." << std::endl;
551 std::cout <<
"Middle button was pressed." << std::endl;
554 std::cout <<
"Right button was pressed. Bye. " << std::endl;
586 vpERROR_TRACE(
"You do not have X11 or GTK display functionalities...");