在这里插入图片描述

请添加图片描述

画框

from PIL import Image
from PIL import ImageDraw

# 模型-沙发

x = 0
y = 94
width = 462
height = 287

# x y width height
# 0 94 462 287
# 352 0 655 455
# 317 250 251 174
# 459 555 121 200
# 0 634 884 196
# 695 645 275 195

a = Image.open("模型-沙发.jpg")

aa = ImageDraw.ImageDraw(a)#用a来表示右侧这段

#在100,150起点画长800宽200的图形,填充白色,边框黑色,边框像素为1
# aa.rectangle((x, y, x+width, y+height), outline='yellow', width=1)
aa.rectangle((0, 94, 0+462, 94+287), outline='yellow', width=2)
aa.rectangle((352, 0, 352+655, 0+455), outline='yellow', width=2)
aa.rectangle((317, 250, 317+251, 250+174), outline='yellow', width=2)
aa.rectangle((459,555,459+121,555+200),outline ='yellow', width=2)
aa.rectangle((0, 634, 0+884, 634+196), outline='yellow', width=2)
aa.rectangle((695, 645, 695+275, 645+195), outline='yellow', width=2)

# a.save("2.jpg")
# print(aa)
a

在这里插入图片描述

抠图

from PIL import Image

x = 0
y = 94
width = 462
height = 287


a = Image.open("模型-沙发.jpg")

box = (x, y, x+width, y+height)
b = a.crop(box)
b

在这里插入图片描述

更多推荐