CVUI 之 打印
格式化输出文本
Python
import numpy as np
import cv2
import cvui
def printf_test():
WINDOW_NAME = 'Printf-Test'
# 创建画布
frame = np.zeros((300, 400, 3), np.uint8)
# 初始化窗口
cvui.init(WINDOW_NAME)
#
value = 3.1415927
while True:
# 画布填色
frame[:] = (50, 100, 180)
# 写文字
cvui.printf(frame, 10, 50, 0.8, 0x00ff00, "PI = %.2f", value)
# 显示
cvui.imshow(WINDOW_NAME, frame)
if cv2.waitKey(20) == 27:
break
if __name__ == '__main__':
printf_test()
CPP
原型
void printf(cv::Mat& theWhere, int theX, int theY, const char *theFmt, ...);
void printf(cv::Mat& theWhere, int theX, int theY, double theFontScale, unsigned int theColor, const char *theFmt, ...);
参数
theWhere: 画布
theX: 绘制的 x
theY: 绘制的 y
theFontScale: 字体大小
theColor: 字体颜色
theFmt: 格式化字符串
用例
printf(frame, 10, 15, 0.4, 0xff0000, "Text: %d and %f", 7, 3.1415);