Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-image-filter.cpp
1
2
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
11void display(vpImage<unsigned char> &I, const std::string &title);
12void display(vpImage<double> &D, const std::string &title);
13
14void display(vpImage<unsigned char> &I, const std::string &title)
15{
16#if defined(VISP_HAVE_X11)
17 vpDisplayX d(I);
18#elif defined(HAVE_OPENCV_HIGHGUI)
19 vpDisplayOpenCV d(I);
20#elif defined(VISP_HAVE_GTK)
21 vpDisplayGTK d(I);
22#elif defined(VISP_HAVE_GDI)
23 vpDisplayGDI d(I);
24#elif defined(VISP_HAVE_D3D9)
25 vpDisplayD3D d(I);
26#else
27 std::cout << "No image viewer is available..." << std::endl;
28#endif
29
30 vpDisplay::setTitle(I, title);
32 vpDisplay::displayText(I, 15, 15, "Click to continue...", vpColor::red);
35}
36
37void display(vpImage<double> &D, const std::string &title)
38{
39 vpImage<unsigned char> I; // Image to display
41 display(I, title);
42}
43
44int main(int argc, char **argv)
45{
46 try {
47 if (argc != 2) {
48 printf("Usage: %s <image name.[pgm,ppm,jpeg,png,bmp]>\n", argv[0]);
49 return EXIT_FAILURE;
50 }
54
55 try {
56 vpImageIo::read(I, argv[1]);
57 }
58 catch (...) {
59 std::cout << "Cannot read image \"" << argv[1] << "\"" << std::endl;
60 return EXIT_FAILURE;
61 }
62
63 display(I, "Original image");
64
69 display(F, "Blur (default)");
70
71 vpImageFilter::gaussianBlur(I, F, 7, 2.);
72 display(F, "Blur (var=2)");
73
78 display(dIx, "Gradient dIx");
79
84 display(dIy, "Gradient dIy");
85
88 vpImageFilter::canny(I, C, 5, -1., 3);
89 display(C, "Canny");
91
93 vpMatrix K(3, 3); // Sobel kernel along x
94 K[0][0] = 1;
95 K[0][1] = 0;
96 K[0][2] = -1;
97 K[1][0] = 2;
98 K[1][1] = 0;
99 K[1][2] = -2;
100 K[2][0] = 1;
101 K[2][1] = 0;
102 K[2][2] = -1;
106 vpImageFilter::filter(I, Gx, K);
108 display(Gx, "Sobel x");
109
111 size_t nlevel = 3;
112 std::vector<vpImage<unsigned char> > pyr(nlevel);
113 pyr[0] = I;
114 for (size_t i = 1; i < nlevel; i++) {
115 vpImageFilter::getGaussPyramidal(pyr[i - 1], pyr[i]);
116 display(pyr[i], "Pyramid");
117 }
119 return EXIT_SUCCESS;
120 }
121 catch (const vpException &e) {
122 std::cout << "Catch an exception: " << e << std::endl;
123 return EXIT_FAILURE;
124 }
125}
static const vpColor red
Definition vpColor.h:211
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:132
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:59
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void gaussianBlur(const vpImage< unsigned char > &I, vpImage< FilterType > &GI, unsigned int size=7, FilterType sigma=0., bool normalize=true)
static void getGradX(const vpImage< unsigned char > &I, vpImage< FilterType > &dIx)
static void filter(const vpImage< unsigned char > &I, vpImage< FilterType > &If, const vpArray2D< FilterType > &M, bool convolve=false)
static void canny(const vpImage< unsigned char > &I, vpImage< unsigned char > &Ic, unsigned int gaussianFilterSize, float thresholdCanny, unsigned int apertureSobel)
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
static void getGradY(const vpImage< unsigned char > &I, vpImage< FilterType > &dIy)
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:135
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:152