对OpenCV的滤波器进行简单的使用,其中包括:方框滤波、均值滤波、高斯滤波、中值滤波、双边滤波、膨胀、腐蚀、开运算、闭运算、形态学梯度、顶帽和黑帽。
class Task13 {
public:
void deal() {
Mat src_img = imread("img\\1.jpg");
imshow("原图", src_img);
Mat out1;
boxFilter(src_img, out1, -1, Size(20, 20));
imshow("方框滤波", out1);
Mat out2;
blur(src_img, out2, Size(20, 20));
imshow("均值滤波", out2);
Mat out3;
GaussianBlur(src_img, out3, Size(21, 21), 0, 0);
imshow("高斯滤波", out3);
Mat out4;
medianBlur(src_img, out4, 21);
imshow("中值滤波", out4);
Mat out5;
bilateralFilter(src_img, out5, 20, 20 * 2, 20 / 2);
imshow("双边滤波", out5);
Mat out6;
Mat element = getStructuringElement(MORPH_RECT, Size(20, 20));
dilate(src_img, out6, element);
imshow("膨胀", out6);
Mat out7;
erode(src_img, out7, element);
imshow("腐蚀", out7);
Mat out8;
morphologyEx(src_img, out8, MORPH_OPEN, element);
imshow("开运算", out8);
Mat out9;
morphologyEx(src_img, out9, MORPH_CLOSE, element);
imshow("闭运算", out9);
Mat out10;
morphologyEx(src_img, out10, MORPH_GRADIENT, element);
imshow("形态学梯度", out10);
Mat out11;
morphologyEx(src_img, out11, MORPH_TOPHAT, element);
imshow("顶帽", out11);
Mat out12;
morphologyEx(src_img, out12, MORPH_BLACKHAT, element);
imshow("黑帽", out12);
waitKey(0);
}
};
如有错误请指正