47 #include <visp3/core/vpConfig.h>
48 #include <visp3/core/vpDebug.h>
49 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
51 #include <visp3/core/vpDisplay.h>
52 #include <visp3/core/vpImage.h>
53 #include <visp3/core/vpIoTools.h>
54 #include <visp3/core/vpTime.h>
55 #include <visp3/gui/vpDisplayGDI.h>
56 #include <visp3/gui/vpDisplayX.h>
57 #include <visp3/io/vpDiskGrabber.h>
58 #include <visp3/io/vpParseArgv.h>
61 #define GETOPTARGS "b:de:f:hi:l:s:z:"
63 #ifdef ENABLE_VISP_NAMESPACE
82 void usage(
const char *name,
const char *badparam, std::string ipath, std::string basename, std::string ext,
long first,
83 long last,
long step,
unsigned int nzero)
86 Read an image sequence from the disk. Display it using X11 or GTK.\n\
87 The sequence is made of separate images. Each image corresponds\n\
91 %s [-i <input image path>] [-b <base name>] [-e <extension>] \n\
92 [-f <first frame>] [-l <last image> [-s <step>] \n\
93 [-z <number of zero>] [-d] [-h]\n",
98 -i <input image path> %s\n\
99 Set image input path.\n\
100 From this path read \"cube/image.%%04d.%s\"\n\
102 Setting the VISP_INPUT_IMAGE_PATH environment\n\
103 variable produces the same behaviour than using\n\
107 Specify the base name of the files of the sequence\n\
108 containing the images to process. \n\
109 By image sequence, we mean one file per image.\n\
110 The format is selected by analysing the filename extension.\n\
113 Specify the extension of the files.\n\
114 Not taken into account for the moment. Will be a\n\
117 -f <first frame> %ld\n\
118 First frame number of the sequence.\n\
120 -l <last image > %ld\n\
121 Last frame number of the sequence.\n\
124 Step between two images.\n\
126 -z <number of zero> %u\n\
127 Number of digits to encode the image number.\n\
130 Turn off the display.\n\
133 Print the help.\n\n",
134 ipath.c_str(), ext.c_str(), basename.c_str(), ext.c_str(), first, last, step, nzero);
137 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
157 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &basename, std::string &ext,
long &first,
158 long &last,
long &step,
unsigned int &nzero,
bool &display)
175 first = atol(optarg_);
181 last = std::atol(optarg_);
184 step = atol(optarg_);
187 nzero = (unsigned)atoi(optarg_);
190 usage(argv[0],
nullptr, ipath, basename, ext, first, last, step, nzero);
195 usage(argv[0], optarg_, ipath, basename, ext, first, last, step, nzero);
201 if ((c == 1) || (c == -1)) {
203 usage(argv[0],
nullptr, ipath, basename, ext, first, last, step, nzero);
204 std::cerr <<
"ERROR: " << std::endl;
205 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
221 int main(
int argc,
const char **argv)
224 std::string env_ipath;
225 std::string opt_ipath;
227 std::string opt_basename =
"cube/image.";
228 #if VISP_HAVE_DATASET_VERSION >= 0x030600
229 std::string opt_ext(
"png");
231 std::string opt_ext(
"pgm");
234 bool opt_display =
true;
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_last, 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],
nullptr, ipath, opt_basename, opt_ext, opt_first, opt_last, 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)
312 vpDisplayX display(I);
313 #elif defined(VISP_HAVE_GDI)
316 std::cout <<
"No image viewer is available..." << std::endl;
320 display.init(I, 100, 100,
"Disk Framegrabber");
349 std::cout <<
"Catch an exception: " << e << std::endl;
357 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface) functionalities to display images..."
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;
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).
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)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()