Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
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
15
int
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
39
vpImage<unsigned char>
I;
41
vpVideoReader
g;
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
54
vpDisplay
*
d
=
vpDisplayFactory::allocateDisplay
(I);
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);
71
vpDisplay::display
(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
);
77
vpDisplay::flush
(I);
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
}
vpColor::red
static const vpColor red
Definition
vpColor.h:198
vpDisplay
Class that defines generic functionalities for display.
Definition
vpDisplay.h:171
vpDisplay::getClick
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Definition
vpDisplay_uchar.cpp:894
vpDisplay::display
static void display(const vpImage< unsigned char > &I)
Definition
vpDisplay_uchar.cpp:869
vpDisplay::setTitle
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
Definition
vpDisplay_uchar.cpp:1364
vpDisplay::flush
static void flush(const vpImage< unsigned char > &I)
Definition
vpDisplay_uchar.cpp:845
vpDisplay::displayText
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Definition
vpDisplay_uchar.cpp:788
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpVideoReader
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
Definition
vpVideoReader.h:181
vpVideoReader::open
void open(vpImage< vpRGBa > &I) VP_OVERRIDE
Definition
vpVideoReader.cpp:213
vpVideoReader::setFileName
void setFileName(const std::string &filename)
Definition
vpVideoReader.cpp:123
vpVideoReader::end
bool end()
Definition
vpVideoReader.h:255
vpVideoReader::getFramerate
double getFramerate()
Definition
vpVideoReader.h:275
vpVideoReader::acquire
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE
Definition
vpVideoReader.cpp:286
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
ibvs-four-points.e
e
Definition
ibvs-four-points.py:272
pbvs-four-points.t
t
Definition
pbvs-four-points.py:220
vpDisplayFactory::allocateDisplay
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
Definition
vpDisplayFactory.h:68
vpTime::measureTimeMs
VISP_EXPORT double measureTimeMs()
vpTime::wait
VISP_EXPORT int wait(double t0, double t)
yolo-centering-task-afma6.d
d
Definition
yolo-centering-task-afma6.py:273
yolo-centering-task-afma6.i
i
Definition
yolo-centering-task-afma6.py:329
tutorial
grabber
tutorial-video-reader.cpp
Generated by
1.17.0