Python将网络输出的检测结果的序号画在原图中
- 将得到位置坐标文件 ( x , y , w , h ) (x,y,w,h) (x,y,w,h) 是通过matlab转为mat文件
- 通过
draw.text
函数根据检测框的左上位置坐标,画出来。
// An core code
import PIL
import numpy as np
from PIL import Image
from PIL import ImageFile
import scipy.io as sio
from PIL import Image,ImageDraw,ImageFont
ImageFile.LOAD_TRUNCATED_IMAGES = True
Image.MAX_IMAGE_PIXELS = None
load_data = sio.loadmat('./result/new_out/img46.mat')
coor = load_data['coordinate']
font = ImageFont.truetype('simsun.ttc',24) #设置字体及其大小 不同字体可在c:\windows\font中找到
im01 = Image.open("E:\pyproject\\result\output\img46.jpg.jpg") #路径不能包含中文,要打双斜线
draw = ImageDraw.Draw(im01)
for i in range(len(coor)):
draw.text((coor[i, 0], coor[i,1]), str(i), fill=(0,255,0),font=font)
im01.save("./result/plot/46.jpg")