python3 opencv 輸出中文
import time
import torch.utils.data.distributed
from PIL import Image, ImageDraw, ImageFont
from distributed.protocol import serialize, deserialize
import cv2
import torch
import numpy as np
if __name__ == '__main__':
font = ImageFont.truetype("simhei.ttf", 22, encoding="utf-8")
for i in range(1000):
person_state = '站立'
img=cv2.imread('d:/bgs.jpg')
start=time.time()
cv2_im = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
pil_im = Image.fromarray(cv2_im)
draw = ImageDraw.Draw(pil_im)
print('time1', time.time() - start)#3ms
draw.text((50,50), person_state, (255, 0, 0), font=font)
img = cv2.cvtColor(np.array(pil_im), cv2.COLOR_RGB2BGR)
print('time2',time.time()-start)#8ms
# cv2.imshow('asdf',img)
# cv2.waitKeyEx()