Visual Servoing Platform version 3.7.0
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
9int 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 {
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
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)
79#else
81#endif
82#else
83 std::cout << "No image viewer is available..." << std::endl;
84#endif
85
86 vpDisplay::setTitle(I, "Planar image projection");
89 std::cout << "A click to quit..." << std::endl;
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}
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
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)
error that can be emitted by ViSP classes.
Definition vpException.h:60
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class which enables to project an image in the 3D space and get the view of a virtual camera.
void getImage(vpImage< unsigned char > &I, const vpCameraParameters &cam)
void init(const vpImage< unsigned char > &I, vpColVector *X)
void setCleanPreviousImage(const bool &clean, const vpColor &color=vpColor::white)
void setInterpolationType(const vpInterpolationType interplt)
void setCameraPosition(const vpHomogeneousMatrix &cMt)
Definition of the vpImage class member functions.
Definition vpImage.h:131
static double rad(double deg)
Definition vpMath.h:129
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.