Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-export-image.cpp
1
2#include <visp3/core/vpConfig.h>
3#include <visp3/gui/vpDisplayFactory.h>
4#include <visp3/io/vpImageIo.h>
5
6#ifdef ENABLE_VISP_NAMESPACE
7using namespace VISP_NAMESPACE_NAME;
8#endif
9
10int main()
11{
12#if defined(VISP_HAVE_DISPLAY)
13 vpImage<unsigned char> I(240, 320, 255); // Create a black grey level image
14 vpImage<vpRGBa> Ioverlay;
15
16 // Initialize the display with the image I. Display and image are now linked together
17#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
18 std::shared_ptr<vpDisplay> d = vpDisplayFactory::createDisplay(I, -1, -1, "Save overlayed image", vpDisplay::SCALE_AUTO);
19#else
20 vpDisplay *d = vpDisplayFactory::allocateDisplay(I, -1, -1, "Save overlayed image", vpDisplay::SCALE_AUTO);
21#endif
22 // Set the display background with image I content
24 // Draw a red rectangle in the display overlay (foreground)
25 vpDisplay::displayRectangle(I, 10, 10, 100, 20, vpColor::red, true);
26 // Flush the foreground and background display
28 // Updates the color image with the original loaded image and the overlay
29 vpDisplay::getImage(I, Ioverlay);
30 // Write the color image on the disk
31 std::string ofilename("overlay.png");
32 std::cout << "Save overlayed image in: " << ofilename << std::endl;
33 vpImageIo::write(Ioverlay, ofilename);
34 // Wait for a click in the display window
35 std::cout << "A click to quit..." << std::endl;
37
38#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
39 delete d;
40#endif
41#else
42 std::cout << "No gui available to display an image..." << std::endl;
43#endif
44}
static const vpColor red
Definition vpColor.h:198
Class that defines generic functionalities for display.
Definition vpDisplay.h:171
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)
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 of the vpImage class member functions.
Definition vpImage.h:131
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.