48 #include <visp3/core/vpDebug.h>
49 #include <visp3/core/vpConfig.h>
50 #include <visp3/io/vpParseArgv.h>
51 #include <visp3/core/vpIoTools.h>
58 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9))
60 #include <visp3/core/vpImage.h>
61 #include <visp3/io/vpImageIo.h>
63 #include <visp3/gui/vpDisplayGTK.h>
64 #include <visp3/gui/vpDisplayX.h>
65 #include <visp3/gui/vpDisplayGDI.h>
66 #include <visp3/gui/vpDisplayD3D.h>
67 #include <visp3/core/vpMouseButton.h>
69 #include <visp3/core/vpTime.h>
82 #define GETOPTARGS "cdi:lp:ht:f:n:s:w"
90 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
91 unsigned first,
unsigned nimages,
unsigned step, vpDisplayType &dtype);
92 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
93 unsigned &first,
unsigned &nimages,
unsigned &step,
94 vpDisplayType &dtype,
bool &list,
bool &
display,
bool &click,
bool &wait);
110 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
111 unsigned first,
unsigned nimages,
unsigned step, vpDisplayType &dtype)
114 Read an image sequence from the disk and display it.\n\
115 The sequence is made of separate images. Each image corresponds\n\
119 %s [-i <test image path>] [-p <personal image path>]\n\
120 [-f <first image>] [-n <number of images>] [-s <step>] \n\
121 [-t <type of video device>] [-l] [-w] [-c] [-d] [-h]\n \
126 case vpX11: display =
"X11";
break;
127 case vpGTK: display =
"GTK";
break;
128 case vpGDI: display =
"GDI";
break;
129 case vpD3D: display =
"D3D";
break;
134 -i <test image path> %s\n\
135 Set image input path.\n\
136 From this path read \"ViSP-images/cube/image.%%04d.pgm\"\n\
137 images. These images come from ViSP-images-x.y.z.tar.gz\n\
138 available on the ViSP website.\n\
139 Setting the VISP_INPUT_IMAGE_PATH environment\n\
140 variable produces the same behaviour than using\n\
143 -p <personal image path> %s\n\
144 Specify a personal sequence containing images \n\
146 By image sequence, we mean one file per image.\n\
147 The following image file formats PNM (PGM P5, PPM P6)\n\
148 are supported. The format is selected by analysing \n\
149 the filename extension.\n\
150 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
151 %%04d is for the image numbering.\n\
153 -f <first image> %u\n\
154 First image number of the sequence.\n\
156 -n <number of images> %u\n\
157 Number of images to load from the sequence.\n\
160 Step between two images.\n\
162 -t <type of video device> \"%s\"\n\
163 String specifying the video device to use.\n\
165 \"X11\": only on UNIX platforms,\n\
166 \"GTK\": on all plaforms,\n\
167 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
168 \"D3D\": only on Windows platform (Direct3D).\n\
171 Print the list of video-devices available and exit.\n\
174 Disable mouse click.\n\
177 Disable the image display. This can be useful \n\
178 for automatic tests using crontab under Unix or \n\
179 using the task manager under Windows.\n\
182 Wait for a mouse click between two images.\n\
183 If the image display is disabled (using -d)\n\
184 this option is without effect.\n\
187 Print the help.\n\n",
188 ipath.c_str(),ppath.c_str(), first, nimages, step, display.c_str());
191 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
217 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
218 unsigned &first,
unsigned &nimages,
unsigned &step,
219 vpDisplayType &dtype,
bool &list,
bool &display,
bool &click,
bool &wait)
223 std::string sDisplayType;
227 case 'c': click =
false;
break;
228 case 'd': display =
false;
break;
229 case 't': sDisplayType = optarg_;
231 if (sDisplayType.compare(
"X11") == 0) {
234 else if (sDisplayType.compare(
"GTK") == 0) {
237 else if (sDisplayType.compare(
"GDI") == 0) {
240 else if (sDisplayType.compare(
"D3D") == 0) {
245 case 'i': ipath = optarg_;
break;
246 case 'l': list =
true;
break;
247 case 'p': ppath = optarg_;
break;
248 case 'f': first = (unsigned) atoi(optarg_);
break;
249 case 'n': nimages = (unsigned) atoi(optarg_);
break;
250 case 's': step = (unsigned) atoi(optarg_);
break;
251 case 'w': wait =
true;
break;
252 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step, dtype);
256 usage(argv[0], optarg_, ipath, ppath, first, nimages, step, dtype);
261 if ((c == 1) || (c == -1)) {
263 usage(argv[0], NULL, ipath, ppath, first, nimages, step, dtype);
264 std::cerr <<
"ERROR: " << std::endl;
265 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
273 main(
int argc,
const char ** argv)
275 std::string env_ipath;
276 std::string opt_ipath;
278 std::string opt_ppath;
280 std::string filename;
281 unsigned opt_first = 30;
282 unsigned opt_nimages = 10;
283 unsigned opt_step = 1;
284 vpDisplayType opt_dtype;
285 bool opt_list =
false;
286 bool opt_display =
true;
287 bool opt_click =
true;
288 bool opt_click_blocking =
false;
291 #if defined VISP_HAVE_GTK
293 #elif defined VISP_HAVE_X11
295 #elif defined VISP_HAVE_GDI
297 #elif defined VISP_HAVE_D3D9
305 if (! env_ipath.empty())
309 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
310 opt_step, opt_dtype, opt_list, opt_display, opt_click,
311 opt_click_blocking) ==
false) {
316 unsigned nbDevices = 0;
317 std::cout <<
"List of video-devices available: \n";
318 #if defined VISP_HAVE_GTK
319 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
322 #if defined VISP_HAVE_X11
323 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
326 #if defined VISP_HAVE_GDI
327 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
330 #if defined VISP_HAVE_D3D9
331 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
335 std::cout <<
" No display is available\n";
341 opt_click_blocking =
false;
344 if (!opt_ipath.empty())
349 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
350 if (ipath != env_ipath) {
351 std::cout << std::endl
352 <<
"WARNING: " << std::endl;
353 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
354 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
355 <<
" we skip the environment variable." << std::endl;
360 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
361 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step,opt_dtype);
362 std::cerr << std::endl
363 <<
"ERROR:" << std::endl;
364 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
366 <<
" environment variable to specify the location of the " << std::endl
367 <<
" image path where test images are located." << std::endl
368 <<
" Use -p <personal image path> option if you want to "<<std::endl
369 <<
" use personal images." << std::endl
380 unsigned iter = opt_first;
381 std::ostringstream s;
382 char cfilename[FILENAME_MAX];
384 if (opt_ppath.empty()){
404 s.setf(std::ios::right, std::ios::adjustfield);
405 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
410 sprintf(cfilename,opt_ppath.c_str(), iter) ;
411 filename = cfilename;
428 std::cerr << std::endl
429 <<
"ERROR:" << std::endl;
430 std::cerr <<
" Cannot read " << filename << std::endl;
431 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
432 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
433 <<
" or VISP_INPUT_IMAGE_PATH environment variable"
442 std::cout <<
"Requested X11 display functionnalities..." << std::endl;
443 #if defined VISP_HAVE_X11
446 std::cout <<
" Sorry, X11 video device is not available.\n";
447 std::cout <<
"Use \"" << argv[0]
448 <<
" -l\" to print the list of available devices.\n";
453 std::cout <<
"Requested GTK display functionnalities..." << std::endl;
454 #if defined VISP_HAVE_GTK
457 std::cout <<
" Sorry, GTK video device is not available.\n";
458 std::cout <<
"Use \"" << argv[0]
459 <<
" -l\" to print the list of available devices.\n";
464 std::cout <<
"Requested GDI display functionnalities..." << std::endl;
465 #if defined VISP_HAVE_GDI
468 std::cout <<
" Sorry, GDI video device is not available.\n";
469 std::cout <<
"Use \"" << argv[0]
470 <<
" -l\" to print the list of available devices.\n";
475 std::cout <<
"Requested D3D display functionnalities..." << std::endl;
476 #if defined VISP_HAVE_D3D9
479 std::cout <<
" Sorry, D3D video device is not available.\n";
480 std::cout <<
"Use \"" << argv[0]
481 <<
" -l\" to print the list of available devices.\n";
491 display->init(I, 100, 100,
"Display...") ;
511 while (iter < opt_first + opt_nimages*opt_step) {
517 if (opt_ppath.empty()){
519 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
523 sprintf(cfilename, opt_ppath.c_str(), iter) ;
524 filename = cfilename;
527 std::cout <<
"read : " << filename << std::endl;
536 if (opt_click_blocking) {
537 std::cout <<
"A click in the image to continue..." << std::endl;
547 std::cout <<
"Left button was pressed." << std::endl;
550 std::cout <<
"Middle button was pressed." << std::endl;
553 std::cout <<
"Right button was pressed. Bye. " << std::endl;
586 vpERROR_TRACE(
"You do not have X11 or GTK display functionalities...");
VISP_EXPORT int wait(double t0, double t)
Class that defines generic functionnalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
vpDisplayGDI()
Basic constructor.
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
static void display(const vpImage< unsigned char > &I)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
static void read(vpImage< unsigned char > &I, const std::string &filename)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...