本文是在参考毛星云大神的文章后写的,文章链接: http://blog.csdn.net/poem_qianmo/article/details/22745559
void cv::blur( InputArray src, OutputArray dst, Size ksize, Point anchor, int borderType ) { boxFilter( src, dst, -1, ksize, anchor, true, borderType );//见补充一 } //================补充一: boxFilter================// 基本流程:复制原图到临时变量->处理ddepth<0的情况(在这里ddepth初始化值为-1)->处理边界类型->调用FilterEngine滤波引擎 void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, Size ksize, Point anchor, bool normalize, int borderType ) { Mat src = _src.getMat(); int sdepth = src.depth(), cn = src.channels();//源图像的深度,源图像的通道索引 //处理ddepth小于零的情况 if( ddepth < 0 ) ddepth = sdepth; _dst.create( src.size(), CV_MAKETYPE(ddepth, cn) );//初始化目标图 Mat dst = _dst.getMat();//复制目标图像Mat数据到临时变量,用于稍后的操作 //调整卷积核的大小 if( borderType != BORDER_CONSTANT && normalize && (borderType & BORDER_ISOLATED) != 0 ) { if( src.rows == 1 ) ksize.height = 1; if( src.cols == 1 ) ksize.width = 1; } //若之前有过HAVE_TEGRA_OPTIMIZATION优化选项的定义,执行宏中的tegra优化 #ifdef HAVE_TEGRA_OPTIMIZATION if ( tegra::box(src, dst, ksize, anchor, normalize, borderType) ) return; #endif //调用FilterEngine滤波引擎,开始正式滤波;创建均值滤波器引擎 Ptr<FilterEngine> f = createBoxFilter( src.type(), dst.type(), ksize, anchor, normalize, borderType ); f->apply( src, dst ); } //==============补充二:Ptr<FilterEngine> ================// Ptr<FilterEngine>是opencv进行滤波操作的引擎,ptr是动态创建指针模板,模板的类型为 FilterEngine