Matlab's Conv2 equivalent in OpenCV

前端 未结 2 1992
予麋鹿
予麋鹿 2020-12-21 17:06

I have been trying to do Convolution of a 2D Matrix using OpenCV. I actually went through this code http://blog.timmlinder.com/2011/07/opencv-equivalent-to-matlabs-conv2-fun

2条回答
  •  执笔经年
    2020-12-21 17:32

    If you are using OpenCV with Python 2 binding you can use Scipy as long as your images will be ndarrays:

    >>> from scipy import signal
    >>> A = np.array([[1,-2], [3,4]])
    >>> B = np.array([[-0.707, 0.707]])
    >>> signal.convolve2d(A,B)
    array([[-0.707,  2.121, -1.414],
          [-2.121, -0.707,  2.828]])
    

    Be sure that you use the full mode (which is set by default) if you want to achieve the same result as in matlab as long as if you use 'same' mode Scipy will center differently from Matlab.

提交回复
热议问题