Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
tutorial-draw-circle.cpp
1 #include <visp3/core/vpConfig.h>
3 #include <visp3/gui/vpDisplayFactory.h>
4 #include <visp3/core/vpImageCircle.h>
5 #include <visp3/core/vpImageDraw.h>
6 
7 int main()
8 {
9 #ifdef ENABLE_VISP_NAMESPACE
10  using namespace VISP_NAMESPACE_NAME;
11 #endif
12 
13  vpImage<unsigned char> I(2160, 3840, 128);
14  vpImage<vpRGBa> I_rgb(2160, 3840, vpColor(0, 0, 0));
15 
16  try {
17  {
18 #if defined(VISP_HAVE_DISPLAY)
20 #else
21  std::cout << "No gui available to display gray level image..." << std::endl;
22 #endif
23 
24  vpDisplay::setTitle(I, "Gray image");
27  vpImageCircle circle(vpImagePoint(I.getHeight()/3, I.getWidth()/3), I.getWidth()/10.f);
28  // Displays in overlay a red circle on the image
29  // i.e. does not modify I
30  vpDisplay::displayCircle(I, circle, vpColor::red, false, 2);
32  vpDisplay::setTitle(I, "Display a red circle on gray level image overlay");
34  std::cout << "Result of displaying a red circle on a gray level image overlay..." << std::endl;
35  std::cout << "A click to continue..." << std::endl;
37 
39  vpImageCircle circle2(vpImagePoint(I.getHeight()/3, 2*I.getWidth()/3), I.getWidth()/10.f);
40  // Draws a white circle on the image
41  // i.e. modifies I
42  vpImageDraw::drawCircle(I, circle2, 255, 2);
45  vpDisplay::setTitle(I, "Display circle by modifying a gray level image");
46  std::cout << "Result of displaying a circle by modifying a gray level image..." << std::endl;
47  std::cout << "A click to continue..." << std::endl;
50 
51 #if defined(VISP_HAVE_DISPLAY)
52  if (d) {
53  delete d;
54  }
55 #endif
56  }
57 
58  {
60  vpImageCircle circle3(vpImagePoint(2*I.getHeight()/3, I.getWidth()/2), I.getWidth()/10.f);
61  // Draws a blue circle on the image
62  // i.e. modifies I_rgb
63  vpImageDraw::drawCircle(I_rgb, circle3, vpColor::blue, 2);
65 
66 #if defined(VISP_HAVE_DISPLAY)
68 #else
69  std::cout << "No gui available to display color image..." << std::endl;
70 #endif
71 
72  vpDisplay::display(I_rgb);
73  vpDisplay::setTitle(I_rgb, "Display blue circle on a modified color image");
74  vpDisplay::flush(I_rgb);
75  std::cout << "Result of displaying a blue circle on a modified color image..." << std::endl;
76  std::cout << "A click to continue..." << std::endl;
77  vpDisplay::getClick(I_rgb);
78 #if defined(VISP_HAVE_DISPLAY)
79  if (d) {
80  delete d;
81  }
82 #endif
83 }
84  }
85  catch (const vpException &e) {
86  std::cout << "Catch an exception: " << e.getMessage() << std::endl;
87  }
88  std::cout << std::endl;
89 }
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static const vpColor red
Definition: vpColor.h:217
static const vpColor blue
Definition: vpColor.h:223
Class that defines generic functionalities for display.
Definition: vpDisplay.h:178
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void displayCircle(const vpImage< unsigned char > &I, const vpImageCircle &circle, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void display(const vpImage< unsigned char > &I)
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static void flush(const vpImage< unsigned char > &I)
@ SCALE_AUTO
Definition: vpDisplay.h:184
error that can be emitted by ViSP classes.
Definition: vpException.h:60
const char * getMessage() const
Definition: vpException.cpp:65
Class that defines a 2D circle in an image.
Definition: vpImageCircle.h:57
static void drawCircle(vpImage< unsigned char > &I, const vpImageCircle &circle, unsigned char color, unsigned int thickness=1)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
unsigned int getWidth() const
Definition: vpImage.h:242
unsigned int getHeight() const
Definition: vpImage.h:181
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.