方框滤波器是一种矩形的且滤波器中的所有值全部相等。
效果
函数原型:
CV_EXPORTS_W void boxFilter( InputArray src, OutputArray dst, int ddepth,
Size ksize, Point anchor = Point(-1,-1),
bool normalize = true,
int borderType = BORDER_DEFAULT );
src:输入图像
dst:输出图像
ddepth:输出图像深度(-1使用src.depth())。
ksize:模糊核的大小。
anchor :锚点;默认值点(-1,-1)表示锚点在内核中心。
normalize :指定内核是否按其区域标准化。
borderType :边界模式
其中anchor必须小于ksize。
代码:
void example()
{
cv::Mat input = cv::imread("C:\\Users\\chuan\\Desktop\\picture\\test.jpg"), output;
cv::namedWindow("example");
int size = 1, anchor_test = -1, anchor = -1;
cv::createTrackbar("Size", "example", &size, 20);
cv::createTrackbar("anchor", "example", &anchor_test, 20);
for(;;)
{
anchor = anchor_test;
if(anchor_test >= size)
anchor = size-1;
cv::boxFilter(input, output, -1, cv::Size(size,size) , cv::Point(anchor,anchor));
cv::imshow("example", output);
if(cv::waitKey(100) == 27)
break;
}
}