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