简体   繁体   English

使用cv2.blur时,“系统错误:新样式的getargs格式,但参数不是元组”

[英]“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 . 将Pillow2.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 intfloat都是有效的,所以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.14.1.0

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取 SystemError:新样式 getargs 格式,但参数不是元组。 我在使用 cv2.putText 时遇到了这个问题。 如何修复此错误? - Getting SystemError: new style getargs format but argument is not a tuple. Facing this issue when I was using cv2.putText. How to fix this error? Python 错误:SystemError: new style getargs format but argument is not a tuple - Python error: SystemError: new style getargs format but argument is not a tuple “新型getargs格式,但参数不是元组”枕头图像粘贴错误 - “New style getargs format but argument is not a tuple” Pillow image paste error 错误在哪里? “ SystemError:新样式的getargs格式,但参数不是元组” - Where is the error? “SystemError: new style getargs format but argument is not a tuple” SystemError:新样式的 getargs 格式但参数不是元组? - SystemError: new style getargs format but argument is not a tuple? SystemError:新样式getargs格式但参数不是OpenCV中的元组 - SystemError: new style getargs format but argument is not a tuple in OpenCV ImageDraw.draw.line():SystemError:新型getargs格式,但参数不是元组 - ImageDraw.draw.line() : SystemError: new style getargs format but argument is not a tuple python,opencv错误cv.rectangle SystemError:旧样式的getargs格式使用了新功能 - python, opencv error cv.rectangle SystemError: old style getargs format uses new features cv2.blur 中的暗边框 - Dark borders in cv2.blur 以元组为参数的新样式格式 - New style formatting with tuple as argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM