Imgproc.blur(Mat src, Mat dst, Size ksize, Point anchor, int borderType );
src : 图片
dst : 目标图
ksize :内核大小 Size(Weight, Height)
anchor : 内核锚点。
borderType : 边界填充方式。默认值填充方式BORDER_DEFAULT。边界填充说明
public static void main(String[] args) {
//读入图片
Mat src = Imgcodecs.imread("F:\\opencvPhoto\\photo\\opencv.jpg");
//灰度化
Imgproc.cvtColor(src, src, Imgproc.COLOR_BGR2GRAY);
//滤波
Mat dst = new Mat();
Imgproc.blur(src, dst, new Size(3, 3), new Point(1, 1), Core.BORDER_DEFAULT);
Imgcodecs.imwrite("F:\\opencvPhoto\\result\\dst.jpg", dst);
}
该函数原理较为简单,通过结果输出来验证上方的原理说明
public static void main(String[] args) {
//图片
Mat src = new Mat(new Size(3, 3), CvType.CV_32F);
src.put(0, 0, 1); src.put(0, 1, 2); src.put(0, 2, 3);
src.put(1, 0, 1); src.put(1, 1, 2); src.put(1, 2, 3);
src.put(2, 0, 1); src.put(2, 1, 2); src.put(2, 2, 3);
System.out.println("-----------图片------------------");
for (int row = 0; row < src.rows(); row++) {
for (int col = 0; col < src.cols(); col++) {
System.out.print(src.get(row, col)[0] + " ");
}
System.out.println();
}
System.out.println("-----------blur------------------");
Mat dst1 = new Mat();
Imgproc.blur(src, dst1, new Size(3, 3), new Point(1, 1), Core.BORDER_DEFAULT);
for (int row = 0; row < dst1.rows(); row++) {
for (int col = 0; col < dst1.cols(); col++) {
System.out.print(dst1.get(row, col)[0] + " ");
}
System.out.println();
}
}
结果输出
-----------图片------------------
1.0 2.0 3.0
1.0 2.0 3.0
1.0 2.0 3.0
-----------blur------------------
1.6666666269302368 2.0 2.3333332538604736
1.6666666269302368 2.0 2.3333332538604736
1.6666666269302368 2.0 2.3333332538604736
https://blog.csdn.net/qq_41553038/article/details/79984462