Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
tutorial-draw-circle.cpp
#include <visp3/core/vpConfig.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/core/vpImageCircle.h>
#include <visp3/core/vpImageDraw.h>
int main()
{
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
vpImage<unsigned char> I(2160, 3840, 128);
vpImage<vpRGBa> I_rgb(2160, 3840, vpColor(0, 0, 0));
try {
{
#if defined(VISP_HAVE_DISPLAY)
#else
std::cout << "No gui available to display gray level image..." << std::endl;
#endif
vpDisplay::setTitle(I, "Gray image");
vpImageCircle circle(vpImagePoint(I.getHeight()/3, I.getWidth()/3), I.getWidth()/10.f);
// Displays in overlay a red circle on the image
// i.e. does not modify I
vpDisplay::displayCircle(I, circle, vpColor::red, false, 2);
vpDisplay::setTitle(I, "Display a red circle on gray level image overlay");
std::cout << "Result of displaying a red circle on a gray level image overlay..." << std::endl;
std::cout << "A click to continue..." << std::endl;
vpImageCircle circle2(vpImagePoint(I.getHeight()/3, 2*I.getWidth()/3), I.getWidth()/10.f);
// Draws a white circle on the image
// i.e. modifies I
vpImageDraw::drawCircle(I, circle2, 255, 2);
vpDisplay::setTitle(I, "Display circle by modifying a gray level image");
std::cout << "Result of displaying a circle by modifying a gray level image..." << std::endl;
std::cout << "A click to continue..." << std::endl;
#if defined(VISP_HAVE_DISPLAY)
if (d) {
delete d;
}
#endif
}
{
vpImageCircle circle3(vpImagePoint(2*I.getHeight()/3, I.getWidth()/2), I.getWidth()/10.f);
// Draws a blue circle on the image
// i.e. modifies I_rgb
#if defined(VISP_HAVE_DISPLAY)
#else
std::cout << "No gui available to display color image..." << std::endl;
#endif
vpDisplay::setTitle(I_rgb, "Display blue circle on a modified color image");
std::cout << "Result of displaying a blue circle on a modified color image..." << std::endl;
std::cout << "A click to continue..." << std::endl;
#if defined(VISP_HAVE_DISPLAY)
if (d) {
delete d;
}
#endif
}
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e.getMessage() << std::endl;
}
std::cout << std::endl;
}
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.