简体   繁体   English

ImageDraw.draw.line():SystemError:新型getargs格式,但参数不是元组

[英]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.

相关问题 SystemError:新样式的 getargs 格式但参数不是元组? - SystemError: new style getargs format but argument is not a tuple? 错误在哪里? “ SystemError:新样式的getargs格式,但参数不是元组” - Where is the error? “SystemError: new style getargs format but argument is not a tuple” 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 SystemError:新样式getargs格式但参数不是OpenCV中的元组 - SystemError: new style getargs format but argument is not a tuple in OpenCV 获取 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? “新型getargs格式,但参数不是元组”枕头图像粘贴错误 - “New style getargs format but argument is not a tuple” Pillow image paste error 使用cv2.blur时,“系统错误:新样式的getargs格式,但参数不是元组” - “System error: new style getargs format but argument is not a tuple” when using cv2.blur python,opencv错误cv.rectangle SystemError:旧样式的getargs格式使用了新功能 - python, opencv error cv.rectangle SystemError: old style getargs format uses new features 尝试使用 PIL ImageDraw.Draw.line() 绘制连接两点的线 - Trying to draw lines that connect two points using PIL ImageDraw.Draw.line() 以元组为参数的新样式格式 - New style formatting with tuple as argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM