1 #include "opencv2/imgproc/imgproc.hpp" 2 #include "opencv2/highgui/highgui.hpp" 3 #include <stdlib.h> 4 #include <stdio.h> 5 6 using namespace cv; 7 8 /** @函数main */ 9 int main ( int argc, char** argv ) 10 { 11 /// 声明变量 12 Mat src, dst; 13 14 Mat kernel; 15 Point anchor; 16 double delta; 17 int ddepth; 18 int kernel_size; 19 char* window_name = "filter2D Demo"; 20 21 int c; 22 23 /// 载入图像 24 src = imread( argv[1] ); 25 26 if( !src.data ) 27 { return -1; } 28 29 /// 创建窗口 30 namedWindow( window_name, CV_WINDOW_AUTOSIZE ); 31 32 /// 初始化滤波器参数 33 anchor = Point( -1, -1 ); 34 delta = 0; 35 ddepth = -1; 36 37 /// 循环 - 每隔0.5秒,用一个不同的核来对图像进行滤波 38 int ind = 0; 39 while( true ) 40 { 41 c = waitKey(500); 42 /// 按'ESC'可退出程序 43 if( (char)c == 27 ) 44 { break; } 45 46 /// 更新归一化块滤波器的核大小 47 kernel_size = 3 + 2*( ind%5 ); 48 kernel = Mat::ones( kernel_size, kernel_size, CV_32F )/ (float)(kernel_size*kernel_size); 49 50 /// 使用滤波器 51 filter2D(src, dst, ddepth , kernel, anchor, delta, BORDER_DEFAULT ); 52 imshow( window_name, dst ); 53 ind++; 54 } 55 56 return 0; 57 }