gpt4 book ai didi

python - ImageDraw.draw.line(): SystemError: new style getargs format but argument is not a tuple

转载 作者:行者123 更新时间:2023-12-05 06:41:50 28 4
gpt4 key购买 nike

我看到了多个关于此的问题,但无法找到我的问题的答案。基本上我只想在图像上画一条线,从 python 中的外部文件获取坐标。这是我的代码:

import Image, ImageDraw
import sys
import csv
im = Image.open("screen.png")
draw = ImageDraw.Draw(im)
with open("outputfile.txt") as file:
reader = csv.reader(file, delimiter=' ')
for row in reader:
if row[0] == 'H':
print "Horizontal line"
endx = row[2]
endy = int(row[3])+int(row[1])
elif row[0] == 'V':
print "Vertical line"
endx = row[2]+row[1]
endy = row[3]
x = row[2]
y = row[3]
draw.line((x,y, endx,endy), fill = 1)
im.show()

一切正常,除了行:

draw.line((x,y, endx,endy), fill = 1)

我在哪里看到以下错误:

File "dummy_test.py", line 21, in <module>
draw.line((x,y, endx,endy), fill = 1)
File "/Library/Python/2.7/site-packages/PIL-1.1.7-py2.7-macosx-10.10- intel.egg/ImageDraw.py", line 200, in line
self.draw.draw_lines(xy, ink, width)
SystemError: new style getargs format but argument is not a tuple

如果我对这些值进行硬编码,我看不出有什么问题。问题仅发生在上述情况下。谁能指出问题所在?

最佳答案

此消息通常意味着有人试图在需要元组的地方传递单独的值。

尽管pillow doc :

xy – Sequence of either 2-tuples like [(x, y), (x, y), ...] or numeric values like [x, y, x, y, ...].

你应该坚持这个版本:

draw.line([(x, y), (endx, endy)], fill = 1)

关于python - ImageDraw.draw.line(): SystemError: new style getargs format but argument is not a tuple,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39497458/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com