Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-video-reader.cpp
1
2#include <visp3/core/vpConfig.h>
3#include <visp3/gui/vpDisplayFactory.h>
5#include <visp3/core/vpTime.h>
6#include <visp3/io/vpVideoReader.h>
8
15int main(int argc, char **argv)
16{
17#if defined(VISP_HAVE_OPENCV) && \
18 (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \
19 ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))
20#ifdef ENABLE_VISP_NAMESPACE
21 using namespace VISP_NAMESPACE_NAME;
22#endif
23 try {
24 std::string videoname = "video.mp4";
25
26 for (int i = 1; i < argc; i++) {
27 if (std::string(argv[i]) == "--name" && i + 1 < argc) {
28 videoname = std::string(argv[++i]);
29 }
30 else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
31 std::cout << "\nUsage: " << argv[0]
32 << " [--name <video name> (default: " << videoname << ")]"
33 << " [--help] [-h]\n"
34 << std::endl;
35 return EXIT_SUCCESS;
36 }
37 }
38
44 g.setFileName(videoname);
47 g.open(I);
49 std::cout << "Video name : " << videoname << std::endl;
50 std::cout << "Video framerate: " << g.getFramerate() << "Hz" << std::endl;
51 std::cout << "Video dimension: " << I.getWidth() << " " << I.getHeight() << std::endl;
52
53#ifdef VISP_HAVE_DISPLAY
55#else
56 std::cout << "No image viewer is available..." << std::endl;
57#endif
58 vpDisplay::setTitle(I, "Video reader");
59
60 unsigned cpt = 1;
61 bool quit = false;
63 while ((!g.end()) && (!quit)) {
66 double t = vpTime::measureTimeMs();
69 g.acquire(I);
72 vpDisplay::displayText(I, 20, 20, "Click to quit", vpColor::red);
73 std::stringstream ss;
74 ss << "Frame: " << ++cpt;
75 std::cout << "Read " << ss.str() << std::endl;
76 vpDisplay::displayText(I, 40, 20, ss.str(), vpColor::red);
78 if (vpDisplay::getClick(I, false)) {
79 quit = true;
80 }
82 vpTime::wait(t, 1000. / g.getFramerate());
84 }
85 if (!quit) {
86 std::cout << "End of video was reached" << std::endl;
87 }
88#ifdef VISP_HAVE_DISPLAY
89 delete d;
90#endif
91 }
92 catch (const vpException &e) {
93 std::cout << e.getMessage() << std::endl;
94 }
95#else
96 (void)argc;
97 (void)argv;
98 std::cout << "Install OpenCV and rebuild ViSP to use this example." << std::endl;
99#endif
100 return EXIT_SUCCESS;
101}
static const vpColor red
Definition vpColor.h:198
Class that defines generic functionalities for display.
Definition vpDisplay.h:171
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:60
Definition of the vpImage class member functions.
Definition vpImage.h:131
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void open(vpImage< vpRGBa > &I) VP_OVERRIDE
void setFileName(const std::string &filename)
double getFramerate()
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)