Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-image-simulator.cpp
1
2#include <visp3/gui/vpDisplayGDI.h>
3#include <visp3/gui/vpDisplayOpenCV.h>
4#include <visp3/gui/vpDisplayX.h>
5#include <visp3/io/vpImageIo.h>
7#include <visp3/robot/vpImageSimulator.h>
9
10int main()
11{
12 try {
15 vpImageIo::read(target, "./target_square.pgm");
17
19 vpColVector X[4];
20 for (int i = 0; i < 4; i++)
21 X[i].resize(3);
22 // Top left Top right Bottom right Bottom left
23 X[0][0] = -0.1;
24 X[1][0] = 0.1;
25 X[2][0] = 0.1;
26 X[3][0] = -0.1;
27 X[0][1] = -0.1;
28 X[1][1] = -0.1;
29 X[2][1] = 0.1;
30 X[3][1] = 0.1;
31 X[0][2] = 0;
32 X[1][2] = 0;
33 X[2][2] = 0;
34 X[3][2] = 0;
36
38 vpImage<unsigned char> I(480, 640);
41 vpCameraParameters cam(840, 840, I.getWidth() / 2, I.getHeight() / 2);
44 vpHomogeneousMatrix cMo(0, 0, 0.35, 0, vpMath::rad(30), vpMath::rad(15));
46
50 sim.init(target, X);
52
53 // Get the new image of the projected planar image target
55 sim.setCleanPreviousImage(true);
56 sim.setCameraPosition(cMo);
57 sim.getImage(I, cam);
59
61 try {
62 vpImageIo::write(I, "./rendered_image.jpg");
63 } catch (...) {
64 std::cout << "Unsupported image format" << std::endl;
65 }
67
68#if defined(VISP_HAVE_X11)
69 vpDisplayX d(I);
70#elif defined(VISP_HAVE_GDI)
71 vpDisplayGDI d(I);
72#elif defined(HAVE_OPENCV_HIGHGUI)
73 vpDisplayOpenCV d(I);
74#else
75 std::cout << "No image viewer is available..." << std::endl;
76#endif
77
78 vpDisplay::setTitle(I, "Planar image projection");
81 std::cout << "A click to quit..." << std::endl;
83 } catch (const vpException &e) {
84 std::cout << "Catch an exception: " << e << std::endl;
85 }
86}
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:132
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:59
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:135
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:184
static double rad(double deg)
Definition vpMath.h:116