44#include <visp3/core/vpConfig.h>
46#if defined(VISP_HAVE_DISPLAY)
48#include <visp3/core/vpImage.h>
49#include <visp3/core/vpIoTools.h>
50#include <visp3/core/vpTime.h>
51#include <visp3/gui/vpDisplayFactory.h>
52#include <visp3/io/vpDiskGrabber.h>
53#include <visp3/io/vpParseArgv.h>
56#define GETOPTARGS "b:de:f:hi:l:s:z:"
58#ifdef ENABLE_VISP_NAMESPACE
75void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &basename,
76 const std::string &ext,
long first,
long last,
long step,
unsigned int nzero)
79Read an image sequence from the disk. Display it using X11 or GTK.\n\
80The sequence is made of separate images. Each image corresponds\n\
84 %s [-i <input image path>] [-b <base name>] [-e <extension>] \n\
85 [-f <first frame>] [-l <last image> [-s <step>] \n\
86 [-z <number of zero>] [-d] [-h]\n", name);
90 -i <input image path> %s\n\
91 Set image input path.\n\
92 From this path read \"cube/image.%%04d.%s\"\n\
94 Setting the VISP_INPUT_IMAGE_PATH environment\n\
95 variable produces the same behaviour than using\n\
99 Specify the base name of the files of the sequence\n\
100 containing the images to process. \n\
101 By image sequence, we mean one file per image.\n\
102 The format is selected by analyzing the filename extension.\n\
105 Specify the extension of the files.\n\
106 Not taken into account for the moment. Will be a\n\
109 -f <first frame> %ld\n\
110 First frame number of the sequence.\n\
112 -l <last image> %ld\n\
113 Last frame number of the sequence.\n\
116 Step between two images.\n\
118 -z <number of zero> %u\n\
119 Number of digits to encode the image number.\n\
122 Turn off the display.\n\
125 Print the help.\n\n",
126 ipath.c_str(), ext.c_str(), basename.c_str(), ext.c_str(), first, last, step, nzero);
129 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
149bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &basename, std::string &ext,
long &first,
150 long &last,
long &step,
unsigned int &nzero,
bool &display)
167 first = atol(optarg_);
173 last = std::atol(optarg_);
176 step = atol(optarg_);
179 nzero =
static_cast<unsigned int>(atoi(optarg_));
182 usage(argv[0],
nullptr, ipath, basename, ext, first, last, step, nzero);
186 usage(argv[0], optarg_, ipath, basename, ext, first, last, step, nzero);
191 if ((c == 1) || (c == -1)) {
193 usage(argv[0],
nullptr, ipath, basename, ext, first, last, step, nzero);
194 std::cerr <<
"ERROR: " << std::endl;
195 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
211int main(
int argc,
const char **argv)
213#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
217 std::string env_ipath;
218 std::string opt_ipath;
220 std::string opt_basename =
"cube/image.";
221#if defined(VISP_HAVE_DATASET)
222#if VISP_HAVE_DATASET_VERSION >= 0x030600
223 std::string opt_ext(
"png");
225 std::string opt_ext(
"pgm");
229 std::string opt_ext(
"png");
232 bool opt_display =
true;
237 unsigned int opt_nzero = 4;
244 if (!env_ipath.empty())
248 if (getOptions(argc, argv, opt_ipath, opt_basename, opt_ext, opt_first, opt_last, opt_step, opt_nzero,
249 opt_display) ==
false) {
254 if (!opt_ipath.empty())
259 if (!opt_ipath.empty() && !env_ipath.empty()) {
260 if (ipath != env_ipath) {
261 std::cout << std::endl <<
"WARNING: " << std::endl;
262 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
263 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
264 <<
" we skip the environment variable." << std::endl;
269 if (opt_ipath.empty() && env_ipath.empty()) {
270 usage(argv[0],
nullptr, ipath, opt_basename, opt_ext, opt_first, opt_last, opt_step, opt_nzero);
271 std::cerr << std::endl <<
"ERROR:" << std::endl;
272 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
273 <<
" environment variable to specify the location of the " << std::endl
274 <<
" image path where test images are located." << std::endl
305 std::cout <<
"Image size: width : " << I.getWidth() <<
" height: " << I.getHeight() << std::endl;
309#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
316 display->init(I, 100, 100,
"Disk Framegrabber");
342#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
343 if (display !=
nullptr) {
350 std::cout <<
"Catch an exception: " <<
e << std::endl;
351#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
352 if (display !=
nullptr) {
363 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface) functionalities to display images..."
365 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
366 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
367 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
368 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) VP_OVERRIDE
void acquire(vpImage< unsigned char > &I) VP_OVERRIDE
void setImageNumber(long number)
void setNumberOfZero(unsigned int noz)
void setBaseName(const std::string &name)
long getImageNumber() const
Class that defines generic functionalities for display.
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
Definition of the vpImage class member functions.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)