44 #include <visp/vpDebug.h>
45 #include <visp/vpConfig.h>
47 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
49 #include <visp/vpDiskGrabber.h>
50 #include <visp/vpDisplay.h>
51 #include <visp/vpDisplayX.h>
52 #include <visp/vpDisplayGDI.h>
53 #include <visp/vpImage.h>
54 #include <visp/vpIoTools.h>
55 #include <visp/vpParseArgv.h>
56 #include <visp/vpTime.h>
68 #define GETOPTARGS "b:de:f:i:hn:s:z:"
70 void usage(
const char *name,
const char *badparam, std::string ipath, std::string basename,
71 std::string ext,
int first,
unsigned int nimages,
int step,
unsigned int nzero);
72 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &basename,
73 std::string &ext,
int &first,
unsigned int &nimages,
74 int &step,
unsigned int &nzero,
bool &display);
91 void usage(
const char *name,
const char *badparam, std::string ipath, std::string basename,
92 std::string ext,
int first,
unsigned int nimages,
int step,
unsigned int nzero)
95 Read an image sequence from the disk. Display it using X11 or GTK.\n\
96 The sequence is made of separate images. Each image corresponds\n\
100 %s [-i <input image path>] [-b <base name>] [-e <extension>] \n\
101 [-f <first frame>] [-n <number of images> [-s <step>] \n\
102 [-z <number of zero>] [-d] [-h]\n", name);
106 -i <input image path> %s\n\
107 Set image input path.\n\
108 From this path read \"ViSP-images/cube/image.%%04d.pgm\"\n\
110 Setting the VISP_INPUT_IMAGE_PATH environment\n\
111 variable produces the same behaviour than using\n\
115 Specify the base name of the files of the sequence\n\
116 containing the images to process. \n\
117 By image sequence, we mean one file per image.\n\
118 The following image file formats PNM (PGM P5, PPM P6)\n\
119 are supported. The format is selected by analysing \n\
120 the filename extension.\n\
123 Specify the extension of the files.\n\
124 Not taken into account for the moment. Will be a\n\
127 -f <first frame> %u\n\
128 First frame number of the sequence\n\
130 -n <number of images> %u\n\
131 Number of images to load from the sequence.\n\
134 Step between two images.\n\
136 -z <number of zero> %u\n\
137 Number of digits to encode the image number.\n\
140 Turn off the display.\n\
143 Print the help.\n\n",
144 ipath.c_str(), basename.c_str(), ext.c_str(), first,
145 nimages, step, nzero);
148 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
168 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &basename,
169 std::string &ext,
int &first,
unsigned int &nimages,
170 int &step,
unsigned int &nzero,
bool &display)
177 case 'b': basename = optarg_;
break;
178 case 'd': display =
false;
break;
179 case 'e': ext = optarg_;
break;
180 case 'f': first = atoi(optarg_);
break;
181 case 'i': ipath = optarg_;
break;
182 case 'n': nimages = (unsigned) atoi(optarg_);
break;
183 case 's': step = atoi(optarg_);
break;
184 case 'z': nzero = (unsigned) atoi(optarg_);
break;
185 case 'h': usage(argv[0], NULL, ipath, basename, ext, first, nimages,
186 step, nzero);
return false;
break;
189 usage(argv[0], optarg_, ipath, basename, ext, first, nimages, step, nzero);
194 if ((c == 1) || (c == -1)) {
196 usage(argv[0], NULL, ipath, basename, ext, first, nimages, step, nzero);
197 std::cerr <<
"ERROR: " << std::endl;
198 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
215 int main(
int argc,
const char ** argv)
218 std::string env_ipath;
219 std::string opt_ipath;
221 std::string opt_basename =
"ViSP-images/cube/image.";
222 std::string opt_ext =
"pgm";
223 bool opt_display =
true;
226 unsigned int opt_nimages = 70;
228 unsigned int opt_nzero = 4;
234 if (! env_ipath.empty())
238 if (getOptions(argc, argv, opt_ipath, opt_basename, opt_ext, opt_first,
239 opt_nimages, opt_step, opt_nzero, opt_display) ==
false) {
244 if (!opt_ipath.empty())
249 if (!opt_ipath.empty() && !env_ipath.empty()) {
250 if (ipath != env_ipath) {
251 std::cout << std::endl
252 <<
"WARNING: " << std::endl;
253 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
254 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
255 <<
" we skip the environment variable." << std::endl;
260 if (opt_ipath.empty() && env_ipath.empty()){
261 usage(argv[0], NULL, ipath, opt_basename, opt_ext, opt_first,
262 opt_nimages, opt_step, opt_nzero);
263 std::cerr << std::endl
264 <<
"ERROR:" << std::endl;
265 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
267 <<
" environment variable to specify the location of the " << std::endl
268 <<
" image path where test images are located." << std::endl << std::endl;
300 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: "
305 #if defined(VISP_HAVE_X11)
307 #elif defined(VISP_HAVE_GDI)
310 std::cout <<
"No image viewer is available..." << std::endl;
314 display.init(I,100,100,
"Disk Framegrabber");
328 while(cpt ++ < opt_nimages)
346 std::cout <<
"Catch an exception: " << e << std::endl;
355 vpERROR_TRACE(
"You do not have X11 or GTK display functionalities...");
unsigned int getWidth() const
Display for windows using GDI (available on any windows 32 platform).
void setBaseName(const char *name)
Define the X11 console to display images.
error that can be emited by ViSP classes.
void setDirectory(const char *dir)
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)
void setNumberOfZero(unsigned int noz)
static void display(const vpImage< unsigned char > &I)
void setImageNumber(long number)
void open(vpImage< unsigned char > &I)
Class to grab (ie. read) images from the disk.
void setExtension(const char *ext)
unsigned int getHeight() const
void acquire(vpImage< unsigned char > &I)