Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 494
Antonio Dourado Avatar asked Nov 05 '12 03:11

Antonio Dourado


2 Answers

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!!!

like image 125
Abid Rahman K Avatar answered Sep 25 '22 05:09

Abid Rahman K


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))) 
like image 26
UlfR Avatar answered Sep 24 '22 05:09

UlfR