可以使用imgproc
类的boxFilter()
方法对图像执行SQRBox滤镜操作。以下是这个方法的语法 -
sqrBoxFilter(src, dst, ddepth, ksize)
该方法接受以下参数 -
Mat
对象。Mat
对象。Size
对象。以下程序演示如何在给定图像上执行Sqrbox滤镜操作。
package com.zyiz.filtering; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Size; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class SqrBoxFilterTest { 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(); // Applying Box Filter effect on the Image Imgproc.sqrBoxFilter(src, dst, -1, new Size(1, 1)); // Writing the image Imgcodecs.imwrite(\"F:/worksp/opencv/images/sample2sqrboxfilter.jpg\", dst); System.out.println(\"Image Processed\"); } }
假定以下是上述程序中指定的输入图像sample2.jpg
。
执行上面示例代码,得到以下结果 -