python PIL图像处理-框选


框选图中位置

代码

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)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM