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/vpImage.h>
51 #include <visp/vpDisplay.h>
52 #include <visp/vpDisplayX.h>
53 #include <visp/vpDisplayGDI.h>
54 #include <visp/vpTime.h>
55 #include <visp/vpParseArgv.h>
67 #define GETOPTARGS "b:de:f:i:hn:s:z:"
69 void usage(
const char *name,
const char *badparam, std::string ipath, std::string basename,
70 std::string ext,
int first,
unsigned int nimages,
int step,
unsigned int nzero);
71 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &basename,
72 std::string &ext,
int &first,
unsigned int &nimages,
73 int &step,
unsigned int &nzero,
bool &display);
90 void usage(
const char *name,
const char *badparam, std::string ipath, std::string basename,
91 std::string ext,
int first,
unsigned int nimages,
int step,
unsigned int nzero)
94 Read an image sequence from the disk. Display it using X11 or GTK.\n\
95 The sequence is made of separate images. Each image corresponds\n\
99 %s [-i <input image path>] [-b <base name>] [-e <extension>] \n\
100 [-f <first frame>] [-n <number of images> [-s <step>] \n\
101 [-z <number of zero>] [-d] [-h]\n", name);
105 -i <input image path> %s\n\
106 Set image input path.\n\
107 From this path read \"ViSP-images/cube/image.%%04d.pgm\"\n\
109 Setting the VISP_INPUT_IMAGE_PATH environment\n\
110 variable produces the same behaviour than using\n\
114 Specify the base name of the files of the sequence\n\
115 containing the images to process. \n\
116 By image sequence, we mean one file per image.\n\
117 The following image file formats PNM (PGM P5, PPM P6)\n\
118 are supported. The format is selected by analysing \n\
119 the filename extension.\n\
122 Specify the extension of the files.\n\
123 Not taken into account for the moment. Will be a\n\
126 -f <first frame> %u\n\
127 First frame number of the sequence\n\
129 -n <number of images> %u\n\
130 Number of images to load from the sequence.\n\
133 Step between two images.\n\
135 -z <number of zero> %u\n\
136 Number of digits to encode the image number.\n\
139 Turn off the display.\n\
142 Print the help.\n\n",
143 ipath.c_str(), basename.c_str(), ext.c_str(), first,
144 nimages, step, nzero);
147 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
167 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &basename,
168 std::string &ext,
int &first,
unsigned int &nimages,
169 int &step,
unsigned int &nzero,
bool &display)
176 case 'b': basename = optarg_;
break;
177 case 'd': display =
false;
break;
178 case 'e': ext = optarg_;
break;
179 case 'f': first = atoi(optarg_);
break;
180 case 'i': ipath = optarg_;
break;
181 case 'n': nimages = (unsigned) atoi(optarg_);
break;
182 case 's': step = atoi(optarg_);
break;
183 case 'z': nzero = (unsigned) atoi(optarg_);
break;
184 case 'h': usage(argv[0], NULL, ipath, basename, ext, first, nimages,
185 step, nzero);
return false;
break;
188 usage(argv[0], optarg_, ipath, basename, ext, first, nimages, step, nzero);
193 if ((c == 1) || (c == -1)) {
195 usage(argv[0], NULL, ipath, basename, ext, first, nimages, step, nzero);
196 std::cerr <<
"ERROR: " << std::endl;
197 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
214 int main(
int argc,
const char ** argv)
217 std::string env_ipath;
218 std::string opt_ipath;
220 std::string opt_basename =
"ViSP-images/cube/image.";
221 std::string opt_ext =
"pgm";
222 bool opt_display =
true;
225 unsigned int opt_nimages = 70;
227 unsigned int opt_nzero = 4;
230 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
235 if (! env_ipath.empty())
239 if (getOptions(argc, argv, opt_ipath, opt_basename, opt_ext, opt_first,
240 opt_nimages, opt_step, opt_nzero, opt_display) ==
false) {
245 if (!opt_ipath.empty())
250 if (!opt_ipath.empty() && !env_ipath.empty()) {
251 if (ipath != env_ipath) {
252 std::cout << std::endl
253 <<
"WARNING: " << std::endl;
254 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
255 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
256 <<
" we skip the environment variable." << std::endl;
261 if (opt_ipath.empty() && env_ipath.empty()){
262 usage(argv[0], NULL, ipath, opt_basename, opt_ext, opt_first,
263 opt_nimages, opt_step, opt_nzero);
264 std::cerr << std::endl
265 <<
"ERROR:" << std::endl;
266 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
268 <<
" environment variable to specify the location of the " << std::endl
269 <<
" image path where test images are located." << std::endl << std::endl;
301 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: "
306 #if defined(VISP_HAVE_X11)
308 #elif defined(VISP_HAVE_GDI)
311 std::cout <<
"No image viewer is available..." << std::endl;
315 display.init(I,100,100,
"Disk Framegrabber");
329 while(cpt ++ < opt_nimages)
347 std::cout <<
"Catch an exception: " << e << std::endl;
356 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)