在opencv中scharr濾波器是配合sobel算子的運算而存在的。當sobel內核為3時,結果可能會產生比較明顯的誤差,針對這一問題,opencv提供了scharr函數。該函數只針對大小為3的核,并且運算速率和sobel函數一樣快,結果更加精確,但抗噪性不如sobel函數。
使用scharr濾波器計算x或y方向的圖像差分,它的參數變量和sobel一樣。
函數:imgproc.scharr(mat src, mat dst, int ddepth, int dx, int dy, double scale, double delta, int bordertype)
參數說明:
src:源圖像
dst:檢測結果圖像
ddepth:輸出圖像的深度
dx:x方向上的差分階數
dy:y方向上的差分階數
scale:縮放因子
delta:結果存入輸出圖像前可選的delta值,默認為0
bordertype:邊界模式,默認border_default
示例代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
public static void main(string[] args) { system.loadlibrary(core.native_library_name); mat src = imgcodecs.imread( "f:\\2011031213205880528.jpg" ); mat dst = src.clone(); mat dstx = src.clone(); mat dsty = src.clone(); imgproc.gaussianblur(src, dst, new size( 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); core.addweighted(dstx, 0.5 , dsty, 0.5 , 0 , dst); imgcodecs.imwrite( "f:\\dst.jpg" , dst); } |
源圖像:
x方向的scharr:
y方向的scharr:
合并梯度后:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://blog.csdn.net/m1109048058/article/details/77412371