Tag Archives: opencv cvFilter2D example on QT

OpenCV – cvFilter2D example on QT

#include <QtCore/QCoreApplication>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.h>

IplImage *image, *image1, *image2;;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    image  = cvLoadImage("C:\\Temp\\99.jpg");

    image1 = cvCreateImage(cvSize(image->width,image->height),8,1);
    image2 = cvCreateImage(cvSize(image->width,image->height),8,1);

    float kernel_vertical[]  = { -1,  0, 1,
                                   -2,  0, 2,
                                   -1,  0, 1};

    float kernel_horizontal[]  = { 1,  2, 1,
                                 0,  0, 0,
                                -1, -2,-1};

    //Vertical filter

    CvMat kernel_ver=cvMat(3,3,CV_32FC1,kernel_vertical);

    cvConvertImage(image,image1,CV_GRAY2BGR);

    cvFilter2D(image1, image1, &kernel_ver, cvPoint(-1,-1));

    cvShowImage("Vertical",image1);

    //Horizontal filter

    CvMat kernel_hor=cvMat(3,3,CV_32FC1,kernel_horizontal);

    cvConvertImage(image,image2,CV_GRAY2BGR);

    cvFilter2D(image2, image2, &kernel_hor, cvPoint(-1,-1));

    cvShowImage("Horizontal",image2);

    return a.exec();

}

 

1

2

3

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS