52 #include <visp/vpConfig.h>
53 #include <visp/vpImage.h>
54 #include <visp/vpImageIo.h>
55 #include <visp/vpParseArgv.h>
56 #include <visp/vpIoTools.h>
57 #include <visp/vpDebug.h>
58 #include <visp/vpVideoReader.h>
59 #include <visp/vpDisplayOpenCV.h>
60 #include <visp/vpDisplayX.h>
61 #include <visp/vpDisplayGTK.h>
62 #include <visp/vpDisplayGDI.h>
64 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK)
67 #define GETOPTARGS "cdi:p:h"
69 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath);
70 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
71 bool &click_allowed,
bool &display);
83 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
86 Read a video file on the disk.\n\
89 %s [-i <input video path>] \n\
95 -i <input video path> %s\n\
96 Set video input path.\n\
97 From this path read \"ViSP-images/video/video.mpeg\"\n\
99 Setting the VISP_INPUT_IMAGE_PATH environment\n\
100 variable produces the same behaviour than using\n\
103 -p <personal video path> %s\n\
104 Specify a personal folder containing a video \n\
106 Example : \"/Temp/ViSP-images/video/video.mpeg\"\n\
109 Disable the mouse click. Useful to automaze the \n\
110 execution of this program without humain intervention.\n\
113 Turn off the display.\n\
116 Print the help.\n\n",
117 ipath.c_str(), ppath.c_str());
120 fprintf(stderr,
"ERROR: \n" );
121 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
137 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
138 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 'h': usage(argv[0], NULL, ipath, ppath);
return false;
break;
152 usage(argv[0], optarg_, ipath, ppath);
return false;
break;
156 if ((c == 1) || (c == -1)) {
158 usage(argv[0], NULL, ipath, ppath);
159 std::cerr <<
"ERROR: " << std::endl;
160 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
170 main(
int argc,
const char ** argv)
173 std::string env_ipath;
174 std::string opt_ipath;
176 std::string opt_ppath;
177 std::string filename;
178 bool opt_click_allowed =
true;
179 bool opt_display =
true;
181 std::cout <<
"-------------------------------------------------------" << std::endl ;
182 std::cout <<
" videoReader.cpp" <<std::endl << std::endl ;
184 std::cout <<
" reading a video file" << std::endl ;
185 std::cout <<
"-------------------------------------------------------" << std::endl ;
186 std::cout << std::endl ;
190 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
195 if (! env_ipath.empty())
199 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed,
200 opt_display) ==
false) {
205 if (!opt_ipath.empty())
210 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
211 if (ipath != env_ipath) {
212 std::cout << std::endl
213 <<
"WARNING: " << std::endl;
214 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
215 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
216 <<
" we skip the environment variable." << std::endl;
221 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()){
222 usage(argv[0], NULL, ipath, opt_ppath);
223 std::cerr << std::endl
224 <<
"ERROR:" << std::endl;
225 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
227 <<
" environment variable to specify the location of the " << std::endl
228 <<
" video path where test images are located." << std::endl << std::endl;
242 if (opt_ppath.empty())
248 filename.assign(opt_ppath);
256 #if defined VISP_HAVE_X11
258 #elif defined VISP_HAVE_GTK
260 #elif defined VISP_HAVE_GDI
262 #elif defined VISP_HAVE_OPENCV
268 display.
init(I, 100, 100,
"Display video frame") ;
287 if (opt_display && opt_click_allowed)
289 std::cout <<
"Click to see the video" << std::endl;
297 for (
int i = 0; i <= lastFrame; i++)
307 if (opt_display && opt_click_allowed)
309 std::cout <<
"Click to exit the test" << std::endl;
314 std::cout <<
"Catch an exception: " << e << std::endl;
321 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 acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
virtual bool getClick(bool blocking=true)=0