耿直boy6

PIL-Image、ImageDraw图像标记

 用方框标记图片

from PIL import Image
from PIL import ImageDraw
info = {"Match_Lat": "36.8890532", 
"LinkID": "42435642N",  
"BboxID": "ImageID": 
"timg.jpg",
"Pos_X": "360", 
"Pos_Y": "260",  
"Pos_W": "80", 
"Pos_H": "70",…………….}


def rectangle():
    img_name=info['ImageID']
    base = Image.open(img_name).convert('RGBA')
    d = ImageDraw.Draw(base)
    # rectangle(xy,fill, outline)
    # xy给出rectangle的左上和右下的像素点坐标,fill填充,outline是pencolor。
    pox_x=info['Pos_X']   #识别框图片坐标x
    pox_y=info['Pos_Y']   #识别框图片坐标x
    pox_h=info['Pos_H']
    pox_w=info['Pos_W']
    print([int(pox_x),int(pox_y),pox_h,pox_w])
    d.rectangle([int(pox_x), int(pox_y), int(pox_x)+int(pox_w), int(pox_y)+int(pox_h)], outline='RED')  # 加入fill="red"的话,就可以填充颜色
    #d.rectangle([60,30,120,80],outline='white')  #加入fill="red"的话,就可以填充颜色
    base.save('rectangle.png')
    base.close()

rectangle()

  

效果展示

 

posted on 2019-08-16 13:13  猫巴  阅读(1311)  评论(0编辑  收藏  举报

导航

原文:https://www.cnblogs.com/djfboai/ 版权声明:本文为博主原创文章,转载请附上博文链接!