52 #include <visp/vpImage.h>
53 #include <visp/vpImageIo.h>
54 #include <visp/vpParseArgv.h>
55 #include <visp/vpIoTools.h>
56 #include <visp/vpDebug.h>
57 #include <visp/vpVideoReader.h>
58 #include <visp/vpDisplayOpenCV.h>
59 #include <visp/vpDisplayX.h>
60 #include <visp/vpDisplayGTK.h>
61 #include <visp/vpDisplayGDI.h>
63 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK)
66 #define GETOPTARGS "cdi:p:f:h"
68 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath);
69 bool getOptions(
int argc,
const char **argv,
70 std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
bool &display);
82 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
85 Read an image sequence on the disk.\n\
88 %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 \"ViSP-images/cube/image.%%04d.pgm\"\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.pgm\"\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 automaze the \n\
113 execution of this program without humain intervention.\n\
116 Turn off the display.\n\
119 Print the help.\n\n",
120 ipath.c_str(), ppath.c_str());
123 fprintf(stderr,
"ERROR: \n" );
124 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
141 bool getOptions(
int argc,
const char **argv,
142 std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
bool &display)
149 case 'c': click_allowed =
false;
break;
150 case 'd': display =
false;
break;
151 case 'i': ipath = optarg_;
break;
152 case 'p': ppath = optarg_;
break;
153 case 'f': first = atoi(optarg_);
break;
154 case 'h': usage(argv[0], NULL, ipath, ppath);
return false;
break;
157 usage(argv[0], optarg_, ipath, ppath);
return false;
break;
161 if ((c == 1) || (c == -1)) {
163 usage(argv[0], NULL, ipath, ppath);
164 std::cerr <<
"ERROR: " << std::endl;
165 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
175 main(
int argc,
const char ** argv)
178 std::string env_ipath;
179 std::string opt_ipath;
181 std::string opt_ppath;
182 std::string filename;
184 bool opt_click_allowed =
true;
185 bool opt_display =
true;
187 std::cout <<
"-------------------------------------------------------" << std::endl ;
188 std::cout <<
" videoImageSequenceReader.cpp" <<std::endl << std::endl ;
190 std::cout <<
" reading an image sequence" << std::endl ;
191 std::cout <<
"-------------------------------------------------------" << std::endl ;
192 std::cout << std::endl ;
195 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
200 if (! env_ipath.empty())
204 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_click_allowed,
205 opt_display) ==
false) {
210 if (!opt_ipath.empty())
215 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
216 if (ipath != env_ipath) {
217 std::cout << std::endl
218 <<
"WARNING: " << std::endl;
219 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
220 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
221 <<
" we skip the environment variable." << std::endl;
226 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()){
227 usage(argv[0], NULL, ipath, opt_ppath);
228 std::cerr << std::endl
229 <<
"ERROR:" << std::endl;
230 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
232 <<
" environment variable to specify the location of the " << std::endl
233 <<
" video path where test images are located." << std::endl << std::endl;
247 if (opt_ppath.empty())
249 filename = ipath +
vpIoTools::path(
"/ViSP-images/mire-2/image.%04d.pgm");
253 filename.assign(opt_ppath);
262 #if defined VISP_HAVE_X11
264 #elif defined VISP_HAVE_GTK
266 #elif defined VISP_HAVE_GDI
268 #elif defined VISP_HAVE_OPENCV
274 display.
init(I, 100, 100,
"Display video frame") ;
280 if (opt_display && opt_click_allowed)
282 std::cout <<
"Click on the image to read and display the second frame" << std::endl;
294 if (opt_display && opt_click_allowed)
296 std::cout <<
"Click on the image to read and display the last frame" << std::endl;
308 if (opt_display && opt_click_allowed)
310 std::cout <<
"Click to see the video" << std::endl;
316 for (
int i = opt_first; i <= lastFrame; i++)
326 if (opt_display && opt_click_allowed)
328 std::cout <<
"Click to exit the test" << std::endl;
335 std::cout <<
"Catch an exception: " << e << std::endl;
342 std::cout <<
"Sorry, no display is available. We quit this example."
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Display for windows using GDI (available on any windows 32 platform).
long getLastFrameIndex() const
Define the X11 console to display images.
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
error that can be emited by ViSP classes.
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void open(vpImage< vpRGBa > &I)
bool getFrame(vpImage< vpRGBa > &I, long frame)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void setFileName(const char *filename)
void setFirstFrameIndex(const long first_frame)
virtual bool getClick(bool blocking=true)=0