49 #include <visp3/core/vpConfig.h> 50 #include <visp3/core/vpDebug.h> 51 #include <visp3/core/vpIoTools.h> 52 #include <visp3/io/vpParseArgv.h> 59 #if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9)) 61 #include <visp3/core/vpImage.h> 62 #include <visp3/io/vpImageIo.h> 64 #include <visp3/core/vpMouseButton.h> 65 #include <visp3/gui/vpDisplayD3D.h> 66 #include <visp3/gui/vpDisplayGDI.h> 67 #include <visp3/gui/vpDisplayGTK.h> 68 #include <visp3/gui/vpDisplayX.h> 70 #include <visp3/core/vpTime.h> 83 #define GETOPTARGS "cdi:lp:ht:f:n:s:w" 91 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
92 unsigned nimages,
unsigned step, vpDisplayType &dtype);
93 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
94 unsigned &step, 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,
unsigned first,
111 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 \ 142 -i <test image path> %s\n\ 143 Set image input path.\n\ 144 From this path read \"cube/image.%%04d.pgm\"\n\ 145 images. These images come from ViSP-images-x.y.z.tar.gz\n\ 146 available on the ViSP website.\n\ 147 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 148 variable produces the same behaviour than using\n\ 151 -p <personal image path> %s\n\ 152 Specify a personal sequence containing images \n\ 154 By image sequence, we mean one file per image.\n\ 155 The following image file formats PNM (PGM P5, PPM P6)\n\ 156 are supported. The format is selected by analysing \n\ 157 the filename extension.\n\ 158 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\ 159 %%04d is for the image numbering.\n\ 161 -f <first image> %u\n\ 162 First image number of the sequence.\n\ 164 -n <number of images> %u\n\ 165 Number of images to load from the sequence.\n\ 168 Step between two images.\n\ 170 -t <type of video device> \"%s\"\n\ 171 String specifying the video device to use.\n\ 173 \"X11\": only on UNIX platforms,\n\ 174 \"GTK\": on all plaforms,\n\ 175 \"GDI\": only on Windows platform (Graphics Device Interface),\n\ 176 \"D3D\": only on Windows platform (Direct3D).\n\ 179 Print the list of video-devices available and exit.\n\ 182 Disable mouse click.\n\ 185 Disable the image display. This can be useful \n\ 186 for automatic tests using crontab under Unix or \n\ 187 using the task manager under Windows.\n\ 190 Wait for a mouse click between two images.\n\ 191 If the image display is disabled (using -d)\n\ 192 this option is without effect.\n\ 195 Print the help.\n\n", ipath.c_str(), ppath.c_str(), first, nimages, step, display.c_str());
198 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
224 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
225 unsigned &step, vpDisplayType &dtype,
bool &list,
bool &display,
bool &click,
bool &wait)
229 std::string sDisplayType;
240 sDisplayType = optarg_;
242 if (sDisplayType.compare(
"X11") == 0) {
244 }
else if (sDisplayType.compare(
"GTK") == 0) {
246 }
else if (sDisplayType.compare(
"GDI") == 0) {
248 }
else if (sDisplayType.compare(
"D3D") == 0) {
263 first = (unsigned)atoi(optarg_);
266 nimages = (unsigned)atoi(optarg_);
269 step = (unsigned)atoi(optarg_);
275 usage(argv[0], NULL, ipath, ppath, first, nimages, step, dtype);
280 usage(argv[0], optarg_, ipath, ppath, first, nimages, step, dtype);
286 if ((c == 1) || (c == -1)) {
288 usage(argv[0], NULL, ipath, ppath, first, nimages, step, dtype);
289 std::cerr <<
"ERROR: " << std::endl;
290 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
297 int main(
int argc,
const char **argv)
299 std::string env_ipath;
300 std::string opt_ipath;
302 std::string opt_ppath;
304 std::string filename;
305 unsigned opt_first = 30;
306 unsigned opt_nimages = 10;
307 unsigned opt_step = 1;
308 vpDisplayType opt_dtype;
309 bool opt_list =
false;
310 bool opt_display =
true;
311 bool opt_click =
true;
312 bool opt_click_blocking =
false;
315 #if defined VISP_HAVE_GTK 317 #elif defined VISP_HAVE_X11 319 #elif defined VISP_HAVE_GDI 321 #elif defined VISP_HAVE_D3D9 330 if (!env_ipath.empty())
334 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_dtype, opt_list, opt_display,
335 opt_click, opt_click_blocking) ==
false) {
340 unsigned nbDevices = 0;
341 std::cout <<
"List of video-devices available: \n";
342 #if defined VISP_HAVE_GTK 343 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
346 #if defined VISP_HAVE_X11 347 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
350 #if defined VISP_HAVE_GDI 351 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
354 #if defined VISP_HAVE_D3D9 355 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
359 std::cout <<
" No display is available\n";
365 opt_click_blocking =
false;
368 if (!opt_ipath.empty())
373 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
374 if (ipath != env_ipath) {
375 std::cout << std::endl <<
"WARNING: " << std::endl;
376 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 377 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
378 <<
" we skip the environment variable." << std::endl;
383 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
384 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_dtype);
385 std::cerr << std::endl <<
"ERROR:" << std::endl;
386 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
387 <<
" environment variable to specify the location of the " << std::endl
388 <<
" image path where test images are located." << std::endl
389 <<
" Use -p <personal image path> option if you want to " << std::endl
390 <<
" use personal images." << std::endl
401 unsigned iter = opt_first;
402 std::ostringstream s;
403 char cfilename[FILENAME_MAX];
405 if (opt_ppath.empty()) {
424 s.setf(std::ios::right, std::ios::adjustfield);
425 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
429 sprintf(cfilename, opt_ppath.c_str(), iter);
430 filename = cfilename;
445 std::cerr << std::endl <<
"ERROR:" << std::endl;
446 std::cerr <<
" Cannot read " << filename << std::endl;
447 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
448 <<
" or your -p " << opt_ppath <<
" option " << std::endl
449 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
457 std::cout <<
"Requested X11 display functionnalities..." << std::endl;
458 #if defined VISP_HAVE_X11 461 std::cout <<
" Sorry, X11 video device is not available.\n";
462 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
467 std::cout <<
"Requested GTK display functionnalities..." << std::endl;
468 #if defined VISP_HAVE_GTK 471 std::cout <<
" Sorry, GTK video device is not available.\n";
472 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
477 std::cout <<
"Requested GDI display functionnalities..." << std::endl;
478 #if defined VISP_HAVE_GDI 481 std::cout <<
" Sorry, GDI video device is not available.\n";
482 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
487 std::cout <<
"Requested D3D display functionnalities..." << std::endl;
488 #if defined VISP_HAVE_D3D9 491 std::cout <<
" Sorry, D3D video device is not available.\n";
492 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
502 display->init(I, 100, 100,
"Display...");
521 while (iter < opt_first + opt_nimages * opt_step) {
527 if (opt_ppath.empty()) {
529 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
532 sprintf(cfilename, opt_ppath.c_str(), iter);
533 filename = cfilename;
536 std::cout <<
"read : " << filename << std::endl;
545 if (opt_click_blocking) {
546 std::cout <<
"A click in the image to continue..." << std::endl;
556 std::cout <<
"Left button was pressed." << std::endl;
559 std::cout <<
"Middle button was pressed." << std::endl;
562 std::cout <<
"Right button was pressed. Bye. " << std::endl;
592 int main() {
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 ...