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"
78 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
81 Read an image sequence on the disk.\n\
84 %s [-i <input images path>] [-p <personal image sequence path>]\n\
90 -i <input images path> %s\n\
91 Set ViSP-images input path.\n\
92 From this path read \"ViSP-images/cube/image.%%04d.pgm\"\n\
94 Setting the VISP_INPUT_IMAGE_PATH environment\n\
95 variable produces the same behaviour than using\n\
98 -p <personal image sequence path> %s\n\
99 Specify a personal folder containing an image sequence \n\
101 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
102 %%04d is for the image numbering.\n\
104 -f <index of the first frame> \n\
105 Specify the first image index.\n\
108 Disable the mouse click. Useful to automaze the \n\
109 execution of this program without humain intervention.\n\
112 Turn off the display.\n\
115 Print the help.\n\n",
116 ipath.c_str(), ppath.c_str());
119 fprintf(stderr,
"ERROR: \n" );
120 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
137 bool getOptions(
int argc,
const char **argv,
138 std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
bool &display)
145 case 'c': click_allowed =
false;
break;
146 case 'd': display =
false;
break;
147 case 'i': ipath = optarg;
break;
148 case 'p': ppath = optarg;
break;
149 case 'f': first = atoi(optarg);
break;
150 case 'h': usage(argv[0], NULL, ipath, ppath);
return false;
break;
153 usage(argv[0], optarg, ipath, ppath);
return false;
break;
157 if ((c == 1) || (c == -1)) {
159 usage(argv[0], NULL, ipath, ppath);
160 std::cerr <<
"ERROR: " << std::endl;
161 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
171 main(
int argc,
const char ** argv)
174 std::string env_ipath;
175 std::string opt_ipath;
177 std::string opt_ppath;
178 std::string filename;
180 bool opt_click_allowed =
true;
181 bool opt_display =
true;
183 std::cout <<
"-------------------------------------------------------" << std::endl ;
184 std::cout <<
" videoImageSequenceReader.cpp" <<std::endl << std::endl ;
186 std::cout <<
" reading an image sequence" << std::endl ;
187 std::cout <<
"-------------------------------------------------------" << std::endl ;
188 std::cout << std::endl ;
192 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
197 if (! env_ipath.empty())
201 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_click_allowed,
202 opt_display) ==
false) {
207 if (!opt_ipath.empty())
212 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
213 if (ipath != env_ipath) {
214 std::cout << std::endl
215 <<
"WARNING: " << std::endl;
216 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
217 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
218 <<
" we skip the environment variable." << std::endl;
223 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()){
224 usage(argv[0], NULL, ipath, opt_ppath);
225 std::cerr << std::endl
226 <<
"ERROR:" << std::endl;
227 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
229 <<
" environment variable to specify the location of the " << std::endl
230 <<
" video path where test images are located." << std::endl << std::endl;
244 if (opt_ppath.empty())
246 filename = ipath +
vpIoTools::path(
"/ViSP-images/mire-2/image.%04d.pgm");
250 filename.assign(opt_ppath);
259 #if defined VISP_HAVE_X11
261 #elif defined VISP_HAVE_GTK
263 #elif defined VISP_HAVE_GDI
265 #elif defined VISP_HAVE_OPENCV
274 display.
init(I, 100, 100,
"Display video frame") ;
285 if (opt_display && opt_click_allowed)
287 std::cout <<
"Click on the image to read and display the second frame" << std::endl;
299 if (opt_display && opt_click_allowed)
301 std::cout <<
"Click on the image to read and display the last frame" << std::endl;
313 if (opt_display && opt_click_allowed)
315 std::cout <<
"Click to see the video" << std::endl;
321 for (
int i = opt_first; i <= lastFrame; i++)
331 if (opt_display && opt_click_allowed)
333 std::cout <<
"Click to exit the test" << std::endl;
342 std::cout <<
"Sorry, no display is available. We quit this example."
void setFirstFrameIndex(const long firstFrame)
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...
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)
virtual bool getClick(bool blocking=true)=0