49 #include <visp3/core/vpConfig.h>
50 #include <visp3/core/vpDebug.h>
51 #include <visp3/core/vpImage.h>
52 #include <visp3/core/vpIoTools.h>
53 #include <visp3/gui/vpDisplayGDI.h>
54 #include <visp3/gui/vpDisplayGTK.h>
55 #include <visp3/gui/vpDisplayOpenCV.h>
56 #include <visp3/gui/vpDisplayX.h>
57 #include <visp3/io/vpImageIo.h>
58 #include <visp3/io/vpParseArgv.h>
59 #include <visp3/io/vpVideoReader.h>
61 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK)
64 #define GETOPTARGS "cdi:p:h"
66 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath);
67 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed,
80 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
83 Read a video file on the disk.\n\
86 %s [-i <input video path>] \n\
92 -i <input video path> %s\n\
93 Set video input path.\n\
94 From this path read \"video/video.mpeg\"\n\
96 Setting the VISP_INPUT_IMAGE_PATH environment\n\
97 variable produces the same behaviour than using\n\
100 -p <personal video path> %s\n\
101 Specify a personal folder containing a video \n\
103 Example : \"/Temp/ViSP-images/video/video.mpeg\"\n\
106 Disable the mouse click. Useful to automaze the \n\
107 execution of this program without humain intervention.\n\
110 Turn off the display.\n\
113 Print the help.\n\n", 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, std::string &ipath, std::string &ppath,
bool &click_allowed,
bool &display)
141 click_allowed =
false;
153 usage(argv[0], NULL, ipath, ppath);
158 usage(argv[0], optarg_, ipath, ppath);
164 if ((c == 1) || (c == -1)) {
166 usage(argv[0], NULL, ipath, ppath);
167 std::cerr <<
"ERROR: " << std::endl;
168 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
175 int 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;
183 bool opt_click_allowed =
true;
184 bool opt_display =
true;
186 std::cout <<
"-------------------------------------------------------" << std::endl;
187 std::cout <<
" videoReader.cpp" << std::endl << std::endl;
189 std::cout <<
" reading a video file" << std::endl;
190 std::cout <<
"-------------------------------------------------------" << std::endl;
191 std::cout << std::endl;
198 if (!env_ipath.empty())
202 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed, 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 <<
"WARNING: " << std::endl;
215 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
216 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
217 <<
" we skip the environment variable." << std::endl;
222 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
223 usage(argv[0], NULL, ipath, opt_ppath);
224 std::cerr << std::endl <<
"ERROR:" << std::endl;
225 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
226 <<
" environment variable to specify the location of the " << std::endl
227 <<
" video path where test images are located." << std::endl
241 if (opt_ppath.empty()) {
244 filename.assign(opt_ppath);
248 std::cout <<
"Process video in " << filename << std::endl;
253 #if defined VISP_HAVE_X11
255 #elif defined VISP_HAVE_GTK
257 #elif defined VISP_HAVE_GDI
259 #elif defined VISP_HAVE_OPENCV
265 display.init(I, 100, 100,
"Display video frame");
284 if (opt_display && opt_click_allowed) {
285 std::cout <<
"Click to see the video" << std::endl;
289 while (!reader.
end()) {
291 std::cout <<
"Display frame: " << reader.
getFrameIndex() << std::endl;
298 if (opt_display && opt_click_allowed) {
299 std::cout <<
"Click to exit this example" << std::endl;
303 std::cout <<
"Catch an exception: " << e << std::endl;
310 std::cout <<
"Sorry, no display is available. We quit this example." << std::endl;