可以使用imgproc
類的boxFilter()
方法對影象執行SQRBox濾鏡操作。以下是這個方法的語法 -
sqrBoxFilter(src, dst, ddepth, ksize)
該方法接受以下引數 -
Mat
物件。Mat
物件。Size
物件。以下程式演示如何在給定影象上執行Sqrbox濾鏡操作。
package com.yiibai.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
。
執行上面範例程式碼,得到以下結果 -