用方框标记图片
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()