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()

  

效果展示

PIL-Image、ImageDraw图像标记

PIL-Image、ImageDraw图像标记

 

相关文章:

  • 2022-12-23
  • 2021-08-22
  • 2021-08-25
  • 2021-04-30
  • 2022-12-23
  • 2021-11-04
  • 2021-05-23
  • 2022-12-23
猜你喜欢
  • 2022-01-11
  • 2022-01-01
  • 2021-04-25
  • 2022-12-23
  • 2021-06-26
相关资源
相似解决方案