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"
75 #ifdef ENABLE_VISP_NAMESPACE
92 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
93 unsigned last,
unsigned step)
95 #if VISP_HAVE_DATASET_VERSION >= 0x030600
96 std::string ext(
"png");
98 std::string ext(
"pgm");
101 Read an image sequence from the disk and display it.\n\
102 The sequence is made of separate images. Each image corresponds\n\
106 %s [-i <test image path>] [-p <personal image path>]\n\
107 [-f <first image>] [-l <last image>] [-s <step>] \n\
108 [-w] [-d] [-h]\n", name);
112 -i <test image path> %s\n\
113 Set image input path.\n\
114 From this path read \"cube/image.%%04d.%s\"\n\
115 images. These images come from ViSP-images-x.y.z.tar.gz\n\
116 available on the ViSP website.\n\
117 Setting the VISP_INPUT_IMAGE_PATH environment\n\
118 variable produces the same behaviour than using\n\
121 -p <personal image path> %s\n\
122 Specify a personal sequence containing images \n\
124 By image sequence, we mean one file per image.\n\
125 The format is selected by analysing the filename extension.\n\
126 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
127 %%04d is for the image numbering.\n\
129 -f <first image> %u\n\
130 First image number of the sequence.\n\
132 -l <last image> %u\n\
133 last image number of the sequence.\n\
136 Step between two images.\n\
139 Disable the image display. This can be useful \n\
140 for automatic tests using crontab under Unix or \n\
141 using the task manager under Windows.\n\
144 Wait for a mouse click between two images.\n\
145 If the image display is disabled (using -d)\n\
146 this option is without effect.\n\
149 Print the help.\n\n",
150 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
153 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
176 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
177 unsigned &step,
bool &display,
bool &wait)
194 first = (unsigned)atoi(optarg_);
197 last = (unsigned)atoi(optarg_);
200 step = (unsigned)atoi(optarg_);
206 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
211 usage(argv[0], optarg_, ipath, ppath, first, last, step);
217 if ((c == 1) || (c == -1)) {
219 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
220 std::cerr <<
"ERROR: " << std::endl;
221 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
228 int main(
int argc,
const char **argv)
231 std::string env_ipath;
232 std::string opt_ipath;
234 std::string opt_ppath;
236 std::string filename;
237 unsigned opt_first = 0;
238 unsigned opt_last = 80;
239 unsigned opt_step = 1;
240 bool opt_display =
true;
241 bool opt_wait =
false;
243 #if VISP_HAVE_DATASET_VERSION >= 0x030600
244 std::string ext(
"png");
246 std::string ext(
"pgm");
254 if (!env_ipath.empty())
258 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_display, opt_wait) ==
267 if (!opt_ipath.empty())
272 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
273 if (ipath != env_ipath) {
274 std::cout << std::endl <<
"WARNING: " << std::endl;
275 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
276 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
277 <<
" we skip the environment variable." << std::endl;
282 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
283 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
284 std::cerr << std::endl <<
"ERROR:" << std::endl;
285 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
286 <<
" environment variable to specify the location of the " << std::endl
287 <<
" image path where test images are located." << std::endl
288 <<
" Use -p <personal image path> option if you want to " << std::endl
289 <<
" use personal images." << std::endl
300 unsigned iter = opt_first;
301 std::ostringstream s;
302 char cfilename[FILENAME_MAX];
304 if (opt_ppath.empty()) {
310 s.setf(std::ios::right, std::ios::adjustfield);
311 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
315 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
316 filename = cfilename;
323 std::cerr << std::endl <<
"ERROR:" << std::endl;
324 std::cerr <<
" Cannot read " << filename << std::endl;
325 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
326 <<
" or your -p " << opt_ppath <<
" option " << std::endl
327 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
331 #if defined(VISP_HAVE_GTK)
333 #elif defined(VISP_HAVE_X11)
335 #elif defined(VISP_HAVE_GDI)
342 display.init(I, 100, 100,
"Display...");
354 while (iter < opt_last) {
358 if (opt_ppath.empty()) {
360 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
364 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
365 filename = cfilename;
368 std::cout <<
"read : " << filename << std::endl;
378 std::cout <<
"A click in the image to continue..." << std::endl;
395 std::cout <<
"Catch an exception: " << e << std::endl;
402 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..."
404 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
405 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
406 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
407 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...
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)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()