48 #include <visp3/core/vpConfig.h> 49 #include <visp3/core/vpImage.h> 50 #include <visp3/io/vpImageIo.h> 51 #include <visp3/io/vpParseArgv.h> 52 #include <visp3/core/vpIoTools.h> 53 #include <visp3/core/vpDebug.h> 54 #include <visp3/io/vpVideoReader.h> 55 #include <visp3/gui/vpDisplayOpenCV.h> 56 #include <visp3/gui/vpDisplayX.h> 57 #include <visp3/gui/vpDisplayGTK.h> 58 #include <visp3/gui/vpDisplayGDI.h> 60 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK) 63 #define GETOPTARGS "cdi:p:h" 65 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath);
66 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
67 bool &click_allowed,
bool &display);
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, std::string &ipath, std::string &ppath,
134 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 ;
189 if (! env_ipath.empty())
193 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed,
194 opt_display) ==
false) {
199 if (!opt_ipath.empty())
204 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
205 if (ipath != env_ipath) {
206 std::cout << std::endl
207 <<
"WARNING: " << std::endl;
208 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 209 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
210 <<
" we skip the environment variable." << std::endl;
215 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()){
216 usage(argv[0], NULL, ipath, opt_ppath);
217 std::cerr << std::endl
218 <<
"ERROR:" << std::endl;
219 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " 221 <<
" environment variable to specify the location of the " << std::endl
222 <<
" video path where test images are located." << std::endl << std::endl;
236 if (opt_ppath.empty())
242 filename.assign(opt_ppath);
246 std::cout <<
"Process video in " << filename << std::endl;
251 #if defined VISP_HAVE_X11 253 #elif defined VISP_HAVE_GTK 255 #elif defined VISP_HAVE_GDI 257 #elif defined VISP_HAVE_OPENCV 263 display.
init(I, 100, 100,
"Display video frame") ;
282 if (opt_display && opt_click_allowed)
284 std::cout <<
"Click to see the video" << std::endl;
288 while (! reader.
end() ) {
289 std::cout <<
"Read frame: " << reader.
getFrameIndex() << std::endl;
298 if (opt_display && opt_click_allowed)
300 std::cout <<
"Click to exit this example" << std::endl;
305 std::cout <<
"Catch an exception: " << e << std::endl;
312 std::cout <<
"Sorry, no display is available. We quit this example." static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
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)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
long getFrameIndex() const