49 #include <visp3/core/vpConfig.h>
50 #include <visp3/core/vpDebug.h>
51 #include <visp3/core/vpIoTools.h>
52 #include <visp3/io/vpParseArgv.h>
53 #if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
55 #include <visp3/core/vpImage.h>
56 #include <visp3/io/vpImageIo.h>
57 #include <visp3/gui/vpDisplayGDI.h>
58 #include <visp3/gui/vpDisplayGTK.h>
59 #include <visp3/gui/vpDisplayX.h>
60 #include <visp3/core/vpTime.h>
73 #define GETOPTARGS "di:p:hf:l:s:w"
88 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
89 unsigned last,
unsigned step)
91 #if VISP_HAVE_DATASET_VERSION >= 0x030600
92 std::string ext(
"png");
94 std::string ext(
"pgm");
97 Read an image sequence from the disk and display it.\n\
98 The sequence is made of separate images. Each image corresponds\n\
102 %s [-i <test image path>] [-p <personal image path>]\n\
103 [-f <first image>] [-l <last image>] [-s <step>] \n\
104 [-w] [-d] [-h]\n", name);
108 -i <test image path> %s\n\
109 Set image input path.\n\
110 From this path read \"cube/image.%%04d.%s\"\n\
111 images. These images come from ViSP-images-x.y.z.tar.gz\n\
112 available on the ViSP website.\n\
113 Setting the VISP_INPUT_IMAGE_PATH environment\n\
114 variable produces the same behaviour than using\n\
117 -p <personal image path> %s\n\
118 Specify a personal sequence containing images \n\
120 By image sequence, we mean one file per image.\n\
121 The format is selected by analysing the filename extension.\n\
122 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
123 %%04d is for the image numbering.\n\
125 -f <first image> %u\n\
126 First image number of the sequence.\n\
128 -l <last image> %u\n\
129 last image number of the sequence.\n\
132 Step between two images.\n\
135 Disable the image display. This can be useful \n\
136 for automatic tests using crontab under Unix or \n\
137 using the task manager under Windows.\n\
140 Wait for a mouse click between two images.\n\
141 If the image display is disabled (using -d)\n\
142 this option is without effect.\n\
145 Print the help.\n\n",
146 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
149 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
172 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
173 unsigned &step,
bool &display,
bool &wait)
190 first = (unsigned)atoi(optarg_);
193 last = (unsigned)atoi(optarg_);
196 step = (unsigned)atoi(optarg_);
202 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
207 usage(argv[0], optarg_, ipath, ppath, first, last, step);
213 if ((c == 1) || (c == -1)) {
215 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
216 std::cerr <<
"ERROR: " << std::endl;
217 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
224 int main(
int argc,
const char **argv)
227 std::string env_ipath;
228 std::string opt_ipath;
230 std::string opt_ppath;
232 std::string filename;
233 unsigned opt_first = 0;
234 unsigned opt_last = 80;
235 unsigned opt_step = 1;
236 bool opt_display =
true;
237 bool opt_wait =
false;
239 #if VISP_HAVE_DATASET_VERSION >= 0x030600
240 std::string ext(
"png");
242 std::string ext(
"pgm");
250 if (!env_ipath.empty())
254 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_display, opt_wait) ==
263 if (!opt_ipath.empty())
268 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
269 if (ipath != env_ipath) {
270 std::cout << std::endl <<
"WARNING: " << std::endl;
271 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
272 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
273 <<
" we skip the environment variable." << std::endl;
278 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
279 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
280 std::cerr << std::endl <<
"ERROR:" << std::endl;
281 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
282 <<
" environment variable to specify the location of the " << std::endl
283 <<
" image path where test images are located." << std::endl
284 <<
" Use -p <personal image path> option if you want to " << std::endl
285 <<
" use personal images." << std::endl
296 unsigned iter = opt_first;
297 std::ostringstream s;
298 char cfilename[FILENAME_MAX];
300 if (opt_ppath.empty()) {
306 s.setf(std::ios::right, std::ios::adjustfield);
307 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
311 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
312 filename = cfilename;
319 std::cerr << std::endl <<
"ERROR:" << std::endl;
320 std::cerr <<
" Cannot read " << filename << std::endl;
321 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
322 <<
" or your -p " << opt_ppath <<
" option " << std::endl
323 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
327 #if defined(VISP_HAVE_GTK)
329 #elif defined(VISP_HAVE_X11)
331 #elif defined(VISP_HAVE_GDI)
338 display.init(I, 100, 100,
"Display...");
350 while (iter < opt_last) {
354 if (opt_ppath.empty()) {
356 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
360 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
361 filename = cfilename;
364 std::cout <<
"read : " << filename << std::endl;
374 std::cout <<
"A click in the image to continue..." << std::endl;
391 std::cout <<
"Catch an exception: " << e << std::endl;
398 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..."
400 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
401 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
402 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
403 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
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...
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)
error that can be emitted by ViSP classes.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()