用方框標記圖片
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()
效果展示

