37 #include <visp3/core/vpConfig.h>
38 #include <visp3/core/vpDebug.h>
39 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
41 #include <visp3/core/vpDisplay.h>
42 #include <visp3/core/vpImage.h>
43 #include <visp3/core/vpIoTools.h>
44 #include <visp3/core/vpTime.h>
45 #include <visp3/gui/vpDisplayGDI.h>
46 #include <visp3/gui/vpDisplayX.h>
47 #include <visp3/io/vpDiskGrabber.h>
48 #include <visp3/io/vpParseArgv.h>
61 #define GETOPTARGS "b:de:f:hi:l:s:z:"
78 void usage(
const char *name,
const char *badparam, std::string ipath, std::string basename, std::string ext,
long first,
79 long last,
long step,
unsigned int nzero)
82 Read an image sequence from the disk. Display it using X11 or GTK.\n\
83 The sequence is made of separate images. Each image corresponds\n\
87 %s [-i <input image path>] [-b <base name>] [-e <extension>] \n\
88 [-f <first frame>] [-l <last image> [-s <step>] \n\
89 [-z <number of zero>] [-d] [-h]\n",
94 -i <input image path> %s\n\
95 Set image input path.\n\
96 From this path read \"cube/image.%%04d.%s\"\n\
98 Setting the VISP_INPUT_IMAGE_PATH environment\n\
99 variable produces the same behaviour than using\n\
103 Specify the base name of the files of the sequence\n\
104 containing the images to process. \n\
105 By image sequence, we mean one file per image.\n\
106 The format is selected by analysing the filename extension.\n\
109 Specify the extension of the files.\n\
110 Not taken into account for the moment. Will be a\n\
113 -f <first frame> %ld\n\
114 First frame number of the sequence.\n\
116 -l <last image > %ld\n\
117 Last frame number of the sequence.\n\
120 Step between two images.\n\
122 -z <number of zero> %u\n\
123 Number of digits to encode the image number.\n\
126 Turn off the display.\n\
129 Print the help.\n\n",
130 ipath.c_str(), ext.c_str(), basename.c_str(), ext.c_str(), first, last, step, nzero);
133 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
153 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &basename, std::string &ext,
long &first,
154 long &last,
long &step,
unsigned int &nzero,
bool &display)
171 first = atol(optarg_);
177 last = std::atol(optarg_);
180 step = atol(optarg_);
183 nzero = (unsigned)atoi(optarg_);
186 usage(argv[0],
nullptr, ipath, basename, ext, first, last, step, nzero);
191 usage(argv[0], optarg_, ipath, basename, ext, first, last, step, nzero);
197 if ((c == 1) || (c == -1)) {
199 usage(argv[0],
nullptr, ipath, basename, ext, first, last, step, nzero);
200 std::cerr <<
"ERROR: " << std::endl;
201 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
217 int main(
int argc,
const char **argv)
220 std::string env_ipath;
221 std::string opt_ipath;
223 std::string opt_basename =
"cube/image.";
224 #if VISP_HAVE_DATASET_VERSION >= 0x030600
225 std::string opt_ext(
"png");
227 std::string opt_ext(
"pgm");
230 bool opt_display =
true;
235 unsigned int opt_nzero = 4;
242 if (!env_ipath.empty())
246 if (getOptions(argc, argv, opt_ipath, opt_basename, opt_ext, opt_first, opt_last, opt_step, opt_nzero,
247 opt_display) ==
false) {
252 if (!opt_ipath.empty())
257 if (!opt_ipath.empty() && !env_ipath.empty()) {
258 if (ipath != env_ipath) {
259 std::cout << std::endl <<
"WARNING: " << std::endl;
260 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
261 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
262 <<
" we skip the environment variable." << std::endl;
267 if (opt_ipath.empty() && env_ipath.empty()) {
268 usage(argv[0],
nullptr, ipath, opt_basename, opt_ext, opt_first, opt_last, opt_step, opt_nzero);
269 std::cerr << std::endl <<
"ERROR:" << std::endl;
270 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
271 <<
" environment variable to specify the location of the " << std::endl
272 <<
" image path where test images are located." << std::endl
303 std::cout <<
"Image size: width : " << I.
getWidth() <<
" height: " << I.
getHeight() << std::endl;
307 #if defined(VISP_HAVE_X11)
309 #elif defined(VISP_HAVE_GDI)
312 std::cout <<
"No image viewer is available..." << std::endl;
316 display.init(I, 100, 100,
"Disk Framegrabber");
345 std::cout <<
"Catch an exception: " << e << std::endl;
353 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface) functionalities to display images..."
355 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
356 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
357 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
358 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
Class to grab (ie. read) images from the disk.
void setDirectory(const std::string &dir)
void setExtension(const std::string &ext)
void open(vpImage< unsigned char > &I)
void setImageNumber(long number)
void setNumberOfZero(unsigned int noz)
void setBaseName(const std::string &name)
long getImageNumber() const
void acquire(vpImage< unsigned char > &I)
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...
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
unsigned int getWidth() const
unsigned int getHeight() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()