CVUI 之 文本
渲染文本到图像上;
Python
import numpy as np
import cv2
import cvui
def text_test():
WINDOW_NAME = 'Text-Test'
checked = [False]
# 创建画布
frame = np.zeros((300, 400, 3), np.uint8)
# 初始化窗口
cvui.init(WINDOW_NAME)
while True:
# 画布填色
frame[:] = (200, 100, 200)
# 写文字
cvui.text(frame, 10, 10, 'The checkbox component')
# 显示
cvui.imshow(WINDOW_NAME, frame)
# ESC 退出
if cv2.waitKey(20) == 27:
break
if __name__ == '__main__':
text_test()
CPP
void text(cv::Mat& theWhere, int theX, int theY, const cv::String& theText, double theFontScale = DEFAULT_FONT_SCALE, unsigned int theColor = 0xCECECE);
参数
theWhere: 画布
theX: 画布的横坐标
theY: 画布的纵坐标
theText: 需要渲染的文本
theFontScale: 字体大小(以像素为单位)
theColor: 字体颜色
cvui::text(frame, 90, 50, "Hello world");