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"
94 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
95 unsigned first,
unsigned nimages,
unsigned step, vpDisplayType &dtype);
96 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
97 unsigned &first,
unsigned &nimages,
unsigned &step,
98 vpDisplayType &dtype,
bool &list,
bool &display,
bool &click,
bool &wait);
114 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
115 unsigned first,
unsigned nimages,
unsigned step, vpDisplayType &dtype)
118 Read an image sequence from the disk and display it.\n\
119 The sequence is made of separate images. Each image corresponds\n\
123 %s [-i <test image path>] [-p <personal image path>]\n\
124 [-f <first image>] [-n <number of images>] [-s <step>] \n\
125 [-t <type of video device>] [-l] [-w] [-c] [-d] [-h]\n \
130 case vpX11: display =
"X11";
break;
131 case vpGTK: display =
"GTK";
break;
132 case vpGDI: display =
"GDI";
break;
133 case vpD3D: display =
"D3D";
break;
138 -i <test image path> %s\n\
139 Set image input path.\n\
140 From this path read \"ViSP-images/cube/image.%%04d.pgm\"\n\
141 images. These images come from ViSP-images-x.y.z.tar.gz\n\
142 available on the ViSP website.\n\
143 Setting the VISP_INPUT_IMAGE_PATH environment\n\
144 variable produces the same behaviour than using\n\
147 -p <personal image path> %s\n\
148 Specify a personal sequence containing images \n\
150 By image sequence, we mean one file per image.\n\
151 The following image file formats PNM (PGM P5, PPM P6)\n\
152 are supported. The format is selected by analysing \n\
153 the filename extension.\n\
154 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
155 %%04d is for the image numbering.\n\
157 -f <first image> %u\n\
158 First image number of the sequence.\n\
160 -n <number of images> %u\n\
161 Number of images to load from the sequence.\n\
164 Step between two images.\n\
166 -t <type of video device> \"%s\"\n\
167 String specifying the video device to use.\n\
169 \"X11\": only on UNIX platforms,\n\
170 \"GTK\": on all plaforms,\n\
171 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
172 \"D3D\": only on Windows platform (Direct3D).\n\
175 Print the list of video-devices available and exit.\n\
178 Disable mouse click.\n\
181 Disable the image display. This can be useful \n\
182 for automatic tests using crontab under Unix or \n\
183 using the task manager under Windows.\n\
186 Wait for a mouse click between two images.\n\
187 If the image display is disabled (using -d)\n\
188 this option is without effect.\n\
191 Print the help.\n\n",
192 ipath.c_str(),ppath.c_str(), first, nimages, step, display.c_str());
195 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
221 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
222 unsigned &first,
unsigned &nimages,
unsigned &step,
223 vpDisplayType &dtype,
bool &list,
bool &display,
bool &click,
bool &wait)
227 std::string sDisplayType;
231 case 'c': click =
false;
break;
232 case 'd': display =
false;
break;
233 case 't': sDisplayType = optarg_;
235 if (sDisplayType.compare(
"X11") == 0) {
238 else if (sDisplayType.compare(
"GTK") == 0) {
241 else if (sDisplayType.compare(
"GDI") == 0) {
244 else if (sDisplayType.compare(
"D3D") == 0) {
249 case 'i': ipath = optarg_;
break;
250 case 'l': list =
true;
break;
251 case 'p': ppath = optarg_;
break;
252 case 'f': first = (unsigned) atoi(optarg_);
break;
253 case 'n': nimages = (unsigned) atoi(optarg_);
break;
254 case 's': step = (unsigned) atoi(optarg_);
break;
255 case 'w': wait =
true;
break;
256 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step, dtype);
260 usage(argv[0], optarg_, ipath, ppath, first, nimages, step, dtype);
265 if ((c == 1) || (c == -1)) {
267 usage(argv[0], NULL, ipath, ppath, first, nimages, step, dtype);
268 std::cerr <<
"ERROR: " << std::endl;
269 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
277 main(
int argc,
const char ** argv)
279 std::string env_ipath;
280 std::string opt_ipath;
282 std::string opt_ppath;
284 std::string filename;
285 unsigned opt_first = 30;
286 unsigned opt_nimages = 10;
287 unsigned opt_step = 1;
288 vpDisplayType opt_dtype;
289 bool opt_list =
false;
290 bool opt_display =
true;
291 bool opt_click =
true;
292 bool opt_click_blocking =
false;
295 #if defined VISP_HAVE_GTK
297 #elif defined VISP_HAVE_X11
299 #elif defined VISP_HAVE_GDI
301 #elif defined VISP_HAVE_D3D9
309 if (! env_ipath.empty())
313 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
314 opt_step, opt_dtype, opt_list, opt_display, opt_click,
315 opt_click_blocking) ==
false) {
320 unsigned nbDevices = 0;
321 std::cout <<
"List of video-devices available: \n";
322 #if defined VISP_HAVE_GTK
323 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
326 #if defined VISP_HAVE_X11
327 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
330 #if defined VISP_HAVE_GDI
331 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
334 #if defined VISP_HAVE_D3D9
335 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
339 std::cout <<
" No display is available\n";
345 opt_click_blocking =
false;
348 if (!opt_ipath.empty())
353 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
354 if (ipath != env_ipath) {
355 std::cout << std::endl
356 <<
"WARNING: " << std::endl;
357 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
358 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
359 <<
" we skip the environment variable." << std::endl;
364 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
365 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step,opt_dtype);
366 std::cerr << std::endl
367 <<
"ERROR:" << std::endl;
368 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
370 <<
" environment variable to specify the location of the " << std::endl
371 <<
" image path where test images are located." << std::endl
372 <<
" Use -p <personal image path> option if you want to "<<std::endl
373 <<
" use personal images." << std::endl
384 unsigned iter = opt_first;
385 std::ostringstream s;
386 char cfilename[FILENAME_MAX];
388 if (opt_ppath.empty()){
408 s.setf(std::ios::right, std::ios::adjustfield);
409 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
414 sprintf(cfilename,opt_ppath.c_str(), iter) ;
415 filename = cfilename;
432 std::cerr << std::endl
433 <<
"ERROR:" << std::endl;
434 std::cerr <<
" Cannot read " << filename << std::endl;
435 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
436 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
437 <<
" or VISP_INPUT_IMAGE_PATH environment variable"
446 std::cout <<
"Requested X11 display functionnalities..." << std::endl;
447 #if defined VISP_HAVE_X11
450 std::cout <<
" Sorry, X11 video device is not available.\n";
451 std::cout <<
"Use \"" << argv[0]
452 <<
" -l\" to print the list of available devices.\n";
457 std::cout <<
"Requested GTK display functionnalities..." << std::endl;
458 #if defined VISP_HAVE_GTK
461 std::cout <<
" Sorry, GTK video device is not available.\n";
462 std::cout <<
"Use \"" << argv[0]
463 <<
" -l\" to print the list of available devices.\n";
468 std::cout <<
"Requested GDI display functionnalities..." << std::endl;
469 #if defined VISP_HAVE_GDI
472 std::cout <<
" Sorry, GDI video device is not available.\n";
473 std::cout <<
"Use \"" << argv[0]
474 <<
" -l\" to print the list of available devices.\n";
479 std::cout <<
"Requested D3D display functionnalities..." << std::endl;
480 #if defined VISP_HAVE_D3D9
483 std::cout <<
" Sorry, D3D video device is not available.\n";
484 std::cout <<
"Use \"" << argv[0]
485 <<
" -l\" to print the list of available devices.\n";
495 display->
init(I, 100, 100,
"Display...") ;
515 while (iter < opt_first + opt_nimages*opt_step) {
521 if (opt_ppath.empty()){
523 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
527 sprintf(cfilename, opt_ppath.c_str(), iter) ;
528 filename = cfilename;
531 std::cout <<
"read : " << filename << std::endl;
540 if (opt_click_blocking) {
541 std::cout <<
"A click in the image to continue..." << std::endl;
551 std::cout <<
"Left button was pressed." << std::endl;
554 std::cout <<
"Middle button was pressed." << std::endl;
557 std::cout <<
"Right button was pressed. Bye. " << std::endl;
590 vpERROR_TRACE(
"You do not have X11 or GTK display functionalities...");
virtual void init(vpImage< unsigned char > &I, int x=-1, int y=-1, const char *title=NULL)=0
Class that defines generic functionnalities for display.
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
static double measureTimeMs()
static int wait(double t0, double t)
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Display for windows using Direct3D.
static void display(const vpImage< unsigned char > &I)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static void read(vpImage< unsigned char > &I, const char *filename)