46 #include <visp3/core/vpDebug.h>
47 #include <visp3/core/vpImage.h>
48 #include <visp3/core/vpIoTools.h>
49 #include <visp3/gui/vpDisplayGDI.h>
50 #include <visp3/gui/vpDisplayGTK.h>
51 #include <visp3/gui/vpDisplayOpenCV.h>
52 #include <visp3/gui/vpDisplayX.h>
53 #include <visp3/io/vpImageIo.h>
54 #include <visp3/io/vpParseArgv.h>
55 #include <visp3/io/vpVideoReader.h>
57 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK)
60 #define GETOPTARGS "cdi:p:f:h"
62 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath);
63 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
76 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
78 #if VISP_HAVE_DATASET_VERSION >= 0x030600
79 std::string ext(
"png");
81 std::string ext(
"pgm");
84 Read an image sequence on the disk.\n\
87 %s [-i <input images path>] [-p <personal image sequence path>]\n\
94 -i <input images path> %s\n\
95 Set ViSP-images 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\
102 -p <personal image sequence path> %s\n\
103 Specify a personal folder containing an image sequence \n\
105 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
106 %%04d is for the image numbering.\n\
108 -f <index of the first frame> \n\
109 Specify the first image index.\n\
112 Disable the mouse click. Useful to automate the \n\
113 execution of this program without human intervention.\n\
116 Turn off the display.\n\
119 Print the help.\n\n",
120 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str());
123 fprintf(stderr,
"ERROR: \n");
124 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
141 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
150 click_allowed =
false;
162 first = atoi(optarg_);
165 usage(argv[0],
nullptr, ipath, ppath);
170 usage(argv[0], optarg_, ipath, ppath);
176 if ((c == 1) || (c == -1)) {
178 usage(argv[0],
nullptr, ipath, ppath);
179 std::cerr <<
"ERROR: " << std::endl;
180 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
187 int main(
int argc,
const char **argv)
190 std::string env_ipath;
191 std::string opt_ipath;
193 std::string opt_ppath;
194 std::string filename;
196 bool opt_click_allowed =
true;
197 bool opt_display =
true;
199 #if VISP_HAVE_DATASET_VERSION >= 0x030600
200 std::string ext(
"png");
202 std::string ext(
"pgm");
205 std::cout <<
"-------------------------------------------------------" << std::endl;
206 std::cout <<
" videoImageSequenceReader.cpp" << std::endl << std::endl;
208 std::cout <<
" reading an image sequence" << std::endl;
209 std::cout <<
"-------------------------------------------------------" << std::endl;
210 std::cout << std::endl;
217 if (!env_ipath.empty())
221 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_click_allowed, opt_display) ==
false) {
226 if (!opt_ipath.empty())
231 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
232 if (ipath != env_ipath) {
233 std::cout << std::endl <<
"WARNING: " << std::endl;
234 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
235 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
236 <<
" we skip the environment variable." << std::endl;
241 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
242 usage(argv[0],
nullptr, ipath, opt_ppath);
243 std::cerr << std::endl <<
"ERROR:" << std::endl;
244 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
245 <<
" environment variable to specify the location of the " << std::endl
246 <<
" video path where test images are located." << std::endl
260 if (opt_ppath.empty()) {
264 filename.assign(opt_ppath);
271 std::cout <<
"Current image number: " << reader.
getFrameIndex() << std::endl;
273 std::cout <<
"Unable to get requested image number: " << opt_first << std::endl;
278 #if defined(VISP_HAVE_X11)
280 #elif defined(VISP_HAVE_GTK)
282 #elif defined(VISP_HAVE_GDI)
284 #elif defined(HAVE_OPENCV_HIGHGUI)
290 display.init(I, 100, 100,
"Display video frame");
295 if (opt_display && opt_click_allowed) {
296 std::cout <<
"Click in the image to read and display the second frame" << std::endl;
301 std::cout <<
"Current image number (should be " << opt_first + 1 <<
"): " << reader.
getFrameIndex() << std::endl;
303 std::cout <<
"Unable to get requested image number: " << opt_first + 1 << std::endl;
312 if (opt_display && opt_click_allowed) {
313 std::cout <<
"Click on the image to read and display the last frame" << std::endl;
326 if (opt_display && opt_click_allowed) {
327 std::cout <<
"Click to see the video" << std::endl;
333 for (
int i = opt_first; i <= lastFrame; i++) {
335 std::cout <<
"Current image number: " << reader.
getFrameIndex() << std::endl;
342 if (opt_display && opt_click_allowed) {
343 std::cout <<
"Click to exit the test" << std::endl;
350 std::cout <<
"Catch an exception: " << e << std::endl;
357 std::cout <<
"Sorry, no display is available. We quit this example." << std::endl;
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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.
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)
void setFileName(const std::string &filename)
void setFirstFrameIndex(const long first_frame)
bool getFrame(vpImage< vpRGBa > &I, long frame)
long getFrameIndex() const
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.