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') cv2.imshow('Image', cv2.blur(im, 2) cv2.waitKey(0)
It's almost copy-and-paste from the documentation. However, it just doesn't work, with no more trace than this message:
SystemError: new style getargs format but argument is not a tuple
The same error occurs with GaussianBlur, but not with medianBlur. Any thoughts?
For cv2.blur, you need to give ksize as a tuple of two elements , like (2,2). But for medianBlur, ksize = 3 is sufficient. It will deduct a square kernel from it.
So make code like this :
im = cv2.imread('./test_imgs/zzzyj.jpg') cv2.imshow('Image', cv2.blur(im, (3,3))) cv2.waitKey(0) cv2.destroyAllWindows()
Hope it will work!!!
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 <module> 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)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With