【问题标题】:"System error: new style getargs format but argument is not a tuple" when using cv2.blur使用 cv2.blur 时出现“系统错误:新样式 getargs 格式但参数不是元组”
【发布时间】:2012-10-24 21:36:25
【问题描述】:

我只是尝试使用 cv2(opencv python 绑定)对图像应用过滤器。这是我的代码的样子:

im = cv2.imread('./test_imgs/zzzyj.jpg')
cv2.imshow('Image', cv2.blur(im, 2)
cv2.waitKey(0)

这几乎是从documentation 复制和粘贴的。但是,它只是不起作用,没有比这条消息更多的痕迹:

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

GaussianBlur 也会出现同样的错误,但中值Blur 不会。有什么想法吗?

【问题讨论】:

    标签: python image-processing opencv


    【解决方案1】:

    对于 cv2.blur,您需要将 ksize 作为两个元素的元组,例如 (2,2)。但是对于 medianBlur,ksize = 3 就足够了。它会从中减去一个平方核。

    所以编写这样的代码:

    im = cv2.imread('./test_imgs/zzzyj.jpg')
    cv2.imshow('Image', cv2.blur(im, (3,3)))
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

    希望能成功!!!

    【讨论】:

    • (2,2) 不起作用,它需要除以模1
    • @ThomasWeller 不是所有东西都除以模 1 吗?
    • Nvm 我现在知道你的意思了。 (2,2)blur 工作,但对于 GaussianBlur 有一个断言 ksize.width%2==1
    【解决方案2】:

    升级 Pillow2.8.14.1.0 时遇到同样的问题。

    下面是一段运行Pillow==4.1.0时会产生异常的示例代码:

    from PIL import Image
    img = Image.new('RGBA', [100,100])
    # An empty mask is created to later overlay the original image (img)
    mask = Image.new('L', img.size, 255)
    # Get transparency (mask) layer pixels, they will be changed!
    data = mask.load()
    # The function used later
    def foo(x,y): return round(1.0*x/(y+1))
    # Update all pixels in the mask according to some function (foo)
    for x in range(img.size[0]):
        for y in range(img.size[1]):
            data[x,y] = foo(x,y)
    

    输出:

    Traceback (most recent call last):
      File "x.py", line 12, in <module>
        data[x,y] = foo(x,y)
    SystemError: new style getargs format but argument is not a tuple
    

    此处的实际错误与异常中所述的内容无关。实际上,分配给数据的数据类型是错误的。在2.8.1intfloat 都是有效的,所以像data[x,y]=1.0 这样的东西是有效的,而在4.1.0需要使用这样的整数:

    data[x,y]=1
    data[x,y]=int(1.0)
    

    因此,在上面的示例中,foo 可以重新定义为以下内容,以便在 2.8.14.1.0 中都可以使用。:

    def foo(x,y): return int(round(1.0*x/(y+1)))
    

    【讨论】:

    • 是的,这是我见过的最具误导性的错误消息之一 - 非常令人沮丧。
    猜你喜欢
    • 1970-01-01
    • 2015-12-16
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多