Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
tutorial-image-simulator.cpp
1 #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 
10 int 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 
48  vpImageSimulator sim;
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(VISP_HAVE_OPENCV)
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 }
void init(const vpImage< unsigned char > &I, vpColVector *X)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
unsigned int getWidth() const
Definition: vpImage.h:239
Implementation of an homogeneous matrix and operations on such kind of matrices.
void getImage(vpImage< unsigned char > &I, const vpCameraParameters &cam)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:151
error that can be emited by ViSP classes.
Definition: vpException.h:71
static void flush(const vpImage< unsigned char > &I)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:375
void setCameraPosition(const vpHomogeneousMatrix &cMt)
void setInterpolationType(const vpInterpolationType interplt)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Generic class defining intrinsic camera parameters.
Class which enables to project an image in the 3D space and get the view of a virtual camera...
static double rad(double deg)
Definition: vpMath.h:102
static void read(vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:207
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void setCleanPreviousImage(const bool &clean, const vpColor &color=vpColor::white)
unsigned int getHeight() const
Definition: vpImage.h:178
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)