Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
tutorial-image-viewer.cpp
1 
2 #include <visp3/core/vpConfig.h>
3 #include <visp3/core/vpImagePoint.h>
4 #include <visp3/gui/vpDisplayGDI.h>
5 #include <visp3/gui/vpDisplayOpenCV.h>
6 #include <visp3/gui/vpDisplayX.h>
7 #include <visp3/io/vpImageIo.h>
8 
9 int main()
10 {
11 #ifdef ENABLE_VISP_NAMESPACE
12  using namespace VISP_NAMESPACE_NAME;
13 #endif
14 
15  try {
17  vpImageIo::read(I, "monkey.ppm");
18 
19 #if defined(VISP_HAVE_X11)
20  vpDisplayX d(I);
21 #elif defined(VISP_HAVE_GDI)
22  vpDisplayGDI d(I);
23 #elif defined(HAVE_OPENCV_HIGHGUI)
24  vpDisplayOpenCV d(I);
25 #else
26  std::cout << "No image viewer is available..." << std::endl;
27 #endif
28  vpDisplay::setTitle(I, "Monkey");
30 
31  vpDisplay::displayRectangle(I, vpImagePoint(90, 90), 70, 90, vpColor::red, false, 2);
33 
35  vpDisplay::getImage(I, O);
36 
37  try {
38  vpImageIo::write(I, "monkey-out.jpg");
39  vpImageIo::write(O, "monkey-out-with-overlay.jpg");
40  }
41  catch (...) {
42  std::cout << "Cannot write the image: unsupported format..." << std::endl;
43  }
44 
46  }
47  catch (const vpException &e) {
48  std::cout << "Catch an exception: " << e << std::endl;
49  }
50 }
static const vpColor red
Definition: vpColor.h:217
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:130
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
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 setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
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)
error that can be emitted by ViSP classes.
Definition: vpException.h:60
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:147
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:291
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82