Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
tutorial-image-simulator.cpp
1
2
#include <visp3/core/vpConfig.h>
3
#include <visp3/gui/vpDisplayFactory.h>
4
#include <visp3/io/vpImageIo.h>
6
#include <visp3/robot/vpImageSimulator.h>
8
9
int
main()
10
{
11
#ifdef ENABLE_VISP_NAMESPACE
12
using namespace
VISP_NAMESPACE_NAME
;
13
#endif
14
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
15
std::shared_ptr<vpDisplay> display;
16
#else
17
vpDisplay
*display =
nullptr
;
18
#endif
19
try
{
21
vpImage<unsigned char>
target;
22
vpImageIo::read
(target,
"./target_square.jpg"
);
24
26
vpColVector
X[4];
27
for
(
int
i = 0;
i
< 4;
i
++)
28
X[i].resize(3);
29
// Top left Top right Bottom right Bottom left
30
X[0][0] = -0.1;
31
X[1][0] = 0.1;
32
X[2][0] = 0.1;
33
X[3][0] = -0.1;
34
X[0][1] = -0.1;
35
X[1][1] = -0.1;
36
X[2][1] = 0.1;
37
X[3][1] = 0.1;
38
X[0][2] = 0;
39
X[1][2] = 0;
40
X[2][2] = 0;
41
X[3][2] = 0;
43
45
vpImage<unsigned char>
I(480, 640);
48
vpCameraParameters
cam
(840, 840, I.getWidth() / 2, I.getHeight() / 2);
51
vpHomogeneousMatrix
cMo
(0, 0, 0.35, 0,
vpMath::rad
(30),
vpMath::rad
(15));
53
55
vpImageSimulator
sim;
56
sim.
setInterpolationType
(
vpImageSimulator::BILINEAR_INTERPOLATION
);
57
sim.
init
(target, X);
59
60
// Get the new image of the projected planar image target
62
sim.
setCleanPreviousImage
(
true
);
63
sim.
setCameraPosition
(cMo);
64
sim.
getImage
(I, cam);
66
68
try
{
69
vpImageIo::write
(I,
"./rendered_image.jpg"
);
70
}
71
catch
(...) {
72
std::cout <<
"Unsupported image format"
<< std::endl;
73
}
75
76
#if defined(VISP_HAVE_DISPLAY)
77
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
78
display =
vpDisplayFactory::createDisplay
(I);
79
#else
80
display =
vpDisplayFactory::allocateDisplay
(I);
81
#endif
82
#else
83
std::cout <<
"No image viewer is available..."
<< std::endl;
84
#endif
85
86
vpDisplay::setTitle
(I,
"Planar image projection"
);
87
vpDisplay::display
(I);
88
vpDisplay::flush
(I);
89
std::cout <<
"A click to quit..."
<< std::endl;
90
vpDisplay::getClick
(I);
91
}
92
catch
(
const
vpException
&e) {
93
std::cout <<
"Catch an exception: "
<<
e
<< std::endl;
94
}
95
96
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
97
if
(display !=
nullptr
) {
98
delete
display;
99
}
100
#endif
101
}
vpCameraParameters
Generic class defining intrinsic camera parameters.
Definition
vpCameraParameters.h:311
vpColVector
Implementation of column vector and the associated operations.
Definition
vpColVector.h:191
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
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpHomogeneousMatrix
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition
vpHomogeneousMatrix.h:221
vpImageIo::read
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition
vpImageIo.cpp:116
vpImageIo::write
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition
vpImageIo.cpp:336
vpImageSimulator
Class which enables to project an image in the 3D space and get the view of a virtual camera.
Definition
vpImageSimulator.h:151
vpImageSimulator::BILINEAR_INTERPOLATION
@ BILINEAR_INTERPOLATION
Definition
vpImageSimulator.h:155
vpImageSimulator::getImage
void getImage(vpImage< unsigned char > &I, const vpCameraParameters &cam)
Definition
vpImageSimulator.cpp:184
vpImageSimulator::init
void init(const vpImage< unsigned char > &I, vpColVector *X)
Definition
vpImageSimulator.cpp:1071
vpImageSimulator::setCleanPreviousImage
void setCleanPreviousImage(const bool &clean, const vpColor &color=vpColor::white)
Definition
vpImageSimulator.h:268
vpImageSimulator::setInterpolationType
void setInterpolationType(const vpInterpolationType interplt)
Definition
vpImageSimulator.h:239
vpImageSimulator::setCameraPosition
void setCameraPosition(const vpHomogeneousMatrix &cMt)
Definition
vpImageSimulator.cpp:957
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpMath::rad
static double rad(double deg)
Definition
vpMath.h:129
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
ibvs-four-points.e
e
Definition
ibvs-four-points.py:272
realsense-mbt.cMo
cMo
Definition
realsense-mbt.py:212
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
yolo-centering-task-afma6.cam
cam
Definition
yolo-centering-task-afma6.py:202
yolo-centering-task-afma6.i
i
Definition
yolo-centering-task-afma6.py:329
tutorial
simulator
image
tutorial-image-simulator.cpp
Generated by
1.17.0