OpenCV平滑处理示例代码

#include<cv.h>
#include<highgui.h>

int main(int argc, char** argv)
{
    IplImage* img = cvLoadImage(argv[1]);
    IplImage* img1 = cvLoadImage(argv[1]);
    IplImage* img2 = cvLoadImage(argv[1]);
    IplImage* img3 = cvLoadImage(argv[1]);
    IplImage* img4 = cvLoadImage(argv[1]);
    IplImage* img5 = cvLoadImage(argv[1]);

    cvSmooth(img, img1, CV_BLUR);
    cvSmooth(img, img2, CV_BLUR_NO_SCALE);
    cvSmooth(img, img3, CV_MEDIAN);
    cvSmooth(img, img4, CV_GAUSSIAN);
    cvSmooth(img, img5, CV_BILATERAL);

    cvNamedWindow("原图", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("简单模糊", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("简单无缩放变换的模糊", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("中值模糊", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("高斯模糊", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("双边滤波", CV_WINDOW_AUTOSIZE);

    cvShowImage("原图", img);
    cvShowImage("简单模糊", img1);
    cvShowImage("简单无缩放变换的模糊", img2);
    cvShowImage("中值模糊", img3);
    cvShowImage("高斯模糊", img4);
    cvShowImage("双边滤波", img5);

    cvWaitKey(0);
    cvReleaseImage(&img);
    cvReleaseImage(&img1);
    cvReleaseImage(&img2);
    cvReleaseImage(&img3);
    cvReleaseImage(&img4);
    cvReleaseImage(&img5);
    cvDestroyWindow("原图");
    cvDestroyWindow("简单模糊");
    cvDestroyWindow("简单无缩放变换的模糊");
    cvDestroyWindow("中值模糊");
    cvDestroyWindow("高斯模糊");
    cvDestroyWindow("双边滤波");
}

注:此示例中没有设置cvSmooth()函数的后4个参数。

结果图:
这里写图片描述

posted @ 2016-05-23 15:51  huahai  阅读(216)  评论(0编辑  收藏  举报