41 #include <visp3/core/vpConfig.h> 42 #include <visp3/core/vpDebug.h> 43 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) 45 #include <visp3/core/vpDisplay.h> 46 #include <visp3/core/vpImage.h> 47 #include <visp3/core/vpIoTools.h> 48 #include <visp3/core/vpTime.h> 49 #include <visp3/gui/vpDisplayGDI.h> 50 #include <visp3/gui/vpDisplayX.h> 51 #include <visp3/io/vpDiskGrabber.h> 52 #include <visp3/io/vpParseArgv.h> 65 #define GETOPTARGS "b:de:f:i:hn:s:z:" 67 void usage(
const char *name,
const char *badparam, std::string ipath, std::string basename, std::string ext,
int first,
68 unsigned int nimages,
int step,
unsigned int nzero);
69 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &basename, std::string &ext,
int &first,
70 unsigned int &nimages,
int &step,
unsigned int &nzero,
bool &display);
87 void usage(
const char *name,
const char *badparam, std::string ipath, std::string basename, std::string ext,
int first,
88 unsigned int nimages,
int step,
unsigned int nzero)
91 Read an image sequence from the disk. Display it using X11 or GTK.\n\ 92 The sequence is made of separate images. Each image corresponds\n\ 96 %s [-i <input image path>] [-b <base name>] [-e <extension>] \n\ 97 [-f <first frame>] [-n <number of images> [-s <step>] \n\ 98 [-z <number of zero>] [-d] [-h]\n", name);
102 -i <input image path> %s\n\ 103 Set image input path.\n\ 104 From this path read \"cube/image.%%04d.pgm\"\n\ 106 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 107 variable produces the same behaviour than using\n\ 111 Specify the base name of the files of the sequence\n\ 112 containing the images to process. \n\ 113 By image sequence, we mean one file per image.\n\ 114 The following image file formats PNM (PGM P5, PPM P6)\n\ 115 are supported. The format is selected by analysing \n\ 116 the filename extension.\n\ 119 Specify the extension of the files.\n\ 120 Not taken into account for the moment. Will be a\n\ 123 -f <first frame> %d\n\ 124 First frame number of the sequence\n\ 126 -n <number of images> %u\n\ 127 Number of images to load from the sequence.\n\ 130 Step between two images.\n\ 132 -z <number of zero> %u\n\ 133 Number of digits to encode the image number.\n\ 136 Turn off the display.\n\ 139 Print the help.\n\n", ipath.c_str(), basename.c_str(), ext.c_str(), first, nimages, step, nzero);
142 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
162 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &basename, std::string &ext,
int &first,
163 unsigned int &nimages,
int &step,
unsigned int &nzero,
bool &display)
180 first = atoi(optarg_);
186 nimages = (unsigned)atoi(optarg_);
189 step = atoi(optarg_);
192 nzero = (unsigned)atoi(optarg_);
195 usage(argv[0], NULL, ipath, basename, ext, first, nimages, step, nzero);
200 usage(argv[0], optarg_, ipath, basename, ext, first, nimages, step, nzero);
206 if ((c == 1) || (c == -1)) {
208 usage(argv[0], NULL, ipath, basename, ext, first, nimages, step, nzero);
209 std::cerr <<
"ERROR: " << std::endl;
210 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
226 int main(
int argc,
const char **argv)
229 std::string env_ipath;
230 std::string opt_ipath;
232 std::string opt_basename =
"cube/image.";
233 std::string opt_ext =
"pgm";
234 bool opt_display =
true;
237 unsigned int opt_nimages = 70;
239 unsigned int opt_nzero = 4;
246 if (!env_ipath.empty())
250 if (getOptions(argc, argv, opt_ipath, opt_basename, opt_ext, opt_first, opt_nimages, opt_step, opt_nzero,
251 opt_display) ==
false) {
256 if (!opt_ipath.empty())
261 if (!opt_ipath.empty() && !env_ipath.empty()) {
262 if (ipath != env_ipath) {
263 std::cout << std::endl <<
"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()) {
272 usage(argv[0], NULL, ipath, opt_basename, opt_ext, opt_first, opt_nimages, opt_step, opt_nzero);
273 std::cerr << std::endl <<
"ERROR:" << std::endl;
274 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
275 <<
" environment variable to specify the location of the " << std::endl
276 <<
" image path where test images are located." << std::endl
307 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: " << I.
getHeight() << std::endl;
311 #if defined(VISP_HAVE_X11) 313 #elif defined(VISP_HAVE_GDI) 316 std::cout <<
"No image viewer is available..." << std::endl;
320 display.init(I, 100, 100,
"Disk Framegrabber");
334 while (cpt++ < opt_nimages) {
350 std::cout <<
"Catch an exception: " << e << std::endl;
358 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface) functionalities to display images..." << std::endl;
359 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
360 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
361 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
362 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
VISP_EXPORT int wait(double t0, double t)
unsigned int getWidth() const
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
void setDirectory(const std::string &dir)
void setBaseName(const std::string &name)
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void setExtension(const std::string &ext)
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.
unsigned int getHeight() const
void acquire(vpImage< unsigned char > &I)