Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
tutorial-autothreshold.cpp
1 
3 #include <cstdlib>
4 #include <iostream>
5 #include <visp3/core/vpImage.h>
6 #include <visp3/gui/vpDisplayGDI.h>
7 #include <visp3/gui/vpDisplayOpenCV.h>
8 #include <visp3/gui/vpDisplayX.h>
9 #include <visp3/io/vpImageIo.h>
10 
11 #if defined(VISP_HAVE_MODULE_IMGPROC)
12 #include <visp3/imgproc/vpImgproc.h>
15 #endif
16 
17 int main(int argc, const char **argv)
18 {
20 #if defined(VISP_HAVE_MODULE_IMGPROC) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
21  std::string input_filename = "grid36-03.pgm";
24 
25  for (int i = 1; i < argc; i++) {
26  if (std::string(argv[i]) == "--input" && i + 1 < argc) {
27  input_filename = std::string(argv[i + 1]);
28  } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
29  std::cout << "Usage: " << argv[0] << " [--input <input image>] [--help]" << std::endl;
30  return EXIT_SUCCESS;
31  }
32  }
33 
35  vpImageIo::read(I, input_filename);
36 
37  vpImage<unsigned char> I_res(3 * I.getHeight(), 3 * I.getWidth());
38  I_res.insert(I, vpImagePoint(I.getHeight(), I.getWidth()));
39 
40 #ifdef VISP_HAVE_X11
41  vpDisplayX d;
42 #elif defined(VISP_HAVE_GDI)
43  vpDisplayGDI d;
44 #elif defined(VISP_HAVE_OPENCV)
46 #endif
48  d.init(I_res);
49 
51  vpImage<unsigned char> I_huang = I;
54  I_res.insert(I_huang, vpImagePoint());
55 
57  vpImage<unsigned char> I_intermodes = I;
60  I_res.insert(I_intermodes, vpImagePoint(0, I.getWidth()));
61 
63  vpImage<unsigned char> I_isodata = I;
66  I_res.insert(I_isodata, vpImagePoint(0, 2 * I.getWidth()));
67 
69  vpImage<unsigned char> I_mean = I;
72  I_res.insert(I_mean, vpImagePoint(I.getHeight(), 0));
73 
75  vpImage<unsigned char> I_otsu = I;
78  I_res.insert(I_otsu, vpImagePoint(I.getHeight(), 2 * I.getWidth()));
79 
81  vpImage<unsigned char> I_triangle = I;
84  I_res.insert(I_triangle, vpImagePoint(2 * I.getHeight(), 0));
85 
86  vpDisplay::display(I_res);
87 
88  vpDisplay::displayText(I_res, 30, 20, "Huang", vpColor::red);
89  vpDisplay::displayText(I_res, 30, 20 + I.getWidth(), "Intermodes", vpColor::red);
90  vpDisplay::displayText(I_res, 30, 20 + 2 * I.getWidth(), "IsoData", vpColor::red);
91  vpDisplay::displayText(I_res, 30 + I.getHeight(), 20, "Mean", vpColor::red);
92  vpDisplay::displayText(I_res, 30 + I.getHeight(), 20 + I.getWidth(), "Original", vpColor::red);
93  vpDisplay::displayText(I_res, 30 + I.getHeight(), 20 + 2 * I.getWidth(), "Otsu", vpColor::red);
94  vpDisplay::displayText(I_res, 30 + 2 * I.getHeight(), 20, "Triangle", vpColor::red);
95 
96  vpDisplay::flush(I_res);
97  vpDisplay::getClick(I_res);
98 
99  return EXIT_SUCCESS;
100 #else
101  (void)argc;
102  (void)argv;
103  return 0;
104 #endif
105 }
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:149
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
virtual void setDownScalingFactor(unsigned int scale)
Definition: vpDisplay.cpp:231
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:134
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:217
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void insert(const vpImage< Type > &src, const vpImagePoint &topLeft)
Definition: vpImage.h:1115
VISP_EXPORT unsigned char autoThreshold(vpImage< unsigned char > &I, const vp::vpAutoThresholdMethod &method, const unsigned char backgroundValue=0, const unsigned char foregroundValue=255)
unsigned int getHeight() const
Definition: vpImage.h:188
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
unsigned int getWidth() const
Definition: vpImage.h:246