> 文章列表 > 【OpenCV-Python】cvui 之 格式化文本打印

【OpenCV-Python】cvui 之 格式化文本打印

【OpenCV-Python】cvui 之 格式化文本打印

CVUI 之 打印

格式化输出文本

Python

【OpenCV-Python】cvui 之 格式化文本打印

import numpy as np 
import cv2
import cvuidef printf_test():WINDOW_NAME = 'Printf-Test'# 创建画布frame = np.zeros((300, 400, 3), np.uint8)# 初始化窗口cvui.init(WINDOW_NAME)#value = 3.1415927while 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:breakif __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);

【参考】

cvui-printf