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_DISPLAY)
55 #include <visp3/core/vpImage.h>
56 #include <visp3/io/vpImageIo.h>
57 #include <visp3/gui/vpDisplayFactory.h>
58 #include <visp3/core/vpTime.h>
71 #define GETOPTARGS "di:p:hf:l:s:w"
73 #ifdef ENABLE_VISP_NAMESPACE
90 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
91 unsigned last,
unsigned step)
93 #if VISP_HAVE_DATASET_VERSION >= 0x030600
94 std::string ext(
"png");
96 std::string ext(
"pgm");
99 Read an image sequence from the disk and display it.\n\
100 The sequence is made of separate images. Each image corresponds\n\
104 %s [-i <test image path>] [-p <personal image path>]\n\
105 [-f <first image>] [-l <last image>] [-s <step>] \n\
106 [-w] [-d] [-h]\n", name);
110 -i <test image path> %s\n\
111 Set image input path.\n\
112 From this path read \"cube/image.%%04d.%s\"\n\
113 images. These images come from ViSP-images-x.y.z.tar.gz\n\
114 available on the ViSP website.\n\
115 Setting the VISP_INPUT_IMAGE_PATH environment\n\
116 variable produces the same behaviour than using\n\
119 -p <personal image path> %s\n\
120 Specify a personal sequence containing images \n\
122 By image sequence, we mean one file per image.\n\
123 The format is selected by analysing the filename extension.\n\
124 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
125 %%04d is for the image numbering.\n\
127 -f <first image> %u\n\
128 First image number of the sequence.\n\
130 -l <last image> %u\n\
131 last image number of the sequence.\n\
134 Step between two images.\n\
137 Disable the image display. This can be useful \n\
138 for automatic tests using crontab under Unix or \n\
139 using the task manager under Windows.\n\
142 Wait for a mouse click between two images.\n\
143 If the image display is disabled (using -d)\n\
144 this option is without effect.\n\
147 Print the help.\n\n",
148 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
151 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
174 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
175 unsigned &step,
bool &display,
bool &wait)
192 first = (unsigned)atoi(optarg_);
195 last = (unsigned)atoi(optarg_);
198 step = (unsigned)atoi(optarg_);
204 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
209 usage(argv[0], optarg_, ipath, ppath, first, last, step);
215 if ((c == 1) || (c == -1)) {
217 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
218 std::cerr <<
"ERROR: " << std::endl;
219 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
226 int main(
int argc,
const char **argv)
228 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
232 std::string env_ipath;
233 std::string opt_ipath;
235 std::string opt_ppath;
237 std::string filename;
238 unsigned opt_first = 0;
239 unsigned opt_last = 80;
240 unsigned opt_step = 1;
241 bool opt_display =
true;
242 bool opt_wait =
false;
244 #if VISP_HAVE_DATASET_VERSION >= 0x030600
245 std::string ext(
"png");
247 std::string ext(
"pgm");
255 if (!env_ipath.empty())
259 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_display, opt_wait) ==
268 if (!opt_ipath.empty())
273 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
274 if (ipath != env_ipath) {
275 std::cout << std::endl <<
"WARNING: " << std::endl;
276 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
277 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
278 <<
" we skip the environment variable." << std::endl;
283 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
284 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
285 std::cerr << std::endl <<
"ERROR:" << std::endl;
286 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
287 <<
" environment variable to specify the location of the " << std::endl
288 <<
" image path where test images are located." << std::endl
289 <<
" Use -p <personal image path> option if you want to " << std::endl
290 <<
" use personal images." << std::endl
301 unsigned iter = opt_first;
302 std::ostringstream s;
303 char cfilename[FILENAME_MAX];
305 if (opt_ppath.empty()) {
311 s.setf(std::ios::right, std::ios::adjustfield);
312 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
316 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
317 filename = cfilename;
324 std::cerr << std::endl <<
"ERROR:" << std::endl;
325 std::cerr <<
" Cannot read " << filename << std::endl;
326 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
327 <<
" or your -p " << opt_ppath <<
" option " << std::endl
328 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
332 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
341 display->init(I, 100, 100,
"Display...");
353 while (iter < opt_last) {
357 if (opt_ppath.empty()) {
359 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
363 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
364 filename = cfilename;
367 std::cout <<
"read : " << filename << std::endl;
377 std::cout <<
"A click in the image to continue..." << std::endl;
391 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
392 if (display !=
nullptr) {
399 std::cout <<
"Catch an exception: " << e << std::endl;
400 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
401 if (display !=
nullptr) {
411 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..."
413 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
414 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
415 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
416 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
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)
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)
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()