箱式过滤器操作与平均模糊操作相似; 它将双边图像应用于滤镜。 在这里,可以选择框是否应该正常化。
可以使用imgproc
类的boxFilter()
方法在图像上执行此操作。 以下是这种方法的语法 -
boxFilter(src, dst, ddepth, ksize, anchor, normalize, borderType)
该方法接受以下参数 -
Mat
对象。Mat
对象。Size
对象。以下程序演示如何对图像执行双边滤镜操作。
package com.zyiz.filtering; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Size; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class BoxFilterTest { public static void main( String[] args ) { // Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); // Reading the Image from the file and storing it in to a Matrix object String file = \\\"F:/worksp/opencv/images/sample2.jpg\\\"; Mat src = Imgcodecs.imread(file); // Creating an empty matrix to store the result Mat dst = new Mat(); // Creating the objects for Size and Point Size size = new Size(45, 45); Point point = new Point(-1, -1); // Applying Box Filter effect on the Image Imgproc.boxFilter(src, dst, 50, size, point, true, Core.BORDER_DEFAULT); // Writing the image Imgcodecs.imwrite(\\\"F:/worksp/opencv/images/sample2boxfilter.jpg\\\", dst); System.out.println(\\\"Image Processed\\\"); } }
假定以下是上述程序中指定的输入图像sample2.jpg
。
执行上面示例代码,得到以下结果 -