Scharr也用于检测水平和垂直方向的图像的二阶导数。可以使用scharr()
方法对图像执行scharr
操作。以下是这种方法的语法 -
Scharr(src, dst, ddepth, dx, dy)
该方法接受以下参数 -
Mat
类的对象。Mat
类的对象。-1
)。x
导数的整数变量(0
或1
)。y
导数的整数变量(0
或1
)。示例
以下程序演示了如何将scharr
应用于给定的图像。
package com.zyiz.sobelderivatives; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class ScharrTest { 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/sample3.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.Scharr(src, dst, Imgproc.CV_SCHARR, 0, 1); // Writing the image Imgcodecs.imwrite("F:/worksp/opencv/images/sample3scharr_output.jpg", dst); System.out.println("Image processed"); } }
假定以下是上述程序中指定的输入图像sample3.jpg
。
执行上面示例代码,得到以下结果 -
将不同的值传递给最后一个参数(dx
和dy
),在0
和1
之间,将得到不同的输出。
// Applying scharr on the Image Imgproc.Scharr(src, dst, -1, 1, 1);