34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import time
|
|
|
|
import cv2
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
import numpy as np
|
|
from common import global_para as gp
|
|
def cv2AddChineseText(draw, text ,position, textColor=(0, 255, 0), textSize=30):
|
|
# tp1 = time.time()
|
|
# if (isinstance(img, np.ndarray)): # ?D??¨º?¡¤?OpenCV¨ª???¨¤¨¤D¨ª
|
|
# img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
|
# tp2 = time.time()
|
|
# if gp.DebugPrint_flag:
|
|
# print("tp1 is ", (tp2 - tp1) * 1000)
|
|
# draw = ImageDraw.Draw(img)
|
|
tp2 = time.time()
|
|
fontStyle = ImageFont.truetype(
|
|
"./Font/msyh.ttc", textSize, encoding="utf-8")
|
|
tp3 = time.time()
|
|
if gp.DebugPrint_flag:
|
|
print("tp2 is ", (tp3 - tp2) * 1000)
|
|
|
|
draw.text(position, text, textColor, font=fontStyle)
|
|
|
|
tp4 = time.time()
|
|
if gp.DebugPrint_flag:
|
|
print("tp3 is ", (tp4 - tp3) * 1000)
|
|
return draw#cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)
|
|
# while(1):
|
|
# frame = cv2.imread("/data1/Hatcher/model/data_MPKFNet/result/hiv00024Detection/0000001.jpg")
|
|
# frame=cv2AddChineseText(frame,"ÊýÁ¿", (123, 123),(0, 255, 0), 30)
|
|
# cv2.imshow('capture',frame)
|
|
# if cv2.waitKey(1) & 0xFF == ord('q'):
|
|
# break
|