Visual Servoing Platform  version 3.1.0
tutorial-video-reader.cpp
1 #include <visp3/gui/vpDisplayGDI.h>
3 #include <visp3/gui/vpDisplayOpenCV.h>
4 #include <visp3/gui/vpDisplayX.h>
6 #include <visp3/core/vpTime.h>
7 #include <visp3/io/vpVideoReader.h>
9 
16 int main(int argc, char **argv)
17 {
18 #if (VISP_HAVE_OPENCV_VERSION >= 0x020100)
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))
67  break;
69  vpTime::wait(t, 1000. / g.getFramerate());
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 and rebuild ViSP to use this example." << std::endl;
79 #endif
80 }
VISP_EXPORT int wait(double t0, double t)
Definition: vpTime.cpp:150
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:151
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:71
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
Definition: vpTime.cpp:88
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...
void acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
const char * getMessage(void) const
Definition: vpException.cpp:90
unsigned int getHeight() const
Definition: vpImage.h:178
double getFramerate()
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
unsigned int getWidth() const
Definition: vpImage.h:229