Visual Servoing Platform  version 3.0.0
tutorial-image-simulator.cpp
1 #include <visp3/gui/vpDisplayX.h>
3 #include <visp3/gui/vpDisplayOpenCV.h>
4 #include <visp3/gui/vpDisplayGDI.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++) X[i].resize(3);
21  // Top left Top right Bottom right Bottom left
22  X[0][0] = -0.1; X[1][0] = 0.1; X[2][0] = 0.1; X[3][0] = -0.1;
23  X[0][1] = -0.1; X[1][1] = -0.1; X[2][1] = 0.1; X[3][1] = 0.1;
24  X[0][2] = 0; X[1][2] = 0; X[2][2] = 0; X[3][2] = 0;
26 
28  vpImage<unsigned char> I(480, 640);
31  vpCameraParameters cam(840, 840, I.getWidth()/2, I.getHeight()/2);
34  vpHomogeneousMatrix cMo(0, 0, 0.35, 0, vpMath::rad(30), vpMath::rad(15));
36 
38  vpImageSimulator sim;
40  sim.init(target, X);
42 
43  // Get the new image of the projected planar image target
45  sim.setCleanPreviousImage(true);
46  sim.setCameraPosition(cMo);
47  sim.getImage(I, cam);
49 
51  try {
52  vpImageIo::write(I, "./rendered_image.jpg");
53  }
54  catch(...) {
55  std::cout << "Unsupported image format" << std::endl;
56  }
58 
59 #if defined(VISP_HAVE_X11)
60  vpDisplayX d(I);
61 #elif defined(VISP_HAVE_GDI)
62  vpDisplayGDI d(I);
63 #elif defined(VISP_HAVE_OPENCV)
64  vpDisplayOpenCV d(I);
65 #else
66  std::cout << "No image viewer is available..." << std::endl;
67 #endif
68 
69  vpDisplay::setTitle(I, "Planar image projection");
72  std::cout << "A click to quit..." << std::endl;
74  }
75  catch(vpException e) {
76  std::cout << "Catch an exception: " << e << std::endl;
77  }
78 }
static void write(const vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:472
void init(const vpImage< unsigned char > &I, vpColVector *X)
unsigned int getWidth() const
Definition: vpImage.h:161
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:128
Define the X11 console to display images.
Definition: vpDisplayX.h:148
error that can be emited by ViSP classes.
Definition: vpException.h:73
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2233
void setCameraPosition(const vpHomogeneousMatrix &cMt)
void setInterpolationType(const vpInterpolationType interplt)
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:206
The vpDisplayOpenCV allows to display image using the opencv library.
Generic class defining intrinsic camera parameters.
virtual void setTitle(const char *title)=0
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:104
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:152
virtual bool getClick(bool blocking=true)=0
static void read(vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:274