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"
100 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
101 unsigned first,
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 \"ViSP-images/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",
156 ipath.c_str(),ppath.c_str(), first, nimages, step);
159 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
182 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
183 unsigned &first,
unsigned &nimages,
unsigned &step,
184 bool &display,
bool &wait)
191 case 'd': display =
false;
break;
192 case 'i': ipath = optarg;
break;
193 case 'p': ppath = optarg;
break;
194 case 'f': first = (unsigned) atoi(optarg);
break;
195 case 'n': nimages = (unsigned) atoi(optarg);
break;
196 case 's': step = (unsigned) atoi(optarg);
break;
197 case 'w': wait =
true;
break;
198 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step);
202 usage(argv[0], optarg, ipath, ppath, first, nimages, step);
207 if ((c == 1) || (c == -1)) {
209 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
210 std::cerr <<
"ERROR: " << std::endl;
211 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
219 main(
int argc,
const char ** argv)
221 std::string env_ipath;
222 std::string opt_ipath;
224 std::string opt_ppath;
226 std::string filename;
227 unsigned opt_first = 0;
228 unsigned opt_nimages = 80;
229 unsigned opt_step = 1;
230 bool opt_display =
true;
231 bool opt_wait =
false;
234 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
239 if (! env_ipath.empty())
243 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
244 opt_step, opt_display, opt_wait) ==
false) {
252 if (!opt_ipath.empty())
257 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
258 if (ipath != env_ipath) {
259 std::cout << std::endl
260 <<
"WARNING: " << std::endl;
261 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
262 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
263 <<
" we skip the environment variable." << std::endl;
268 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
269 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
270 std::cerr << std::endl
271 <<
"ERROR:" << std::endl;
272 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
274 <<
" environment variable to specify the location of the " << std::endl
275 <<
" image path where test images are located." << std::endl
276 <<
" Use -p <personal image path> option if you want to "<<std::endl
277 <<
" use personal images." << std::endl
288 unsigned iter = opt_first;
289 std::ostringstream s;
290 char cfilename[FILENAME_MAX];
292 if (opt_ppath.empty()){
312 s.setf(std::ios::right, std::ios::adjustfield);
313 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
314 filename = dirname + s.str();
318 sprintf(cfilename,opt_ppath.c_str(), iter) ;
319 filename = cfilename;
336 std::cerr << std::endl
337 <<
"ERROR:" << std::endl;
338 std::cerr <<
" Cannot read " << filename << std::endl;
339 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
340 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
341 <<
" or VISP_INPUT_IMAGE_PATH environment variable"
346 #if defined VISP_HAVE_GTK
348 #elif defined VISP_HAVE_X11
350 #elif defined VISP_HAVE_GDI
357 display.
init(I, 100, 100,
"Display...") ;
376 while (iter < opt_first + opt_nimages*opt_step) {
382 if (opt_ppath.empty()){
384 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
385 filename = dirname + s.str();
388 sprintf(cfilename, opt_ppath.c_str(), iter) ;
389 filename = cfilename;
392 std::cout <<
"read : " << filename << std::endl;
403 std::cout <<
"A click in the image to continue..." << std::endl;
427 vpERROR_TRACE(
"You do not have X11 or GTK display functionalities...");