[英]ImageDraw.draw.line() : SystemError: new style getargs format but argument is not a tuple
I saw multiple questions on this but was not able to find answer to my problem. 我对此有多个问题,但找不到我的问题的答案。 Basically I just want to draw a line on an image taking the co-ordinates from a external file in python.
基本上,我只想在图像上画一条线,以python中的外部文件作为坐标。 And here goes my code :
这是我的代码:
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()
Everything works except the line : 一切正常,除了以下行:
draw.line((x,y, endx,endy), fill = 1)
where i see the following error : 在这里我看到以下错误:
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
If i hard-code the values, I see no problems. 如果我对值进行硬编码,则看不到任何问题。 Issue happens only on the above case.
问题仅在上述情况下发生。 Can anyone point out the problem?
谁能指出这个问题?
This message often means that one tries to pass separate values where a tuple is expected. 该消息通常意味着人们试图在期望元组的地方传递单独的值。
Despite pillow doc : 尽管有枕头文档 :
xy – Sequence of either 2-tuples like [(x, y), (x, y), ...] or numeric values like [x, y, x, y, ...].
xy –由[[x,y),(x,y),...]等2元组或[x,y,x,y,...]等数值组成的序列。
You should stick to this version: 您应该坚持以下版本:
draw.line([(x, y), (endx, endy)], fill = 1)
Looks like just few int(...)
were missing? 看起来只缺少几个
int(...)
?
--- a.py.ORIG 2016-09-14 20:54:47.442291244 +0200
+++ a.py 2016-09-14 20:53:34.990627259 +0200
@@ -1,4 +1,4 @@
-import Image, ImageDraw
+from PIL import Image, ImageDraw
import sys
import csv
im = Image.open("screen.png")
@@ -8,13 +8,13 @@
for row in reader:
if row[0] == 'H':
print "Horizontal line"
- endx = row[2]
+ endx = int(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]
+ endx = int(row[2])+int(row[1])
+ endy = int(row[3])
+ x = int(row[2])
+ y = int(row[3])
draw.line((x,y, endx,endy), fill = 1)
im.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.