Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 }
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:226
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
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:153
error that can be emited by ViSP classes.
Definition: vpException.h:73
static void flush(const vpImage< unsigned char > &I)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:368
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:104
static void read(vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:205
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:175
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)