ViSP  2.10.0
tutorial-video-reader.cpp
1 #include <visp/vpDisplayGDI.h>
3 #include <visp/vpDisplayOpenCV.h>
4 #include <visp/vpDisplayX.h>
6 #include <visp/vpTime.h>
7 #include <visp/vpVideoReader.h>
9 
16 int main(int argc, char** argv)
17 {
18 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100) || defined(VISP_HAVE_FFMPEG)
19  try {
20  std::string videoname = "video.mpg";
21 
22  for (int i=0; i<argc; i++) {
23  if (std::string(argv[i]) == "--name")
24  videoname = std::string(argv[i+1]);
25  else if (std::string(argv[i]) == "--help") {
26  std::cout << "\nUsage: " << argv[0] << " [--name <video name>] [--help]\n" << std::endl;
27  return 0;
28  }
29  }
30 
33  vpVideoReader g;
36  g.setFileName(videoname);
39  g.open(I);
41  std::cout << "video name: " << videoname << std::endl;
42  std::cout << "video framerate: " << g.getFramerate() << "Hz" << std::endl;
43  std::cout << "video dimension: " << I.getWidth() << " " << I.getHeight() << std::endl;
44 
45 #ifdef VISP_HAVE_X11
46  vpDisplayX d(I);
47 #elif defined(VISP_HAVE_GDI)
48  vpDisplayGDI d(I);
49 #elif defined(VISP_HAVE_OPENCV)
50  vpDisplayOpenCV d(I);
51 #else
52  std::cout << "No image viewer is available..." << std::endl;
53 #endif
54  vpDisplay::setTitle(I, "Video reader");
56  while (! g.end() ) {
59  double t = vpTime::measureTimeMs();
62  g.acquire(I);
66  if (vpDisplay::getClick(I, false)) break;
68  vpTime::wait(t, 1000. / g.getFramerate());
70  }
71  }
72  catch(vpException e) {
73  std::cout << e.getMessage() << std::endl;
74  }
75 #else
76  (void)argc;
77  (void)argv;
78  std::cout << "Install OpenCV or ffmpeg and rebuild ViSP to use this example." << std::endl;
79 #endif
80 }
const char * getMessage(void)
unsigned int getWidth() const
Definition: vpImage.h:161
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:132
Define the X11 console to display images.
Definition: vpDisplayX.h:152
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.
Definition: vpException.h:76
static double measureTimeMs()
Definition: vpTime.cpp:86
static int wait(double t0, double t)
Definition: vpTime.cpp:149
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2232
void open(vpImage< vpRGBa > &I)
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:210
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void setTitle(const char *title)=0
void acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
double getFramerate()
unsigned int getHeight() const
Definition: vpImage.h:152
virtual bool getClick(bool blocking=true)=0