45#include <visp3/core/vpConfig.h>
46#include <visp3/core/vpDebug.h>
47#include <visp3/core/vpIoTools.h>
48#include <visp3/io/vpParseArgv.h>
55#if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9))
57#include <visp3/core/vpImage.h>
58#include <visp3/io/vpImageIo.h>
60#include <visp3/core/vpMouseButton.h>
61#include <visp3/gui/vpDisplayD3D.h>
62#include <visp3/gui/vpDisplayGDI.h>
63#include <visp3/gui/vpDisplayGTK.h>
64#include <visp3/gui/vpDisplayX.h>
66#include <visp3/core/vpTime.h>
79#define GETOPTARGS "cdi:Lp:ht:f:l:s:w"
101void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
unsigned last,
102 unsigned step, vpDisplayType &dtype)
104#if VISP_HAVE_DATASET_VERSION >= 0x030600
105 std::string ext(
"png");
107 std::string ext(
"pgm");
111Read an image sequence from the disk and display it.\n\
112The sequence is made of separate images. Each image corresponds\n\
116 %s [-i <test image path>] [-p <personal image path>]\n\
117 [-f <first image>] [-l <last image>] [-s <step>] \n\
118 [-t <type of video device>] [-L] [-w] [-c] [-d] [-h]\n\
140 -i <test image path> %s\n\
141 Set image input path.\n\
142 From this path read \"cube/image.%%04d.%s\"\n\
143 images. These images come from ViSP-images-x.y.z.tar.gz\n\
144 available on the ViSP website.\n\
145 Setting the VISP_INPUT_IMAGE_PATH environment\n\
146 variable produces the same behaviour than using\n\
149 -p <personal image path> %s\n\
150 Specify a personal sequence containing images \n\
152 By image sequence, we mean one file per image.\n\
153 The format is selected by analysing the filename extension.\n\
154 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
155 %%04d is for the image numbering.\n\
157 -f <first image> %u\n\
158 First image number of the sequence.\n\
160 -l <last image> %u\n\
161 Last image number of 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(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step, display.c_str());
195 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
221bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
222 unsigned &step, vpDisplayType &dtype,
bool &list,
bool &display,
bool &click,
bool &wait)
226 std::string sDisplayType;
237 sDisplayType = optarg_;
239 if (sDisplayType.compare(
"X11") == 0) {
241 }
else if (sDisplayType.compare(
"GTK") == 0) {
243 }
else if (sDisplayType.compare(
"GDI") == 0) {
245 }
else if (sDisplayType.compare(
"D3D") == 0) {
260 first = (unsigned)atoi(optarg_);
263 last = (unsigned)atoi(optarg_);
266 step = (unsigned)atoi(optarg_);
272 usage(argv[0], NULL, ipath, ppath, first, last, step, dtype);
277 usage(argv[0], optarg_, ipath, ppath, first, last, step, dtype);
283 if ((c == 1) || (c == -1)) {
285 usage(argv[0], NULL, ipath, ppath, first, last, step, dtype);
286 std::cerr <<
"ERROR: " << std::endl;
287 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
294int main(
int argc,
const char **argv)
296 std::string env_ipath;
297 std::string opt_ipath;
299 std::string opt_ppath;
301 std::string filename;
302 unsigned opt_first = 30;
303 unsigned opt_last = 40;
304 unsigned opt_step = 1;
305 vpDisplayType opt_dtype;
306 bool opt_list =
false;
307 bool opt_display =
true;
308 bool opt_click =
true;
309 bool opt_click_blocking =
false;
311#if VISP_HAVE_DATASET_VERSION >= 0x030600
312 std::string ext(
"png");
314 std::string ext(
"pgm");
318#if defined(VISP_HAVE_GTK)
320#elif defined(VISP_HAVE_X11)
322#elif defined(VISP_HAVE_GDI)
324#elif defined(VISP_HAVE_D3D9)
333 if (!env_ipath.empty())
337 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_dtype, opt_list, opt_display,
338 opt_click, opt_click_blocking) ==
false) {
343 unsigned nbDevices = 0;
344 std::cout <<
"List of video-devices available: \n";
345#if defined(VISP_HAVE_GTK)
346 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
349#if defined(VISP_HAVE_X11)
350 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
353#if defined(VISP_HAVE_GDI)
355 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
358#if defined(VISP_HAVE_D3D9)
359 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
363 std::cout <<
" No display is available\n";
369 opt_click_blocking =
false;
372 if (!opt_ipath.empty())
377 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
378 if (ipath != env_ipath) {
379 std::cout << std::endl <<
"WARNING: " << std::endl;
380 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
381 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
382 <<
" we skip the environment variable." << std::endl;
387 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
388 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_last, opt_step, opt_dtype);
389 std::cerr << std::endl <<
"ERROR:" << std::endl;
390 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
391 <<
" environment variable to specify the location of the " << std::endl
392 <<
" image path where test images are located." << std::endl
393 <<
" Use -p <personal image path> option if you want to " << std::endl
394 <<
" use personal images." << std::endl
405 unsigned iter = opt_first;
406 std::ostringstream s;
407 char cfilename[FILENAME_MAX];
409 if (opt_ppath.empty()) {
414 s.setf(std::ios::right, std::ios::adjustfield);
415 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
419 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
420 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)
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...");
501 while (iter < opt_last) {
506 if (opt_ppath.empty()) {
508 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
511 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
512 filename = cfilename;
515 std::cout <<
"read : " << filename << std::endl;
524 if (opt_click_blocking) {
525 std::cout <<
"A click in the image to continue..." << std::endl;
535 std::cout <<
"Left button was pressed." << std::endl;
538 std::cout <<
"Middle button was pressed." << std::endl;
541 std::cout <<
"Right button was pressed. Bye. " << std::endl;
564int 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...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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 ...
Definition of the vpImage class member functions.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()