44#include <visp3/core/vpConfig.h>
45#include <visp3/core/vpDebug.h>
46#include <visp3/core/vpImage.h>
47#include <visp3/core/vpIoTools.h>
48#include <visp3/gui/vpDisplayFactory.h>
49#include <visp3/io/vpImageIo.h>
50#include <visp3/io/vpParseArgv.h>
51#include <visp3/io/vpVideoReader.h>
53#if defined(VISP_HAVE_DISPLAY)
56#define GETOPTARGS "cdi:p:f:h"
58#ifdef ENABLE_VISP_NAMESPACE
62void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath);
63bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
76void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath)
78#if defined(VISP_HAVE_DATASET)
79#if VISP_HAVE_DATASET_VERSION >= 0x030600
80 std::string ext(
"png");
82 std::string ext(
"pgm");
86 std::string ext(
"png");
89Read an image sequence on the disk.\n\
92 %s [-i <input images path>] [-p <personal image sequence path>]\n\
99 -i <input images path> %s\n\
100 Set ViSP-images input path.\n\
101 From this path read \"cube/image.%%04d.%s\"\n\
103 Setting the VISP_INPUT_IMAGE_PATH environment\n\
104 variable produces the same behaviour than using\n\
107 -p <personal image sequence path> %s\n\
108 Specify a personal folder containing an image sequence \n\
110 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
111 %%04d is for the image numbering.\n\
113 -f <index of the first frame> \n\
114 Specify the first image index.\n\
117 Disable the mouse click. Useful to automate the \n\
118 execution of this program without human intervention.\n\
121 Turn off the display.\n\
124 Print the help.\n\n",
125 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str());
128 fprintf(stderr,
"ERROR: \n");
129 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
146bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
155 click_allowed =
false;
167 first = atoi(optarg_);
170 usage(argv[0],
nullptr, ipath, ppath);
174 usage(argv[0], optarg_, ipath, ppath);
179 if ((c == 1) || (c == -1)) {
181 usage(argv[0],
nullptr, ipath, ppath);
182 std::cerr <<
"ERROR: " << std::endl;
183 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
190int main(
int argc,
const char **argv)
192#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
193 std::shared_ptr<vpDisplay> display;
198 std::string env_ipath;
199 std::string opt_ipath;
201 std::string opt_ppath;
204 bool opt_click_allowed =
true;
205 bool opt_display =
true;
207#if defined(VISP_HAVE_DATASET)
208#if VISP_HAVE_DATASET_VERSION >= 0x030600
209 std::string ext(
"png");
211 std::string ext(
"pgm");
215 std::string ext(
"png");
218 std::cout <<
"-------------------------------------------------------" << std::endl;
219 std::cout <<
" videoImageSequenceReader.cpp" << std::endl << std::endl;
221 std::cout <<
" reading an image sequence" << std::endl;
222 std::cout <<
"-------------------------------------------------------" << std::endl;
223 std::cout << std::endl;
230 if (!env_ipath.empty())
234 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_click_allowed, opt_display) ==
false) {
239 if (!opt_ipath.empty())
244 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
245 if (ipath != env_ipath) {
246 std::cout << std::endl <<
"WARNING: " << std::endl;
247 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
248 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
249 <<
" we skip the environment variable." << std::endl;
254 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
255 usage(argv[0],
nullptr, ipath, opt_ppath);
256 std::cerr << std::endl <<
"ERROR:" << std::endl;
257 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
258 <<
" environment variable to specify the location of the " << std::endl
259 <<
" video path where test images are located." << std::endl
273 if (opt_ppath.empty()) {
284 std::cout <<
"Current image number: " << reader.
getFrameIndex() << std::endl;
286 std::cout <<
"Unable to get requested image number: " << opt_first << std::endl;
292#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
301 if (opt_display && opt_click_allowed) {
302 std::cout <<
"Click in the image to read and display the second frame" << std::endl;
307 std::cout <<
"Current image number (should be " << opt_first + 1 <<
"): " << reader.
getFrameIndex() << std::endl;
309 std::cout <<
"Unable to get requested image number: " << opt_first + 1 << std::endl;
310#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
311 if (display !=
nullptr) {
323 if (opt_display && opt_click_allowed) {
324 std::cout <<
"Click on the image to read and display the last frame" << std::endl;
337 if (opt_display && opt_click_allowed) {
338 std::cout <<
"Click to see the video" << std::endl;
344 for (
int i = opt_first;
i <= lastFrame;
i++) {
346 std::cout <<
"Current image number: " << reader.
getFrameIndex() << std::endl;
353 if (opt_display && opt_click_allowed) {
354 std::cout <<
"Click to exit the test" << std::endl;
358#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
359 if (display !=
nullptr) {
366 std::cout <<
"Catch an exception: " <<
e << std::endl;
367#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
368 if (display !=
nullptr) {
378 std::cout <<
"Sorry, no display is available. We quit this example." << std::endl;
Class that defines generic functionalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void open(vpImage< vpRGBa > &I) VP_OVERRIDE
void setFileName(const std::string &filename)
void setFirstFrameIndex(const long first_frame)
bool getFrame(vpImage< vpRGBa > &I, long frame)
long getFrameIndex() const
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.