[英]“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. 我只是尝试使用cv2(opencv python绑定)将过滤器应用于图像。 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. GaussianBlur会出现相同的错误,但不会出现medianBlur错误。 Any thoughts?
有什么想法吗?
For cv2.blur, you need to give ksize as a tuple of two elements , like (2,2). 对于cv2.blur,您需要将ksize作为两个元素的元组,如(2,2)。 But for medianBlur, ksize = 3 is sufficient.
但对于medianBlur,ksize = 3就足够了。 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
. 将Pillow从
2.8.1
升级到4.1.0
时,我遇到了同样的问题。
Here is a piece of example code that will generate the exception when running Pillow==4.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)
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: 在
2.8.1
int
和float
都是有效的,所以data[x,y]=1.0
是有效的,而在4.1.0
你需要使用像这样的整数:
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
.: 因此,在上面的示例中,可以将
foo
重新定义为以下内容,以便在2.8.1
和4.1.0
。
def foo(x,y): return int(round(1.0*x/(y+1)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.