Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
tutorial-export-image.cpp
1 #include <visp3/core/vpConfig.h>
3 #include <visp3/gui/vpDisplayD3D.h>
4 #include <visp3/gui/vpDisplayGDI.h>
5 #include <visp3/gui/vpDisplayGTK.h>
6 #include <visp3/gui/vpDisplayOpenCV.h>
7 #include <visp3/gui/vpDisplayX.h>
8 #include <visp3/io/vpImageIo.h>
9 
10 int main()
11 {
12 #ifdef ENABLE_VISP_NAMESPACE
13  using namespace VISP_NAMESPACE_NAME;
14 #endif
15 
16  vpImage<unsigned char> I(240, 320, 255); // Create a black grey level image
17  vpImage<vpRGBa> Ioverlay;
18 
19  // Depending on the detected third party libraries, we instantiate here the
20  // first video device which is available
21 #if defined(VISP_HAVE_X11)
22  vpDisplay *d = new vpDisplayX;
23 #elif defined(VISP_HAVE_GTK)
24  vpDisplay *d = new vpDisplayGTK;
25 #elif defined(VISP_HAVE_GDI)
26  vpDisplay *d = new vpDisplayGDI;
27 #elif defined(VISP_HAVE_D3D9)
28  vpDisplay *d = new vpDisplayD3D;
29 #elif defined(HAVE_OPENCV_HIGHGUI)
30  vpDisplay *d = new vpDisplayOpenCV;
31 #endif
32  // Initialize the display with the image I. Display and image are
33  // now link together.
34 #ifdef VISP_HAVE_DISPLAY
35  d->init(I);
36 #endif
37  // Set the display background with image I content
39  // Draw a red rectangle in the display overlay (foreground)
40  vpDisplay::displayRectangle(I, 10, 10, 100, 20, vpColor::red, true);
41  // Flush the foreground and background display
43  // Updates the color image with the original loaded image and the overlay
44  vpDisplay::getImage(I, Ioverlay);
45  // Write the color image on the disk
46  std::cout << "Save image in overlay.ppm" << std::endl;
47  std::string ofilename("overlay.png");
48  vpImageIo::write(Ioverlay, ofilename);
49  // Wait for a click in the display window
50  std::cout << "A click to quit..." << std::endl;
52 #ifdef VISP_HAVE_DISPLAY
53  delete d;
54 #endif
55 }
static const vpColor red
Definition: vpColor.h:217
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Definition: vpDisplayD3D.h:106
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:130
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:133
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
Class that defines generic functionalities for display.
Definition: vpDisplay.h:178
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:140
static void flush(const vpImage< unsigned char > &I)
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 write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:291