Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-autothreshold.cpp
1
2
3#include <cstdlib>
4#include <iostream>
5#include <visp3/core/vpConfig.h>
6#include <visp3/core/vpImage.h>
7#include <visp3/gui/vpDisplayFactory.h>
8#include <visp3/io/vpImageIo.h>
9
10#if defined(VISP_HAVE_MODULE_IMGPROC)
12#include <visp3/imgproc/vpImgproc.h>
14#endif
15
16int main(int argc, const char **argv)
17{
19#if defined(VISP_HAVE_MODULE_IMGPROC) && defined(VISP_HAVE_DISPLAY)
22
23#ifdef ENABLE_VISP_NAMESPACE
24 using namespace VISP_NAMESPACE_NAME;
25#endif
26
27 std::string input_filename = "grid36-03.pgm";
28
29 for (int i = 1; i < argc; i++) {
30 if (std::string(argv[i]) == "--input" && i + 1 < argc) {
31 input_filename = std::string(argv[i + 1]);
32 }
33 else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
34 std::cout << "Usage: " << argv[0] << " [--input <input image>] [--help]" << std::endl;
35 return EXIT_SUCCESS;
36 }
37 }
38
40 vpImageIo::read(I, input_filename);
41
42 vpImage<unsigned char> I_res(3 * I.getHeight(), 3 * I.getWidth());
43 I_res.insert(I, vpImagePoint(I.getHeight(), I.getWidth()));
44
45#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
46 std::shared_ptr<vpDisplay> display = vpDisplayFactory::createDisplay();
47#else
49#endif
50 display->setDownScalingFactor(vpDisplay::SCALE_2);
51 display->init(I_res);
52
54 vpImage<unsigned char> I_huang = I;
57 I_res.insert(I_huang, vpImagePoint());
58
60 vpImage<unsigned char> I_intermodes = I;
63 I_res.insert(I_intermodes, vpImagePoint(0, I.getWidth()));
64
66 vpImage<unsigned char> I_isodata = I;
69 I_res.insert(I_isodata, vpImagePoint(0, 2 * I.getWidth()));
70
72 vpImage<unsigned char> I_mean = I;
75 I_res.insert(I_mean, vpImagePoint(I.getHeight(), 0));
76
78 vpImage<unsigned char> I_otsu = I;
81 I_res.insert(I_otsu, vpImagePoint(I.getHeight(), 2 * I.getWidth()));
82
84 vpImage<unsigned char> I_triangle = I;
87 I_res.insert(I_triangle, vpImagePoint(2 * I.getHeight(), 0));
88
89 vpDisplay::display(I_res);
90
91 vpDisplay::displayText(I_res, 30, 20, "Huang", vpColor::red);
92 vpDisplay::displayText(I_res, 30, 20 + I.getWidth(), "Intermodes", vpColor::red);
93 vpDisplay::displayText(I_res, 30, 20 + 2 * I.getWidth(), "IsoData", vpColor::red);
94 vpDisplay::displayText(I_res, 30 + I.getHeight(), 20, "Mean", vpColor::red);
95 vpDisplay::displayText(I_res, 30 + I.getHeight(), 20 + I.getWidth(), "Original", vpColor::red);
96 vpDisplay::displayText(I_res, 30 + I.getHeight(), 20 + 2 * I.getWidth(), "Otsu", vpColor::red);
97 vpDisplay::displayText(I_res, 30 + 2 * I.getHeight(), 20, "Triangle", vpColor::red);
98
99 vpDisplay::flush(I_res);
100 vpDisplay::getClick(I_res);
101
102#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11) && defined(VISP_HAVE_DISPLAY)
103 if (display != nullptr) {
104 delete display;
105 }
106#endif
107#else
108 (void)argc;
109 (void)argv;
110#endif
111 return EXIT_SUCCESS;
112}
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 flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
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 ...
Definition of the vpImage class member functions.
Definition vpImage.h:131
VISP_EXPORT unsigned char autoThreshold(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, const vpAutoThresholdMethod &method, const unsigned char backgroundValue=0, const unsigned char foregroundValue=255)
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.