44 #include <visp3/core/vpConfig.h>
45 #include <visp3/core/vpDebug.h>
46 #include <visp3/core/vpIoTools.h>
47 #include <visp3/io/vpParseArgv.h>
54 #if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9))
56 #include <visp3/core/vpImage.h>
57 #include <visp3/io/vpImageIo.h>
59 #include <visp3/core/vpMouseButton.h>
60 #include <visp3/gui/vpDisplayD3D.h>
61 #include <visp3/gui/vpDisplayGDI.h>
62 #include <visp3/gui/vpDisplayGTK.h>
63 #include <visp3/gui/vpDisplayX.h>
65 #include <visp3/core/vpTime.h>
68 #define GETOPTARGS "cdi:Lp:ht:f:l:s:w"
70 #ifdef ENABLE_VISP_NAMESPACE
96 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
unsigned last,
97 unsigned step, vpDisplayType &dtype)
99 #if VISP_HAVE_DATASET_VERSION >= 0x030600
100 std::string ext(
"png");
102 std::string ext(
"pgm");
106 Read an image sequence from the disk and display it.\n\
107 The sequence is made of separate images. Each image corresponds\n\
111 %s [-i <test image path>] [-p <personal image path>]\n\
112 [-f <first image>] [-l <last image>] [-s <step>] \n\
113 [-t <type of video device>] [-L] [-w] [-c] [-d] [-h]\n\
135 -i <test image path> %s\n\
136 Set image input path.\n\
137 From this path read \"cube/image.%%04d.%s\"\n\
138 images. These images come from ViSP-images-x.y.z.tar.gz\n\
139 available on the ViSP website.\n\
140 Setting the VISP_INPUT_IMAGE_PATH environment\n\
141 variable produces the same behaviour than using\n\
144 -p <personal image path> %s\n\
145 Specify a personal sequence containing images \n\
147 By image sequence, we mean one file per image.\n\
148 The format is selected by analysing the filename extension.\n\
149 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
150 %%04d is for the image numbering.\n\
152 -f <first image> %u\n\
153 First image number of the sequence.\n\
155 -l <last image> %u\n\
156 Last image number of 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(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, 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,
unsigned &first,
unsigned &last,
217 unsigned &step, vpDisplayType &dtype,
bool &list,
bool &display,
bool &click,
bool &wait)
221 std::string sDisplayType;
232 sDisplayType = optarg_;
234 if (sDisplayType.compare(
"X11") == 0) {
237 else if (sDisplayType.compare(
"GTK") == 0) {
240 else if (sDisplayType.compare(
"GDI") == 0) {
243 else if (sDisplayType.compare(
"D3D") == 0) {
258 first = (unsigned)atoi(optarg_);
261 last = (unsigned)atoi(optarg_);
264 step = (unsigned)atoi(optarg_);
270 usage(argv[0],
nullptr, ipath, ppath, first, last, step, dtype);
275 usage(argv[0], optarg_, ipath, ppath, first, last, step, dtype);
281 if ((c == 1) || (c == -1)) {
283 usage(argv[0],
nullptr, ipath, ppath, first, last, step, dtype);
284 std::cerr <<
"ERROR: " << std::endl;
285 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
292 int main(
int argc,
const char **argv)
294 std::string env_ipath;
295 std::string opt_ipath;
297 std::string opt_ppath;
299 std::string filename;
300 unsigned opt_first = 30;
301 unsigned opt_last = 40;
302 unsigned opt_step = 1;
303 vpDisplayType opt_dtype;
304 bool opt_list =
false;
305 bool opt_display =
true;
306 bool opt_click =
true;
307 bool opt_click_blocking =
false;
309 #if VISP_HAVE_DATASET_VERSION >= 0x030600
310 std::string ext(
"png");
312 std::string ext(
"pgm");
316 #if defined(VISP_HAVE_GTK)
318 #elif defined(VISP_HAVE_X11)
320 #elif defined(VISP_HAVE_GDI)
322 #elif defined(VISP_HAVE_D3D9)
331 if (!env_ipath.empty())
335 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_dtype, opt_list, opt_display,
336 opt_click, opt_click_blocking) ==
false) {
341 unsigned nbDevices = 0;
342 std::cout <<
"List of video-devices available: \n";
343 #if defined(VISP_HAVE_GTK)
344 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
347 #if defined(VISP_HAVE_X11)
348 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
351 #if defined(VISP_HAVE_GDI)
353 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
356 #if defined(VISP_HAVE_D3D9)
357 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
361 std::cout <<
" No display is available\n";
367 opt_click_blocking =
false;
370 if (!opt_ipath.empty())
375 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
376 if (ipath != env_ipath) {
377 std::cout << std::endl <<
"WARNING: " << std::endl;
378 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
379 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
380 <<
" we skip the environment variable." << std::endl;
385 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
386 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step, opt_dtype);
387 std::cerr << std::endl <<
"ERROR:" << std::endl;
388 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
389 <<
" environment variable to specify the location of the " << std::endl
390 <<
" image path where test images are located." << std::endl
391 <<
" Use -p <personal image path> option if you want to " << std::endl
392 <<
" use personal images." << std::endl
403 unsigned iter = opt_first;
404 std::ostringstream s;
405 char cfilename[FILENAME_MAX];
407 if (opt_ppath.empty()) {
412 s.setf(std::ios::right, std::ios::adjustfield);
413 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
418 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
419 filename = cfilename;
426 std::cerr << std::endl <<
"ERROR:" << std::endl;
427 std::cerr <<
" Cannot read " << filename << std::endl;
428 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
429 <<
" or your -p " << opt_ppath <<
" option " << std::endl
430 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
438 std::cout <<
"Requested X11 display functionalities..." << std::endl;
439 #if defined(VISP_HAVE_X11)
440 display =
new vpDisplayX;
442 std::cout <<
" Sorry, X11 video device is not available.\n";
443 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
448 std::cout <<
"Requested GTK display functionalities..." << std::endl;
449 #if defined(VISP_HAVE_GTK)
452 std::cout <<
" Sorry, GTK video device is not available.\n";
453 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
458 std::cout <<
"Requested GDI display functionalities..." << std::endl;
459 #if defined(VISP_HAVE_GDI)
463 std::cout <<
" Sorry, GDI video device is not available.\n";
464 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
469 std::cout <<
"Requested D3D display functionalities..." << std::endl;
470 #if defined(VISP_HAVE_D3D9)
473 std::cout <<
" Sorry, D3D video device is not available.\n";
474 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
484 display->init(I, 100, 100,
"Display...");
495 vpERROR_TRACE(
"Error while displaying the image");
502 while (iter < opt_last) {
507 if (opt_ppath.empty()) {
509 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
513 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
514 filename = cfilename;
517 std::cout <<
"read : " << filename << std::endl;
526 if (opt_click_blocking) {
527 std::cout <<
"A click in the image to continue..." << std::endl;
537 std::cout <<
"Left button was pressed." << std::endl;
540 std::cout <<
"Middle button was pressed." << std::endl;
543 std::cout <<
"Right button was pressed. Bye. " << std::endl;
568 int main() { vpERROR_TRACE(
"You do not have X11 or GTK display functionalities..."); }
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Class that defines generic functionalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()