ViSP  2.8.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 {
10  vpImageIo::read(target, "./target_square.pgm");
11 
12  vpColVector X[4];
13  for (int i = 0; i < 4; i++) X[i].resize(3);
14  // Top left Top right Bottom right Bottom left
15  X[0][0] = -0.1; X[1][0] = 0.1; X[2][0] = 0.1; X[3][0] = -0.1;
16  X[0][1] = -0.1; X[1][1] = -0.1; X[2][1] = 0.1; X[3][1] = 0.1;
17  X[0][2] = 0; X[1][2] = 0; X[2][2] = 0; X[3][2] = 0;
18 
19  vpImage<unsigned char> I(480, 640);
20  vpCameraParameters cam(840, 840, I.getWidth()/2, I.getHeight()/2);
21  vpHomogeneousMatrix cMo(0, 0, 0.35, 0, vpMath::rad(30), vpMath::rad(15));
22 
23  vpImageSimulator sim;
25  sim.init(target, X);
26 
27  // Get the new image of the projected planar image target
28  sim.setCleanPreviousImage(true);
29  sim.setCameraPosition(cMo);
30  sim.getImage(I, cam);
31 
32  try {
33  vpImageIo::write(I, "./rendered_image.jpg");
34  }
35  catch(...) {
36  std::cout << "Unsupported image format" << std::endl;
37  }
38 
39 #if defined(VISP_HAVE_X11)
40  vpDisplayX d(I);
41 #elif defined(VISP_HAVE_GDI)
42  vpDisplayGDI d(I);
43 #else
44  std::cout << "No image viewer is available..." << std::endl;
45 #endif
46 
47  vpDisplay::setTitle(I, "Planar image projection");
50  std::cout << "A click to quit..." << std::endl;
52 }
static void write(const vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:442
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:133
Define the X11 console to display images.
Definition: vpDisplayX.h:152
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:1991
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:203
Generic class defining intrinsic camera parameters.
void init(const vpImage< unsigned char > &I, vpColVector *_X)
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...
void setInterpolationType(const vpInterpolationType interp)
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
void setCameraPosition(const vpHomogeneousMatrix &_cMt)
static void read(vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:277