Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-viewer.cpp
1
2#include <visp3/core/vpConfig.h>
3#include <visp3/core/vpFont.h>
4#include <visp3/core/vpIoTools.h>
5#include <visp3/core/vpTime.h>
7#include <visp3/gui/vpDisplayFactory.h>
10#include <visp3/io/vpImageIo.h>
12
13#ifdef ENABLE_VISP_NAMESPACE
14using namespace VISP_NAMESPACE_NAME;
15#endif
16
17int main(int argc, char **argv)
18{
19#ifdef VISP_HAVE_DISPLAY
20 if (argc != 2) {
21 printf("Usage: %s <image name.[pgm,ppm,jpeg,png,tiff,bmp,ras,jp2]>\n", argv[0]);
22 return EXIT_FAILURE;
23 }
24
28
30 try {
31 vpImageIo::read(I, argv[1]);
32 }
33 catch (...) {
34 std::cout << "Cannot read image \"" << argv[1] << "\"" << std::endl;
35 return EXIT_FAILURE;
36 }
38
39 try {
41#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
42 std::shared_ptr<vpDisplay> pdisp = vpDisplayFactory::createDisplay(I, 10, 10, vpIoTools::getName(argv[1]), vpDisplay::SCALE_AUTO);
43#else
45#endif
47
51
56 std::cout << "Right click to quit" << std::endl;
57 std::cout << "Left click to inspect pixel position (i,j) and RGBa values\n" << std::endl;
59 bool quit = false;
60 vpImagePoint ip;
62 unsigned int scale_factor = vpDisplay::getDownScalingFactor(I);
64 while (!quit) {
65 if (vpDisplay::getClick(I, ip, button, false)) {
66 if (button == vpMouseButton::button3) {
67 quit = true;
68 }
69 else {
70 std::stringstream ss;
71 unsigned int i = static_cast<unsigned int>(ip.get_i());
72 unsigned int j = static_cast<unsigned int>(ip.get_j());
73 ss << i << " " << j << ": " << I[i][j];
74 std::cout << ss.str() << std::endl;
75 font.drawText(I, ss.str(), vpImagePoint(I.getHeight() - 20*scale_factor, 10), vpColor::red, vpColor::white);
78 }
79 }
81 }
82
84#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
85 delete pdisp;
86#endif
87 }
88 catch (const vpException &e) {
89 std::cout << "Catch an exception: " << e << std::endl;
90 }
91#else
92 (void)argc;
93 (void)argv;
94 std::cout << "No display available!" << std::endl;
95#endif
96}
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
@ 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)