55 #include <visp/vpDebug.h>
56 #include <visp/vpConfig.h>
57 #include <visp/vpParseArgv.h>
58 #include <visp/vpIoTools.h>
63 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
65 #include <visp/vpImage.h>
66 #include <visp/vpImageIo.h>
68 #include <visp/vpDisplayGTK.h>
69 #include <visp/vpDisplayX.h>
70 #include <visp/vpDisplayGDI.h>
72 #include <visp/vpTime.h>
85 #define GETOPTARGS "di:p:hf:n:s:w"
87 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
88 unsigned first,
unsigned nimages,
unsigned step);
89 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
90 unsigned &first,
unsigned &nimages,
unsigned &step,
bool &display,
bool &wait);
105 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
106 unsigned first,
unsigned nimages,
unsigned step)
109 Read an image sequence from the disk and display it.\n\
110 The sequence is made of separate images. Each image corresponds\n\
114 %s [-i <test image path>] [-p <personal image path>]\n\
115 [-f <first image>] [-n <number of images>] [-s <step>] \n\
121 -i <test image path> %s\n\
122 Set image input path.\n\
123 From this path read \"ViSP-images/cube/image.%%04d.pgm\"\n\
124 images. These images come from ViSP-images-x.y.z.tar.gz\n\
125 available on the ViSP website.\n\
126 Setting the VISP_INPUT_IMAGE_PATH environment\n\
127 variable produces the same behaviour than using\n\
130 -p <personal image path> %s\n\
131 Specify a personal sequence containing images \n\
133 By image sequence, we mean one file per image.\n\
134 The following image file formats PNM (PGM P5, PPM P6)\n\
135 are supported. The format is selected by analysing \n\
136 the filename extension.\n\
137 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
138 %%04d is for the image numbering.\n\
140 -f <first image> %u\n\
141 First image number of the sequence.\n\
143 -n <number of images> %u\n\
144 Number of images to load from the sequence.\n\
147 Step between two images.\n\
150 Disable the image display. This can be useful \n\
151 for automatic tests using crontab under Unix or \n\
152 using the task manager under Windows.\n\
155 Wait for a mouse click between two images.\n\
156 If the image display is disabled (using -d)\n\
157 this option is without effect.\n\
160 Print the help.\n\n",
161 ipath.c_str(),ppath.c_str(), first, nimages, step);
164 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
187 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
188 unsigned &first,
unsigned &nimages,
unsigned &step,
bool &display,
bool &wait)
195 case 'd': display =
false;
break;
196 case 'i': ipath = optarg_;
break;
197 case 'p': ppath = optarg_;
break;
198 case 'f': first = (unsigned) atoi(optarg_);
break;
199 case 'n': nimages = (unsigned) atoi(optarg_);
break;
200 case 's': step = (unsigned) atoi(optarg_);
break;
201 case 'w': wait =
true;
break;
202 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step);
206 usage(argv[0], optarg_, ipath, ppath, first, nimages, step);
211 if ((c == 1) || (c == -1)) {
213 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
214 std::cerr <<
"ERROR: " << std::endl;
215 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
223 main(
int argc,
const char ** argv)
226 std::string env_ipath;
227 std::string opt_ipath;
229 std::string opt_ppath;
231 std::string filename;
232 unsigned opt_first = 0;
233 unsigned opt_nimages = 80;
234 unsigned opt_step = 1;
235 bool opt_display =
true;
236 bool opt_wait =
false;
239 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
244 if (! env_ipath.empty())
248 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
249 opt_step, opt_display, opt_wait) ==
false) {
257 if (!opt_ipath.empty())
262 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
263 if (ipath != env_ipath) {
264 std::cout << std::endl
265 <<
"WARNING: " << std::endl;
266 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
267 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
268 <<
" we skip the environment variable." << std::endl;
273 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
274 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
275 std::cerr << std::endl
276 <<
"ERROR:" << std::endl;
277 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
279 <<
" environment variable to specify the location of the " << std::endl
280 <<
" image path where test images are located." << std::endl
281 <<
" Use -p <personal image path> option if you want to "<<std::endl
282 <<
" use personal images." << std::endl
293 unsigned iter = opt_first;
294 std::ostringstream s;
295 char cfilename[FILENAME_MAX];
297 if (opt_ppath.empty()){
317 s.setf(std::ios::right, std::ios::adjustfield);
318 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
319 filename = dirname + s.str();
323 sprintf(cfilename,opt_ppath.c_str(), iter) ;
324 filename = cfilename;
341 std::cerr << std::endl
342 <<
"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"
351 #if defined VISP_HAVE_GTK
353 #elif defined VISP_HAVE_X11
355 #elif defined VISP_HAVE_GDI
362 display.
init(I, 100, 100,
"Display...") ;
376 while (iter < opt_first + opt_nimages*opt_step) {
381 if (opt_ppath.empty()){
383 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
384 filename = dirname + s.str();
387 sprintf(cfilename, opt_ppath.c_str(), iter) ;
388 filename = cfilename;
391 std::cout <<
"read : " << filename << std::endl;
402 std::cout <<
"A click in the image to continue..." << std::endl;
420 std::cout <<
"Catch an exception: " << e << std::endl;
428 vpERROR_TRACE(
"You do not have X11 or GTK display functionalities...");
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
error that can be emited by ViSP classes.
static double measureTimeMs()
static int wait(double t0, double t)
static void flush(const vpImage< unsigned char > &I)
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+ library version 1.2.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
virtual bool getClick(bool blocking=true)=0
static void read(vpImage< unsigned char > &I, const char *filename)