【问题标题】:How to implement a kernel of size 1 in a Gaussian filter in opencv?如何在opencv的高斯滤波器中实现大小为1的内核?
【发布时间】:2018-02-13 06:18:08
【问题描述】:

我正在尝试创建一个 1 像素内核:

x = cv2.getGaussianKernel(1, 2)

我在高斯滤波器中使用它:

blur = cv2.GaussianBlur(img, x, 0)

结果出现错误:

SystemError: new style getargs format but argument is not a tuple

如何解决这个错误?

【问题讨论】:

    标签: python opencv gaussianblur


    【解决方案1】:

    您不能将内核传递给 GaussianBlur 函数。您必须传递内核大小。

    所以 x 应该是一个像 (5,5) 或 (3,3) 这样的元组

    内核大小值也应该是奇数和正数,并且可以不同。你不能使用 size(1,2) 因为 2 是偶数。

    如果您想查看高斯内核,请使用:

    cv2.getGaussianKernel(ksize, sigma[, ktype]) 
    

    前:

    kernel = cv2.getGaussianKernel(ksize=(1,1),sigma=2)
    

    如果您想使用内核模糊图像,请使用:

    cv2.GaussianBlur(src, ksize, sigmaX[, dst[, sigmaY[, borderType]]])
    

    前:

    cv2.GaussianBlur(src, ksize=(1,1))
    

    查看this

    【讨论】:

    • 帮助说明:possible future modifications of all this semantics, it is recommended to specify all of ksize, sigmaX, and sigmaY.
    • 在这种情况下,2 是 sigma。文档:Python:cv2.getGaussianKernel(ksize, sigma[, ktype]) → retval
    • 那么你必须将 ksize 和 sigma 传递给 gaussianBlur 本身。 cv2.GaussianBlur(src, ksize, sigmaX[, dst[, sigmaY[, borderType]]])
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 2012-12-13
    • 1970-01-01
    • 2018-01-26
    • 1970-01-01
    • 2017-05-09
    相关资源
    最近更新 更多