Visual Servoing Platform  version 3.2.1 under development (2019-08-24) under development (2019-08-24)
tutorial-export-image.cpp
1 #include <visp3/io/vpImageIo.h>
3 #include <visp3/gui/vpDisplayX.h>
4 #include <visp3/gui/vpDisplayGTK.h>
5 #include <visp3/gui/vpDisplayGDI.h>
6 #include <visp3/gui/vpDisplayD3D.h>
7 #include <visp3/gui/vpDisplayOpenCV.h>
8 
9 int main()
10 {
11  vpImage<unsigned char> I(240, 320, 255); // Create a black grey level image
12  vpImage<vpRGBa> Ioverlay;
13 
14  // Depending on the detected third party libraries, we instantiate here the
15  // first video device which is available
16 #if defined(VISP_HAVE_X11)
17  vpDisplay *d = new vpDisplayX;
18 #elif defined(VISP_HAVE_GTK)
19  vpDisplay *d = new vpDisplayGTK;
20 #elif defined(VISP_HAVE_GDI)
21  vpDisplay *d = new vpDisplayGDI;
22 #elif defined(VISP_HAVE_D3D9)
23  vpDisplay *d = new vpDisplayD3D;
24 #elif defined(VISP_HAVE_OPENCV)
25  vpDisplay *d = new vpDisplayOpenCV;
26 #endif
27  // Initialize the display with the image I. Display and image are
28  // now link together.
29 #ifdef VISP_HAVE_DISPLAY
30  d->init(I);
31 #endif
32  // Set the display background with image I content
34  // Draw a red rectangle in the display overlay (foreground)
35  vpDisplay::displayRectangle(I, 10, 10, 100, 20, vpColor::red, true);
36  // Flush the foreground and background display
38  // Updates the color image with the original loaded image and the overlay
39  vpDisplay::getImage(I, Ioverlay) ;
40  // Write the color image on the disk
41  std::cout << "Save image in overlay.ppm" << std::endl;
42  std::string ofilename("overlay.ppm");
43  vpImageIo::write(Ioverlay, ofilename) ;
44  // Wait for a click in the display window
45  std::cout << "A click to quit..." << std::endl;
47 #ifdef VISP_HAVE_DISPLAY
48  delete d;
49 #endif
50 }
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:171
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:180
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:436
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
Definition: vpDisplayD3D.h:107
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:138
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:144