ViSP  2.9.0
tutorial-image-simulator.cpp
1 
2 #include <visp/vpDisplayX.h>
3 #include <visp/vpDisplayGDI.h>
4 #include <visp/vpImageIo.h>
5 #include <visp/vpImageSimulator.h>
6 
7 int main()
8 {
9  try {
11  vpImageIo::read(target, "./target_square.pgm");
12 
13  vpColVector X[4];
14  for (int i = 0; i < 4; i++) X[i].resize(3);
15  // Top left Top right Bottom right Bottom left
16  X[0][0] = -0.1; X[1][0] = 0.1; X[2][0] = 0.1; X[3][0] = -0.1;
17  X[0][1] = -0.1; X[1][1] = -0.1; X[2][1] = 0.1; X[3][1] = 0.1;
18  X[0][2] = 0; X[1][2] = 0; X[2][2] = 0; X[3][2] = 0;
19 
20  vpImage<unsigned char> I(480, 640);
21  vpCameraParameters cam(840, 840, I.getWidth()/2, I.getHeight()/2);
22  vpHomogeneousMatrix cMo(0, 0, 0.35, 0, vpMath::rad(30), vpMath::rad(15));
23 
24  vpImageSimulator sim;
26  sim.init(target, X);
27 
28  // Get the new image of the projected planar image target
29  sim.setCleanPreviousImage(true);
30  sim.setCameraPosition(cMo);
31  sim.getImage(I, cam);
32 
33  try {
34  vpImageIo::write(I, "./rendered_image.jpg");
35  }
36  catch(...) {
37  std::cout << "Unsupported image format" << std::endl;
38  }
39 
40 #if defined(VISP_HAVE_X11)
41  vpDisplayX d(I);
42 #elif defined(VISP_HAVE_GDI)
43  vpDisplayGDI d(I);
44 #else
45  std::cout << "No image viewer is available..." << std::endl;
46 #endif
47 
48  vpDisplay::setTitle(I, "Planar image projection");
51  std::cout << "A click to quit..." << std::endl;
53  }
54  catch(vpException e) {
55  std::cout << "Catch an exception: " << e << std::endl;
56  }
57 }
static void write(const vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:452
void init(const vpImage< unsigned char > &I, vpColVector *X)
unsigned int getWidth() const
Definition: vpImage.h:159
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void getImage(vpImage< unsigned char > &I, const vpCameraParameters &cam)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:132
Define the X11 console to display images.
Definition: vpDisplayX.h:152
error that can be emited by ViSP classes.
Definition: vpException.h:76
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:1994
void setCameraPosition(const vpHomogeneousMatrix &cMt)
void setInterpolationType(const vpInterpolationType interplt)
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:206
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:100
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
void setCleanPreviousImage(const bool &clean, const vpColor &color=vpColor::white)
unsigned int getHeight() const
Definition: vpImage.h:150
virtual bool getClick(bool blocking=true)=0
static void read(vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:278