ViSP  2.9.0
tutorial-image-filter.cpp
1 
3 #include <visp/vpDisplayD3D.h>
4 #include <visp/vpDisplayGDI.h>
5 #include <visp/vpDisplayGTK.h>
6 #include <visp/vpDisplayX.h>
7 #include <visp/vpDisplayOpenCV.h>
8 #include <visp/vpImageIo.h>
9 #include <visp/vpImageFilter.h>
10 
11 void display(vpImage<unsigned char> &I, const std::string &title);
12 void display(vpImage<double> &D, const std::string &title);
13 
14 void display(vpImage<unsigned char> &I, const std::string &title)
15 {
16 #if defined(VISP_HAVE_X11)
17  vpDisplayX d(I);
18 #elif defined(VISP_HAVE_OPENCV)
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.c_str());
32  vpDisplay::displayCharString(I, 15,15, "Click to continue...", vpColor::red);
35 }
36 
37 void display(vpImage<double> &D, const std::string &title)
38 {
39  vpImage<unsigned char> I; // Image to display
41  display(I, title);
42 }
43 
44 int 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 -1;
50  }
51 
53 
54  try {
55  vpImageIo::read(I, argv[1]);
56  }
57  catch(...) {
58  std::cout << "Cannot read image \"" << argv[1] << "\"" << std::endl;
59  return -1;
60  }
61 
62  display(I, "Original image");
63 
66  display(F, "Blur (default)");
67 
68  vpImageFilter::gaussianBlur(I, F, 7, 2);
69  display(F, "Blur (var=2)");
70 
71  vpImage<double> dIx;
73  display(dIx, "Gradient dIx");
74 
75  vpImage<double> dIy;
77  display(dIy, "Gradient dIy");
78 
79 
80 #if (VISP_HAVE_OPENCV_VERSION >= 0x020100)
82  vpImageFilter::canny(I, C, 5, 15, 3);
83  display(C, "Canny");
84 #endif
85 
86  vpMatrix K(3,3); // Sobel kernel along x
87  K[0][0] = 1; K[0][1] = 0; K[0][2] = -1;
88  K[1][0] = 2; K[1][1] = 0; K[1][2] = -2;
89  K[2][0] = 1; K[2][1] = 0; K[2][2] = -1;
90  vpImage<double> Gx;
91  vpImageFilter::filter(I, Gx, K);
92  display(Gx, "Sobel x");
93 
94  size_t nlevel = 3;
95  std::vector< vpImage<unsigned char> > pyr(nlevel);
96  pyr[0] = I;
97  for (size_t i=1; i < nlevel; i++) {
98  vpImageFilter::getGaussPyramidal(pyr[i-1], pyr[i]);
99  display(pyr[i], "Pyramid");
100  }
101  return 0;
102  }
103  catch(vpException &e) {
104  std::cout << "Catch an exception: " << e << std::endl;
105  return 1;
106  }
107 }
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void getGradX(const vpImage< unsigned char > &I, vpImage< double > &dIx)
static void getGradY(const vpImage< unsigned char > &I, vpImage< double > &dIy)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:132
Define the X11 console to display images.
Definition: vpDisplayX.h:152
error that can be emited by ViSP classes.
Definition: vpException.h:76
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:1994
static const vpColor red
Definition: vpColor.h:167
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M)
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:206
The vpDisplayOpenCV allows to display image using the opencv library.
static void gaussianBlur(const vpImage< unsigned char > &I, vpImage< double > &GI, unsigned int size=7, double sigma=0., bool normalize=true)
virtual void setTitle(const char *title)=0
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
Definition: vpDisplayGTK.h:145
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
virtual bool getClick(bool blocking=true)=0
static void canny(const vpImage< unsigned char > &I, vpImage< unsigned char > &Ic, const unsigned int gaussianFilterSize, const double thresholdCanny, const unsigned int apertureSobel)
static void read(vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:278