Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-image-filter.cpp
1
2#include <visp3/core/vpConfig.h>
3#include <visp3/core/vpImageFilter.h>
4#include <visp3/gui/vpDisplayD3D.h>
5#include <visp3/gui/vpDisplayGDI.h>
6#include <visp3/gui/vpDisplayGTK.h>
7#include <visp3/gui/vpDisplayOpenCV.h>
8#include <visp3/gui/vpDisplayX.h>
9#include <visp3/io/vpImageIo.h>
10
11#ifdef ENABLE_VISP_NAMESPACE
12using namespace VISP_NAMESPACE_NAME;
13#endif
14
15void display(vpImage<unsigned char> &I, const std::string &title);
16void display(vpImage<double> &D, const std::string &title);
17
18void display(vpImage<unsigned char> &I, const std::string &title)
19{
20#if defined(VISP_HAVE_X11)
21 vpDisplayX d(I);
22#elif defined(HAVE_OPENCV_HIGHGUI)
24#elif defined(VISP_HAVE_GTK)
25 vpDisplayGTK d(I);
26#elif defined(VISP_HAVE_GDI)
27 vpDisplayGDI d(I);
28#elif defined(VISP_HAVE_D3D9)
29 vpDisplayD3D d(I);
30#else
31 std::cout << "No image viewer is available..." << std::endl;
32#endif
33
34 vpDisplay::setTitle(I, title);
36 vpDisplay::displayText(I, 15, 15, "Click to continue...", vpColor::red);
39}
40
41void display(vpImage<double> &D, const std::string &title)
42{
43 vpImage<unsigned char> I; // Image to display
45 display(I, title);
46}
47
48int main(int argc, char **argv)
49{
50 try {
51 if (argc != 2) {
52 printf("Usage: %s <image name.[pgm,ppm,jpeg,png,bmp]>\n", argv[0]);
53 return EXIT_FAILURE;
54 }
58
59 try {
60 vpImageIo::read(I, argv[1]);
61 }
62 catch (...) {
63 std::cout << "Cannot read image \"" << argv[1] << "\"" << std::endl;
64 return EXIT_FAILURE;
65 }
66
67 display(I, "Original image");
68
73 display(F, "Blur (default)");
74
75 vpImageFilter::gaussianBlur(I, F, 7, 2.);
76 display(F, "Blur (var=2)");
77
82 display(dIx, "Gradient dIx");
83
88 display(dIy, "Gradient dIy");
89
92 vpImageFilter::canny(I, C, 5, -1., 3);
93 display(C, "Canny");
95
97 vpMatrix K(3, 3); // Sobel kernel along x
98 K[0][0] = 1;
99 K[0][1] = 0;
100 K[0][2] = -1;
101 K[1][0] = 2;
102 K[1][1] = 0;
103 K[1][2] = -2;
104 K[2][0] = 1;
105 K[2][1] = 0;
106 K[2][2] = -1;
110 vpImageFilter::filter(I, Gx, K);
112 display(Gx, "Sobel x");
113
115 size_t nlevel = 3;
116 std::vector<vpImage<unsigned char> > pyr(nlevel);
117 pyr[0] = I;
118 for (size_t i = 1; i < nlevel; i++) {
119 vpImageFilter::getGaussPyramidal(pyr[i - 1], pyr[i]);
120 display(pyr[i], "Pyramid");
121 }
123 return EXIT_SUCCESS;
124 }
125 catch (const vpException &e) {
126 std::cout << "Catch an exception: " << e << std::endl;
127 return EXIT_FAILURE;
128 }
129}
static const vpColor red
Definition vpColor.h:198
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:135
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)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Definition vpException.h:60
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void canny(const vpImage< unsigned char > &I, vpImage< unsigned char > &Ic, const unsigned int &gaussianFilterSize, const float &thresholdCanny, const unsigned int &apertureSobel)
static void getGradX(const vpImage< unsigned char > &I, vpImage< FilterType > &dIx, const vpImage< bool > *p_mask=nullptr)
static void filter(const vpImage< ImageType > &I, vpImage< FilterType > &If, const vpArray2D< FilterType > &M, bool convolve=false, const vpImage< bool > *p_mask=nullptr)
static void gaussianBlur(const vpImage< ImageType > &I, vpImage< OutputType > &GI, unsigned int size=7, FilterType sigma=0., bool normalize=true, const vpImage< bool > *p_mask=nullptr)
static void getGradY(const vpImage< unsigned char > &I, vpImage< FilterType > &dIy, const vpImage< bool > *p_mask=nullptr)
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175