:
PIL.ImageDraw.Draw.rectangle(xy, fill=None, outline=None)
Draws a rectangle.
Parameters:
xy – Four points to define the bounding box.
Sequence of either [(x0, y0), (x1, y1)]
or [x0, y0, x1, y1]
. The second point is just outside the drawn rectangle.
outline – Color to use for the outline.
fill – Color to use for the fill.
これはあなたが順序を渡す必要があることを意味し、documentationから同様:だから問題はあなたが4タプルを渡すことです
Image.getbbox()
Calculates the bounding box of the non-zero regions in the image.
Returns: The bounding box is returned as a 4-tuple defining the left, upper, right, and lower pixel coordinate. If the image is completely empty, this method returns None.
を関数は、いずれかのシーケンスを期待します[(x0, y0), (x1, y1)]
または[x0, y0, x1, y1]
あなたは4タプルwi list()
番目の関数が期待するものの第二の選択肢取得するリテラル:
from PIL import Image
from PIL import ImageChops
from PIL import ImageDraw
file1 = '300.jpg'
file2 = '300.jpg'
im1 = Image.open(file1)
im2 = Image.open(file2)
diff = ImageChops.difference(im1, im2).getbbox()
draw = ImageDraw.Draw(im2)
diff_list = list(diff) if diff else []
draw.rectangle(diff_list)
im2.convert('RGB').save('file3.jpg')
それとも、最初のタイプrectangle
への入力を交換したい場合は、次の操作を行うことができます見込ん:
from PIL import Image
from PIL import ImageChops
from PIL import ImageDraw
file1 = '300.jpg'
file2 = '300.jpg'
im1 = Image.open(file1)
im2 = Image.open(file2)
diff = ImageChops.difference(im1, im2).getbbox()
draw = ImageDraw.Draw(im2)
diff_list_tuples = >>> [diff[0:2], diff[2:]] if diff else [(None, None), (None, None)]
draw.rectangle(diff_list)
im2.convert('RGB').save('file3.jpg')
をお示しすることはできます完全なスタックトレースはどこにエラーがあるのか正確に見ることができますか?当然の –
@AvihooMamka: ファイル "test.py"、13行目、 draw.rectangle(差分) ファイルで 「C:\ユーザーはJohn.Smithj \のAppData \ローカル\プログラム\ Pythonの\を\長方形でPIL \ ImageDraw.py」、行192 \ Python36 \ libには\サイト - パッケージは、 self.draw.draw_rectangle(XY、インク、0) 例外TypeError:引数には、あなたは以下の私の答えを試すことができますシーケンス –
でなければなりません。 –