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
306 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
311 if (! env_ipath.empty())
315 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
316 opt_step, opt_dtype, opt_list, opt_display, opt_click,
317 opt_click_blocking) ==
false) {
322 unsigned nbDevices = 0;
323 std::cout <<
"List of video-devices available: \n";
324 #if defined VISP_HAVE_GTK
325 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
328 #if defined VISP_HAVE_X11
329 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
332 #if defined VISP_HAVE_GDI
333 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
336 #if defined VISP_HAVE_D3D9
337 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
341 std::cout <<
" No display is available\n";
347 opt_click_blocking =
false;
350 if (!opt_ipath.empty())
355 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
356 if (ipath != env_ipath) {
357 std::cout << std::endl
358 <<
"WARNING: " << std::endl;
359 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
360 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
361 <<
" we skip the environment variable." << std::endl;
366 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
367 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step,opt_dtype);
368 std::cerr << std::endl
369 <<
"ERROR:" << std::endl;
370 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
372 <<
" environment variable to specify the location of the " << std::endl
373 <<
" image path where test images are located." << std::endl
374 <<
" Use -p <personal image path> option if you want to "<<std::endl
375 <<
" use personal images." << std::endl
386 unsigned iter = opt_first;
387 std::ostringstream s;
388 char cfilename[FILENAME_MAX];
390 if (opt_ppath.empty()){
410 s.setf(std::ios::right, std::ios::adjustfield);
411 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
412 filename = dirname + s.str();
416 sprintf(cfilename,opt_ppath.c_str(), iter) ;
417 filename = cfilename;
434 std::cerr << std::endl
435 <<
"ERROR:" << std::endl;
436 std::cerr <<
" Cannot read " << filename << std::endl;
437 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
438 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
439 <<
" or VISP_INPUT_IMAGE_PATH environment variable"
448 std::cout <<
"Requested X11 display functionnalities..." << std::endl;
449 #if defined VISP_HAVE_X11
452 std::cout <<
" Sorry, X11 video device is not available.\n";
453 std::cout <<
"Use \"" << argv[0]
454 <<
" -l\" to print the list of available devices.\n";
459 std::cout <<
"Requested GTK display functionnalities..." << std::endl;
460 #if defined VISP_HAVE_GTK
463 std::cout <<
" Sorry, GTK video device is not available.\n";
464 std::cout <<
"Use \"" << argv[0]
465 <<
" -l\" to print the list of available devices.\n";
470 std::cout <<
"Requested GDI display functionnalities..." << std::endl;
471 #if defined VISP_HAVE_GDI
474 std::cout <<
" Sorry, GDI video device is not available.\n";
475 std::cout <<
"Use \"" << argv[0]
476 <<
" -l\" to print the list of available devices.\n";
481 std::cout <<
"Requested D3D display functionnalities..." << std::endl;
482 #if defined VISP_HAVE_D3D9
485 std::cout <<
" Sorry, D3D video device is not available.\n";
486 std::cout <<
"Use \"" << argv[0]
487 <<
" -l\" to print the list of available devices.\n";
497 display->
init(I, 100, 100,
"Display...") ;
517 while (iter < opt_first + opt_nimages*opt_step) {
523 if (opt_ppath.empty()){
525 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
526 filename = dirname + s.str();
529 sprintf(cfilename, opt_ppath.c_str(), iter) ;
530 filename = cfilename;
533 std::cout <<
"read : " << filename << std::endl;
542 if (opt_click_blocking) {
543 std::cout <<
"A click in the image to continue..." << std::endl;
553 std::cout <<
"Left button was pressed." << std::endl;
556 std::cout <<
"Middle button was pressed." << std::endl;
559 std::cout <<
"Right button was pressed. Bye. " << std::endl;
591 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)