30 lines
962 B
Python
30 lines
962 B
Python
|
import cv2
|
||
|
import numpy as np
|
||
|
|
||
|
fontConstant = 1/6000
|
||
|
w=10200
|
||
|
fontSize = round(fontConstant*w)
|
||
|
|
||
|
#(label_width, label_height), baseline = cv2.getTextSize(label, FONT, FONT_SCALE, FONT_THICKNESS)
|
||
|
#label_patch = np.zeros((label_height + baseline, label_width, 3), np.uint8)
|
||
|
#label_patch[:,:] = bg_color
|
||
|
|
||
|
def generate_text (text, fontSize, rotation) :
|
||
|
rgb_color=(255,255,255)
|
||
|
color = tuple(reversed(rgb_color))
|
||
|
|
||
|
print(rotation)
|
||
|
print(fontSize)
|
||
|
print(text)
|
||
|
print(len(text))
|
||
|
(w, h), baseline = cv2.getTextSize(text, (round(w/2), round(h/2)), cv2.FONT_HERSHEY_PLAIN, 1, [0, 0, 0], 3, cv2.LINE_AA)
|
||
|
w = (fontSize * len(text))
|
||
|
h = (fontSize)
|
||
|
print(f'{w}x{h}')
|
||
|
image = np.zeros((h + baseline, w, 3), np.uint8)
|
||
|
image[:] = color
|
||
|
image = cv2.cvtColor(image, cv2.COLOR_BGR2BGRA)
|
||
|
image = cv2.putText(image, text, (round(w/2), round(h/2)), cv2.FONT_HERSHEY_PLAIN, 1, [0, 0, 0], 3, cv2.LINE_AA)
|
||
|
|
||
|
cv2.imwrite('test.png', image)
|
||
|
generate_text("example", fontSize, 90)
|