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;
242 if (! env_ipath.empty())
246 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
247 opt_step, opt_display, opt_wait) ==
false) {
255 if (!opt_ipath.empty())
260 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
261 if (ipath != env_ipath) {
262 std::cout << std::endl
263 <<
"WARNING: " << std::endl;
264 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
265 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
266 <<
" we skip the environment variable." << std::endl;
271 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
272 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
273 std::cerr << std::endl
274 <<
"ERROR:" << std::endl;
275 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
277 <<
" environment variable to specify the location of the " << std::endl
278 <<
" image path where test images are located." << std::endl
279 <<
" Use -p <personal image path> option if you want to "<<std::endl
280 <<
" use personal images." << std::endl
291 unsigned iter = opt_first;
292 std::ostringstream s;
293 char cfilename[FILENAME_MAX];
295 if (opt_ppath.empty()){
315 s.setf(std::ios::right, std::ios::adjustfield);
316 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
320 sprintf(cfilename,opt_ppath.c_str(), iter) ;
321 filename = cfilename;
338 std::cerr << std::endl
339 <<
"ERROR:" << std::endl;
340 std::cerr <<
" Cannot read " << filename << std::endl;
341 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
342 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
343 <<
" or VISP_INPUT_IMAGE_PATH environment variable"
348 #if defined VISP_HAVE_GTK
350 #elif defined VISP_HAVE_X11
352 #elif defined VISP_HAVE_GDI
359 display.
init(I, 100, 100,
"Display...") ;
373 while (iter < opt_first + opt_nimages*opt_step) {
378 if (opt_ppath.empty()){
380 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
384 sprintf(cfilename, opt_ppath.c_str(), iter) ;
385 filename = cfilename;
388 std::cout <<
"read : " << filename << std::endl;
399 std::cout <<
"A click in the image to continue..." << std::endl;
417 std::cout <<
"Catch an exception: " << e << std::endl;
425 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)