“System error: new style getargs format but argument is not a tuple” when using cv2.blur

前端 未结 2 558
一个人的身影
一个人的身影 2020-12-17 08:06

I am just trying to apply a filter to an image using cv2, the opencv python bindings. Here is what my code look like:

im = cv2.imread(\'./test_imgs/zzzyj.jpg         


        
2条回答
  •  有刺的猬
    2020-12-17 08:23

    I have got the same issue when upgrading Pillow from 2.8.1 to 4.1.0.

    Here is a piece of example code that will generate the exception when running 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)
    

    Output:

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

    The actual error here has nothing to do with what is stated in the exception. It is actually the type of the data assigned to data that is wrong. In 2.8.1 both int and float are valid, so things like data[x,y]=1.0 is valid, while in 4.1.0 you need to use integers like any of this:

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

    So in the example above foo could be redefined to the following to work in both 2.8.1 and 4.1.0.:

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

提交回复
热议问题