54 #include <visp3/core/vpConfig.h> 55 #include <visp3/core/vpDebug.h> 56 #include <visp3/core/vpIoTools.h> 57 #include <visp3/io/vpParseArgv.h> 58 #if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) 60 #include <visp3/core/vpImage.h> 61 #include <visp3/io/vpImageIo.h> 63 #include <visp3/gui/vpDisplayGDI.h> 64 #include <visp3/gui/vpDisplayGTK.h> 65 #include <visp3/gui/vpDisplayX.h> 67 #include <visp3/core/vpTime.h> 80 #define GETOPTARGS "di:p:hf:n:s:w" 82 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
83 unsigned nimages,
unsigned step);
84 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
85 unsigned &step,
bool &display,
bool &wait);
100 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
101 unsigned nimages,
unsigned step)
104 Read an image sequence from the disk and display it.\n\ 105 The sequence is made of separate images. Each image corresponds\n\ 109 %s [-i <test image path>] [-p <personal image path>]\n\ 110 [-f <first image>] [-n <number of images>] [-s <step>] \n\ 116 -i <test image path> %s\n\ 117 Set image input path.\n\ 118 From this path read \"cube/image.%%04d.pgm\"\n\ 119 images. These images come from ViSP-images-x.y.z.tar.gz\n\ 120 available on the ViSP website.\n\ 121 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 122 variable produces the same behaviour than using\n\ 125 -p <personal image path> %s\n\ 126 Specify a personal sequence containing images \n\ 128 By image sequence, we mean one file per image.\n\ 129 The following image file formats PNM (PGM P5, PPM P6)\n\ 130 are supported. The format is selected by analysing \n\ 131 the filename extension.\n\ 132 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\ 133 %%04d is for the image numbering.\n\ 135 -f <first image> %u\n\ 136 First image number of the sequence.\n\ 138 -n <number of images> %u\n\ 139 Number of images to load from the sequence.\n\ 142 Step between two images.\n\ 145 Disable the image display. This can be useful \n\ 146 for automatic tests using crontab under Unix or \n\ 147 using the task manager under Windows.\n\ 150 Wait for a mouse click between two images.\n\ 151 If the image display is disabled (using -d)\n\ 152 this option is without effect.\n\ 155 Print the help.\n\n", ipath.c_str(), ppath.c_str(), first, nimages, step);
158 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
181 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
182 unsigned &step,
bool &display,
bool &wait)
199 first = (unsigned)atoi(optarg_);
202 nimages = (unsigned)atoi(optarg_);
205 step = (unsigned)atoi(optarg_);
211 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
216 usage(argv[0], optarg_, ipath, ppath, first, nimages, step);
222 if ((c == 1) || (c == -1)) {
224 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
225 std::cerr <<
"ERROR: " << std::endl;
226 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
233 int main(
int argc,
const char **argv)
236 std::string env_ipath;
237 std::string opt_ipath;
239 std::string opt_ppath;
241 std::string filename;
242 unsigned opt_first = 0;
243 unsigned opt_nimages = 80;
244 unsigned opt_step = 1;
245 bool opt_display =
true;
246 bool opt_wait =
false;
253 if (!env_ipath.empty())
257 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_display, opt_wait) ==
266 if (!opt_ipath.empty())
271 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
272 if (ipath != env_ipath) {
273 std::cout << std::endl <<
"WARNING: " << std::endl;
274 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 275 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
276 <<
" we skip the environment variable." << std::endl;
281 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
282 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
283 std::cerr << std::endl <<
"ERROR:" << std::endl;
284 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
285 <<
" environment variable to specify the location of the " << std::endl
286 <<
" image path where test images are located." << std::endl
287 <<
" Use -p <personal image path> option if you want to " << std::endl
288 <<
" use personal images." << std::endl
299 unsigned iter = opt_first;
300 std::ostringstream s;
301 char cfilename[FILENAME_MAX];
303 if (opt_ppath.empty()) {
322 s.setf(std::ios::right, std::ios::adjustfield);
323 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
326 sprintf(cfilename, opt_ppath.c_str(), iter);
327 filename = cfilename;
342 std::cerr << std::endl <<
"ERROR:" << std::endl;
343 std::cerr <<
" Cannot read " << filename << std::endl;
344 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
345 <<
" or your -p " << opt_ppath <<
" option " << std::endl
346 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
350 #if defined VISP_HAVE_GTK 352 #elif defined VISP_HAVE_X11 354 #elif defined VISP_HAVE_GDI 361 display.
init(I, 100, 100,
"Display...");
375 while (iter < opt_first + opt_nimages * opt_step) {
380 if (opt_ppath.empty()) {
382 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
385 sprintf(cfilename, opt_ppath.c_str(), iter);
386 filename = cfilename;
389 std::cout <<
"read : " << filename << std::endl;
399 std::cout <<
"A click in the image to continue..." << std::endl;
415 std::cout <<
"Catch an exception: " << e << std::endl;
421 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..." << std::endl;
422 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
423 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
424 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
425 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
VISP_EXPORT int wait(double t0, double t)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void display(const vpImage< unsigned char > &I)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
static void read(vpImage< unsigned char > &I, const std::string &filename)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")