我试图使用filter2D方法在OpenCV中找到卷积,但结果不正确
import cv2 as cv
import scipy.signal as sig
import numpy as np
b=np.asarray([[1,2,0,1,2],
[2,3,1,1,2],
[1,4,2,2,0],
[3,2,3,3,0],
[1,0,0,2,1]
],dtype=np.uint8)
w=np.asarray([[1,1,1],
[1,1,2],
[2,1,1]],dtype=np.uint8)
w_r=np.asarray([[1,1,1],
[2,1,1],
[1,1,1]
],dtype=np.uint8)
print(sig.convolve2d(b,w,mode="same"))
kernel_r=np.asarray([[1,1,1],[1,1,2],[2,1,1]])
print("-------")
print(cv.filter2D(b,-1,w_r))
Run Code Online (Sandbox Code Playgroud)
第一个输出是由 scipy.signal.convolve2D 生成的,这是正确的。第二个输出是由 OpenCV filter2D 生成的,这是不正确的。我怎样才能得到正确的结果。
[[ 8 10 10 7 7]
[15 18 20 14 9]
[18 23 26 18 10]
[15 21 22 16 11]
[ 8 13 13 9 8]]
-------
[[23 16 15 11 13]
[25 18 19 12 13]
[28 22 25 16 16]
[19 …Run Code Online (Sandbox Code Playgroud)