框选图中位置

代码

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
from PIL import Image,ImageDraw,ImageFont,ImageFilter
import random

#-------------------------------------
#filepath,[837,103][942,208]

#图片处理,框选
def pic_rectangle(filepath,bound):
    image = Image.open(filepath)
    draw = ImageDraw.Draw(image)
    # 坐标
    x1, y1 =bound[0]
    x2, y2 =bound[1]
    # outline 外线,fill填充
    draw.rectangle((x1, y1, x2, y2), outline="red", width=5)
    image.save('filepath', 'jpeg')
    #image.show()

if  __name__=="__main__":
    #调用
    filepath="./image/name.jpg"
    bound=[[744, 276],[1014, 366]]
    pic_rectangle(filepath,bound)

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄