Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-viewer.cpp
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpFont.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpTime.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/io/vpImageIo.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main(int argc, char **argv)
{
#ifdef VISP_HAVE_DISPLAY
if (argc != 2) {
printf("Usage: %s <image name.[pgm,ppm,jpeg,png,tiff,bmp,ras,jp2]>\n", argv[0]);
return EXIT_FAILURE;
}
try {
vpImageIo::read(I, argv[1]);
}
catch (...) {
std::cout << "Cannot read image \"" << argv[1] << "\"" << std::endl;
return EXIT_FAILURE;
}
try {
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
std::shared_ptr<vpDisplay> pdisp = vpDisplayFactory::createDisplay(I, 10, 10, vpIoTools::getName(argv[1]), vpDisplay::SCALE_AUTO);
#else
#endif
std::cout << "Right click to quit" << std::endl;
std::cout << "Left click to inspect pixel position (i,j) and RGBa values\n" << std::endl;
bool quit = false;
unsigned int scale_factor = vpDisplay::getDownScalingFactor(I);
while (!quit) {
if (vpDisplay::getClick(I, ip, button, false)) {
if (button == vpMouseButton::button3) {
quit = true;
}
else {
std::stringstream ss;
unsigned int i = static_cast<unsigned int>(ip.get_i());
unsigned int j = static_cast<unsigned int>(ip.get_j());
ss << i << " " << j << ": " << I[i][j];
std::cout << ss.str() << std::endl;
font.drawText(I, ss.str(), vpImagePoint(I.getHeight() - 20*scale_factor, 10), vpColor::red, vpColor::white);
}
}
}
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
delete pdisp;
#endif
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
}
#else
(void)argc;
(void)argv;
std::cout << "No display available!" << std::endl;
#endif
}
static const vpColor white
Definition vpColor.h:193
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 setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static void flush(const vpImage< unsigned char > &I)
unsigned int getDownScalingFactor()
Definition vpDisplay.h:218
error that can be emitted by ViSP classes.
Definition vpException.h:60
Font drawing functions for image.
Definition vpFont.h:55
bool drawText(vpImage< unsigned char > &I, const std::string &text, const vpImagePoint &position, unsigned char color) const
Definition vpFont.cpp:2636
@ GENERIC_MONOSPACE
Definition vpFont.h:57
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
double get_j() const
double get_i() const
Definition of the vpImage class member functions.
Definition vpImage.h:131
static std::string getName(const std::string &pathname)
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.
VISP_EXPORT void sleepMs(double t)