Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
tutorial-image-filter.cpp
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImageFilter.h>
#include <visp3/gui/vpDisplayD3D.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayGTK.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpImageIo.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
void display(vpImage<unsigned char> &I, const std::string &title);
void display(vpImage<double> &D, const std::string &title);
void display(vpImage<unsigned char> &I, const std::string &title)
{
#if defined(VISP_HAVE_X11)
vpDisplayX d(I);
#elif defined(HAVE_OPENCV_HIGHGUI)
#elif defined(VISP_HAVE_GTK)
#elif defined(VISP_HAVE_GDI)
#elif defined(VISP_HAVE_D3D9)
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
vpDisplay::displayText(I, 15, 15, "Click to continue...", vpColor::red);
}
void display(vpImage<double> &D, const std::string &title)
{
vpImage<unsigned char> I; // Image to display
display(I, title);
}
int main(int argc, char **argv)
{
try {
if (argc != 2) {
printf("Usage: %s <image name.[pgm,ppm,jpeg,png,bmp]>\n", argv[0]);
return EXIT_FAILURE;
}
try {
vpImageIo::read(I, argv[1]);
}
catch (...) {
std::cout << "Cannot read image \"" << argv[1] << "\"" << std::endl;
return EXIT_FAILURE;
}
display(I, "Original image");
display(F, "Blur (default)");
display(F, "Blur (var=2)");
display(dIx, "Gradient dIx");
display(dIy, "Gradient dIy");
vpImageFilter::canny(I, C, 5, -1., 3);
display(C, "Canny");
vpMatrix K(3, 3); // Sobel kernel along x
K[0][0] = 1;
K[0][1] = 0;
K[0][2] = -1;
K[1][0] = 2;
K[1][1] = 0;
K[1][2] = -2;
K[2][0] = 1;
K[2][1] = 0;
K[2][2] = -1;
display(Gx, "Sobel x");
size_t nlevel = 3;
std::vector<vpImage<unsigned char> > pyr(nlevel);
pyr[0] = I;
for (size_t i = 1; i < nlevel; i++) {
vpImageFilter::getGaussPyramidal(pyr[i - 1], pyr[i]);
display(pyr[i], "Pyramid");
}
return EXIT_SUCCESS;
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
}
static const vpColor red
Definition: vpColor.h:217
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Definition: vpDisplayD3D.h:106
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:130
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:133
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
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 gaussianBlur(const vpImage< ImageType > &I, vpImage< FilterType > &GI, unsigned int size=7, FilterType sigma=0., bool normalize=true, 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 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: vpImageIo.cpp:147
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169