#include
#include
#include
using namespace std;
using namespace cv;
#define BOX_FILTER_ORIGINAL_WINDOW_NAME "方框滤波【原图】"
#define BOX_FILTER_RESULT_WINDOW_NAME "方框滤波【效果图】"
int main()
{
//载入原图
Mat image = imread("test.jpg");
//创建窗口
namedWindow(BOX_FILTER_ORIGINAL_WINDOW_NAME);
namedWindow(BOX_FILTER_RESULT_WINDOW_NAME);
//显示原图
imshow(BOX_FILTER_ORIGINAL_WINDOW_NAME, image);
//进行滤波操作
Mat out;
boxFilter(image, out, -1, Size(5, 5));
//显示效果图
imshow(BOX_FILTER_RESULT_WINDOW_NAME, out);
waitKey(0);
return 0;
}
#include
#include
#include
using namespace std;
using namespace cv;
#define BOX_FILTER_ORIGINAL_WINDOW_NAME "均值滤波【原图】"
#define BOX_FILTER_RESULT_WINDOW_NAME "均值滤波【效果图】"
int main()
{
//载入原图
Mat image = imread("test.jpg");
//创建窗口
namedWindow(BOX_FILTER_ORIGINAL_WINDOW_NAME);
namedWindow(BOX_FILTER_RESULT_WINDOW_NAME);
//显示原图
imshow(BOX_FILTER_ORIGINAL_WINDOW_NAME, image);
//进行滤波操作
Mat out;
blur(image, out, Size(5, 5));
//显示效果图
imshow(BOX_FILTER_RESULT_WINDOW_NAME, out);
waitKey(0);
return 0;
}
#include
#include
#include
using namespace std;
using namespace cv;
#define BOX_FILTER_ORIGINAL_WINDOW_NAME "高斯滤波【原图】"
#define BOX_FILTER_RESULT_WINDOW_NAME "高斯滤波【效果图】"
int main()
{
//载入原图
Mat image = imread("test.jpg");
//创建窗口
namedWindow(BOX_FILTER_ORIGINAL_WINDOW_NAME);
namedWindow(BOX_FILTER_RESULT_WINDOW_NAME);
//显示原图
imshow(BOX_FILTER_ORIGINAL_WINDOW_NAME, image);
//进行滤波操作
Mat out;
GaussianBlur(image, out, Size(5, 5), 0, 0);
//显示效果图
imshow(BOX_FILTER_RESULT_WINDOW_NAME, out);
waitKey(0);
return 0;
}
#include
#include
using namespace std;
using namespace cv;
#define BOX_FILTER_WINDOW "方框滤波"
#define MEAN_BLUR_WINDOW "均值滤波"
#define GAUSSIAN_BLUR_WINDOW "高斯滤波"
Mat g_srcImage, g_dstImage1, g_dstImage2, g_dstImage3; //存储图片的Mat类型
int g_nBoxFilterValue = 3; //方框滤波参数值
int g_nMeanBlurValue = 3; //均值滤波参数值
int g_nGaussianBlurValue = 3; //高斯滤波参数值
//轨迹条的回调函数
static void on_BoxFilter(int, void *); //方框滤波
static void on_MeanBlur(int, void *); //均值滤波
static void on_GaussianBlur(int, void *); //高斯滤波
int main()
{
//改变console字体颜色
system("color5E");
//载入原图
g_srcImage = imread("test.jpg");
if (!g_srcImage.data)
{
printf("读取srcImage错误!\n");
return -1;
}
//复制原图到三个Mat类型中
g_dstImage1 = g_srcImage.clone();
g_dstImage2 = g_srcImage.clone();
g_dstImage3 = g_srcImage.clone();
//显示原图
imshow("原图窗口", g_srcImage);
//1.方框滤波
//创建窗口
namedWindow(BOX_FILTER_WINDOW);
//创建轨迹条
createTrackbar("内核值:", BOX_FILTER_WINDOW, &g_nBoxFilterValue, 40, on_BoxFilter);
on_BoxFilter(g_nBoxFilterValue, 0);
imshow(BOX_FILTER_WINDOW, g_dstImage1);
//2.均值滤波
//创建窗口
namedWindow(MEAN_BLUR_WINDOW);
//创建轨迹条
createTrackbar("内核值:", MEAN_BLUR_WINDOW, &g_nMeanBlurValue, 40, on_MeanBlur);
on_MeanBlur(g_nMeanBlurValue, 0);
//3.高斯滤波
//创建窗口
namedWindow(GAUSSIAN_BLUR_WINDOW);
createTrackbar("内核值:", GAUSSIAN_BLUR_WINDOW, &g_nGaussianBlurValue, 40, on_GaussianBlur);
on_GaussianBlur(g_nGaussianBlurValue, 0);
//输出一些帮助信息
cout << endl << "\t请调整滚动条观察图像效果\n"
<< "\t按下“q”键时,程序退出!\n";
//按下"q"键时,程序退出
while (char(waitKey(1)) != 'q');
destroyAllWindows();
return 0;
}
static void on_BoxFilter(int, void *)
{
boxFilter(g_srcImage, g_dstImage1, -1, Size(g_nBoxFilterValue + 1, g_nBoxFilterValue + 1));
imshow("方框滤波", g_dstImage1);
}
static void on_MeanBlur(int, void *)
{
blur(g_srcImage, g_dstImage2, Size(g_nMeanBlurValue + 1, g_nMeanBlurValue + 1), Point(-1, -1));
imshow("均值滤波", g_dstImage2);
}
static void on_GaussianBlur(int, void *)
{
GaussianBlur(g_srcImage, g_dstImage3, Size(g_nGaussianBlurValue*2 + 1, g_nGaussianBlurValue*2 + 1), 0, 0);
imshow("高斯滤波", g_dstImage3);
}