47#include <visp3/core/vpConfig.h>
48#include <visp3/core/vpDebug.h>
49#include <visp3/core/vpIoTools.h>
50#include <visp3/io/vpParseArgv.h>
51#if defined(VISP_HAVE_DISPLAY)
53#include <visp3/core/vpImage.h>
54#include <visp3/io/vpImageIo.h>
55#include <visp3/gui/vpDisplayFactory.h>
56#include <visp3/core/vpTime.h>
69#define GETOPTARGS "di:p:hf:l:s:w"
71#ifdef ENABLE_VISP_NAMESPACE
88void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath,
unsigned first,
89 unsigned last,
unsigned step)
91#if defined(VISP_HAVE_DATASET)
92#if VISP_HAVE_DATASET_VERSION >= 0x030600
93 std::string ext(
"png");
95 std::string ext(
"pgm");
99 std::string ext(
"png");
102Read an image sequence from the disk and display it.\n\
103The sequence is made of separate images. Each image corresponds\n\
107 %s [-i <test image path>] [-p <personal image path>]\n\
108 [-f <first image>] [-l <last image>] [-s <step>] \n\
109 [-w] [-d] [-h]\n", name);
113 -i <test image path> %s\n\
114 Set image input path.\n\
115 From this path read \"cube/image.%%04d.%s\"\n\
116 images. These images come from ViSP-images-x.y.z.tar.gz\n\
117 available on the ViSP website.\n\
118 Setting the VISP_INPUT_IMAGE_PATH environment\n\
119 variable produces the same behaviour than using\n\
122 -p <personal image path> %s\n\
123 Specify a personal sequence containing images \n\
125 By image sequence, we mean one file per image.\n\
126 The format is selected by analyzing the filename extension.\n\
127 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
128 %%04d is for the image numbering.\n\
130 -f <first image> %u\n\
131 First image number of the sequence.\n\
133 -l <last image> %u\n\
134 last image number of the sequence.\n\
137 Step between two images.\n\
140 Disable the image display. This can be useful \n\
141 for automatic tests using crontab under Unix or \n\
142 using the task manager under Windows.\n\
145 Wait for a mouse click between two images.\n\
146 If the image display is disabled (using -d)\n\
147 this option is without effect.\n\
150 Print the help.\n\n",
151 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
154 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
177bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
178 unsigned &step,
bool &display,
bool &wait)
195 first =
static_cast<unsigned int>(atoi(optarg_));
198 last =
static_cast<unsigned int>(atoi(optarg_));
201 step =
static_cast<unsigned int>(atoi(optarg_));
207 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
211 usage(argv[0], optarg_, ipath, ppath, first, last, step);
216 if ((c == 1) || (c == -1)) {
218 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
219 std::cerr <<
"ERROR: " << std::endl;
220 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
227int main(
int argc,
const char **argv)
229#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
233 std::string env_ipath;
234 std::string opt_ipath;
236 std::string opt_ppath;
239 unsigned opt_first = 0;
240 unsigned opt_last = 80;
241 unsigned opt_step = 1;
242 bool opt_display =
true;
243 bool opt_wait =
false;
245#if defined(VISP_HAVE_DATASET)
246#if VISP_HAVE_DATASET_VERSION >= 0x030600
247 std::string ext(
"png");
249 std::string ext(
"pgm");
253 std::string ext(
"png");
261 if (!env_ipath.empty())
265 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_display, opt_wait) ==
274 if (!opt_ipath.empty())
279 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
280 if (ipath != env_ipath) {
281 std::cout << std::endl <<
"WARNING: " << std::endl;
282 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
283 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
284 <<
" we skip the environment variable." << std::endl;
289 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
290 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
291 std::cerr << std::endl <<
"ERROR:" << std::endl;
292 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
293 <<
" environment variable to specify the location of the " << std::endl
294 <<
" image path where test images are located." << std::endl
295 <<
" Use -p <personal image path> option if you want to " << std::endl
296 <<
" use personal images." << std::endl
307 unsigned iter = opt_first;
308 std::string imagename(
"image.%04d." + ext);
310 if (opt_ppath.empty()) {
325 std::cerr << std::endl <<
"ERROR:" << std::endl;
326 std::cerr <<
" Cannot read " <<
filename << std::endl;
327 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
328 <<
" or your -p " << opt_ppath <<
" option " << std::endl
329 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
333#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
342 display->init(I, 100, 100,
"Display...");
354 while (iter < opt_last) {
358 if (opt_ppath.empty()) {
365 std::cout <<
"read : " <<
filename << std::endl;
375 std::cout <<
"A click in the image to continue..." << std::endl;
389#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
390 if (display !=
nullptr) {
397 std::cout <<
"Catch an exception: " <<
e << std::endl;
398#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
399 if (display !=
nullptr) {
409 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..."
411 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
412 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
413 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
414 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)
Definition of the vpImage class member functions.
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 double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)