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"
79 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
82 Read a video file on the disk.\n\
85 %s [-i <input video path>] \n\
91 -i <input video path> %s\n\
92 Set video input path.\n\
93 From this path read \"ViSP-images/video/video.mpeg\"\n\
95 Setting the VISP_INPUT_IMAGE_PATH environment\n\
96 variable produces the same behaviour than using\n\
99 -p <personal video path> %s\n\
100 Specify a personal folder containing a video \n\
102 Example : \"/Temp/ViSP-images/video/video.mpeg\"\n\
105 Disable the mouse click. Useful to automaze the \n\
106 execution of this program without humain intervention.\n\
109 Turn off the display.\n\
112 Print the help.\n\n",
113 ipath.c_str(), ppath.c_str());
116 fprintf(stderr,
"ERROR: \n" );
117 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
133 bool getOptions(
int argc,
const char **argv,
134 std::string &ipath, std::string &ppath,
bool &click_allowed,
bool &display)
141 case 'c': click_allowed =
false;
break;
142 case 'd': display =
false;
break;
143 case 'i': ipath = optarg;
break;
144 case 'p': ppath = optarg;
break;
145 case 'h': usage(argv[0], NULL, ipath, ppath);
return false;
break;
148 usage(argv[0], optarg, ipath, ppath);
return false;
break;
152 if ((c == 1) || (c == -1)) {
154 usage(argv[0], NULL, ipath, ppath);
155 std::cerr <<
"ERROR: " << std::endl;
156 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
166 main(
int argc,
const char ** argv)
169 std::string env_ipath;
170 std::string opt_ipath;
172 std::string opt_ppath;
173 std::string filename;
174 bool opt_click_allowed =
true;
175 bool opt_display =
true;
177 std::cout <<
"-------------------------------------------------------" << std::endl ;
178 std::cout <<
" videoReader.cpp" <<std::endl << std::endl ;
180 std::cout <<
" reading a video file" << std::endl ;
181 std::cout <<
"-------------------------------------------------------" << std::endl ;
182 std::cout << std::endl ;
186 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
191 if (! env_ipath.empty())
195 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed,
196 opt_display) ==
false) {
201 if (!opt_ipath.empty())
206 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
207 if (ipath != env_ipath) {
208 std::cout << std::endl
209 <<
"WARNING: " << std::endl;
210 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
211 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
212 <<
" we skip the environment variable." << std::endl;
217 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()){
218 usage(argv[0], NULL, ipath, opt_ppath);
219 std::cerr << std::endl
220 <<
"ERROR:" << std::endl;
221 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
223 <<
" environment variable to specify the location of the " << std::endl
224 <<
" video path where test images are located." << std::endl << std::endl;
238 if (opt_ppath.empty())
244 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") ;
299 if (opt_display && opt_click_allowed)
301 std::cout <<
"Click to see the video" << std::endl;
309 for (
int i = 0; i <= lastFrame; i++)
319 if (opt_display && opt_click_allowed)
321 std::cout <<
"Click to exit the test" << std::endl;
329 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...
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