Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-video-reader.cpp
1
2#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
16int main(int argc, char **argv)
17{
18#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO)
19 try {
20 std::string videoname = "video.mp4";
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" || std::string(argv[i]) == "-h") {
26 std::cout << "\nUsage: " << argv[0] << " [--name <video name> (default: " << videoname << ")]"
27 << " [--help] [-h]\n"
28 << std::endl;
29 return EXIT_SUCCESS;
30 }
31 }
32
38 g.setFileName(videoname);
41 g.open(I);
43 std::cout << "Video name : " << videoname << std::endl;
44 std::cout << "Video framerate: " << g.getFramerate() << "Hz" << std::endl;
45 std::cout << "Video dimension: " << I.getWidth() << " " << I.getHeight() << std::endl;
46
47#ifdef VISP_HAVE_X11
48 vpDisplayX d(I);
49#elif defined(VISP_HAVE_GDI)
50 vpDisplayGDI d(I);
51#elif defined(HAVE_OPENCV_HIGHGUI)
52 vpDisplayOpenCV d(I);
53#else
54 std::cout << "No image viewer is available..." << std::endl;
55#endif
56 vpDisplay::setTitle(I, "Video reader");
57
58 unsigned cpt = 1;
60 while (!g.end()) {
63 double t = vpTime::measureTimeMs();
66 g.acquire(I);
69 vpDisplay::displayText(I, 20, 20, "Click to quit", vpColor::red);
70 std::stringstream ss;
71 ss << "Frame: " << cpt++;
72 vpDisplay::displayText(I, 40, 20, ss.str(), vpColor::red);
74 if (vpDisplay::getClick(I, false))
75 break;
77 vpTime::wait(t, 1000. / g.getFramerate());
79 }
80 std::cout << "End of video was reached" << std::endl;
81 } catch (const vpException &e) {
82 std::cout << e.getMessage() << std::endl;
83 }
84#else
85 (void)argc;
86 (void)argv;
87 std::cout << "Install OpenCV and rebuild ViSP to use this example." << std::endl;
88#endif
89 return EXIT_SUCCESS;
90}
static const vpColor red
Definition vpColor.h:211
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:132
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Definition vpException.h:59
const char * getMessage() const
Definition of the vpImage class member functions.
Definition vpImage.h:135
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:184
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void acquire(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
double getFramerate()
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)