Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
tutorial-viewer.cpp
1
2
#include <visp3/core/vpConfig.h>
3
#include <visp3/core/vpFont.h>
4
#include <visp3/core/vpIoTools.h>
5
#include <visp3/core/vpTime.h>
7
#include <visp3/gui/vpDisplayFactory.h>
10
#include <visp3/io/vpImageIo.h>
12
13
#ifdef ENABLE_VISP_NAMESPACE
14
using namespace
VISP_NAMESPACE_NAME
;
15
#endif
16
17
int
main(
int
argc,
char
**argv)
18
{
19
#ifdef VISP_HAVE_DISPLAY
20
if
(argc != 2) {
21
printf(
"Usage: %s <image name.[pgm,ppm,jpeg,png,tiff,bmp,ras,jp2]>\n"
, argv[0]);
22
return
EXIT_FAILURE;
23
}
24
26
vpImage<vpRGBa>
I;
28
30
try
{
31
vpImageIo::read
(I, argv[1]);
32
}
33
catch
(...) {
34
std::cout <<
"Cannot read image \""
<< argv[1] <<
"\""
<< std::endl;
35
return
EXIT_FAILURE;
36
}
38
39
try
{
41
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
42
std::shared_ptr<vpDisplay> pdisp =
vpDisplayFactory::createDisplay
(I, 10, 10,
vpIoTools::getName
(argv[1]),
vpDisplay::SCALE_AUTO
);
43
#else
44
vpDisplay
*pdisp =
vpDisplayFactory::allocateDisplay
(I, 10, 10,
vpIoTools::getName
(argv[1]),
vpDisplay::SCALE_AUTO
);
45
#endif
47
49
vpDisplay::setTitle
(I,
vpIoTools::getName
(argv[1]));
51
53
vpDisplay::display
(I);
54
vpDisplay::flush
(I);
56
std::cout <<
"Right click to quit"
<< std::endl;
57
std::cout <<
"Left click to inspect pixel position (i,j) and RGBa values\n"
<< std::endl;
59
bool
quit =
false
;
60
vpImagePoint
ip;
61
vpMouseButton::vpMouseButtonType
button;
62
unsigned
int
scale_factor =
vpDisplay::getDownScalingFactor
(I);
63
vpFont
font(14,
vpFont::GENERIC_MONOSPACE
);
64
while
(!quit) {
65
if
(
vpDisplay::getClick
(I, ip, button,
false
)) {
66
if
(button ==
vpMouseButton::button3
) {
67
quit =
true
;
68
}
69
else
{
70
std::stringstream ss;
71
unsigned
int
i
=
static_cast<
unsigned
int
>
(ip.
get_i
());
72
unsigned
int
j
=
static_cast<
unsigned
int
>
(ip.
get_j
());
73
ss <<
i
<<
" "
<<
j
<<
": "
<< I[
i
][
j
];
74
std::cout << ss.str() << std::endl;
75
font.drawText(I, ss.str(),
vpImagePoint
(I.getHeight() - 20*scale_factor, 10),
vpColor::red
,
vpColor::white
);
76
vpDisplay::display
(I);
77
vpDisplay::flush
(I);
78
}
79
}
80
vpTime::sleepMs
(40);
81
}
82
84
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
85
delete
pdisp;
86
#endif
87
}
88
catch
(
const
vpException
&e) {
89
std::cout <<
"Catch an exception: "
<<
e
<< std::endl;
90
}
91
#else
92
(void)argc;
93
(void)argv;
94
std::cout <<
"No display available!"
<< std::endl;
95
#endif
96
}
vpColor::white
static const vpColor white
Definition
vpColor.h:193
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::SCALE_AUTO
@ SCALE_AUTO
Definition
vpDisplay.h:177
vpDisplay::getDownScalingFactor
unsigned int getDownScalingFactor()
Definition
vpDisplay.h:218
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpFont
Font drawing functions for image.
Definition
vpFont.h:55
vpFont::GENERIC_MONOSPACE
@ GENERIC_MONOSPACE
Definition
vpFont.h:57
vpImageIo::read
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition
vpImageIo.cpp:116
vpImagePoint
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition
vpImagePoint.h:82
vpImagePoint::get_j
double get_j() const
Definition
vpImagePoint.h:125
vpImagePoint::get_i
double get_i() const
Definition
vpImagePoint.h:114
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpIoTools::getName
static std::string getName(const std::string &pathname)
Definition
vpIoTools.cpp:1236
vpMouseButton::vpMouseButtonType
vpMouseButtonType
Definition
vpMouseButton.h:49
vpMouseButton::button3
@ button3
Definition
vpMouseButton.h:52
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
ibvs-four-points.e
e
Definition
ibvs-four-points.py:272
vpDisplayFactory::createDisplay
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
Definition
vpDisplayFactory.h:142
vpDisplayFactory::allocateDisplay
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
Definition
vpDisplayFactory.h:68
vpTime::sleepMs
VISP_EXPORT void sleepMs(double t)
yolo-centering-task-afma6.j
j
Definition
yolo-centering-task-afma6.py:329
yolo-centering-task-afma6.i
i
Definition
yolo-centering-task-afma6.py:329
tutorial
image
tutorial-viewer.cpp
Generated by
1.17.0