在opencv中scharr滤波器是配合sobel算子的运算而存在的。当sobel内核为3时,结果可能会产生比较明显的误差,针对这一问题,opencv提供了scharr函数。该函数只针对大小为3的核,并且运算速率和索贝尔函数一样快,结果更加精确,但抗噪性不如sobel函数。
使用scharr滤波器计算x或y方向的图像差分,它的参数变量和索贝尔一样。
函数:Imgproc。Scharr(垫src,垫dst, int ddepth, int dx, int dy,双,双三角洲,int borderType)
参数说明:
src:源图像
dst:检测结果图像
ddepth:输出图像的深度
dx: x方向上的差分阶数
dy: y方向上的差分阶数
规模:缩放因子
三角洲:结果存入输出图像前可选的δ值,默认为0
borderType:边界模式,默认BORDER_DEFAULT
示例代码:
公共静态void main (String [] args) { System.loadLibrary (Core.NATIVE_LIBRARY_NAME); 垫src=https://www.yisu.com/zixun/Imgcodecs.imread (“F: \ \ 2011031213205880528. jpg”); 垫dst=src.clone (); 垫dstx=src.clone (); 垫dsty=src.clone (); Imgproc。高斯模糊(src, dst,新的大小(3、3),0); Imgproc。cvtColor (dst, dst, Imgproc.COLOR_RGB2GRAY); Imgproc。Scharr (dst dstx 1, - 1, 0, 1, 0, Core.BORDER_DEFAULT); Imgcodecs.imwrite (“F: \ \ dstx.jpg dstx); Imgproc。Scharr (dst dsty 1, 0, 1, 1, 0, Core.BORDER_DEFAULT); Imgcodecs.imwrite (“F: \ \ dsty.jpg dsty); 核心。dsty addWeighted (dstx, 0.5, 0.5, 0, dst); Imgcodecs.imwrite (“F: \ \ dst.jpg”, dst); } >之前源图像:
X方向的scharr:
Y方向的scharr:
合并梯度后:
,以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
Java + opencv3.2.0之scharr滤波器