8. CVUI 2.7.0 组件:Printf (官方文档翻译)

官方文档链接:https://dovyski.github.io/cvui/components/printf/


printf

cvui::printf() 用于渲染一段可以使用 C printf() 样式格式化的文本。函数声明如下:

void printf(cv::Mat& theWhere, int theX, int theY, const char *theFmt, ...);

theWhere 是用于渲染图像的图像/帧,theX 是 X 坐标,theY 是 Y 的坐标,theFmt 是为 stdio 的 printf() 提供的格式化字符串,例如:printf(“Text: %d and %f”, 7, 3.1415)

cvui::printf() 几乎和 C语言 的 printf() 函数一样使用。下面是示例以及输出结果。

核心语句

double pi = 3.1415926;
cvui::printf(frame, 100, 80, "PI = %.7f", pi);

完整代码

#define CVUI_IMPLEMENTATION
#define CVUI_DISABLE_COMPILATION_NOTICES
#include "cvui.h"

#include <iostream>

#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

#define WINDOW_NAME "CVUI Test"

int main(int argc, char** argv)
{
	cvui::init(WINDOW_NAME);

	cv::Mat frame = cv::Mat(cv::Size(300, 200), CV_8UC3);
	frame = cv::Scalar(49, 52, 200);

	double pi = 3.1415926;
	cvui::printf(frame, 100, 80, "PI = %.7f", pi);

	cvui::imshow(WINDOW_NAME, frame);

	cv::waitKey(0);
	return 0;
}

运行结果

在这里插入图片描述


Text size and color

It is possible to customize the size and color of the text produced by cvui::printf(). The following function signature can be used in that case:

还可以自定义由 cvui::printf() 生成的文本的大小和颜色。在这种情况下,可以使用以下函数:

void printf (
    cv::Mat& theWhere,
    int theX,
    int theY,
    double theFontScale,
    unsigned int theColor,
    const char *theFmt,
    ...
);

where theWhere is the image/frame where the image will be rendered, theX is the position X, theY is the position Y, theFontScale is the size of the text, theColor is the color of the text in the format 0xRRGGBB, e.g. 0xff0000 for red, and theFmt is the formating string as it would be supplied for stdio’s printf(), e.g. “Text: %d and %f”, 7, 3.1415.

theWhere 是用于渲染的图像的图像/帧,theX 是 X 坐标,theY 是 Y 坐标,theFontScale 是文本的字号,theColor 是文本的颜色,格式为 0xRRGGBB,例如 0xff0000 表示红色,theFmt 是为 stdio 的 printf() 提供的格式化字符串,例如:printf(“Text: %d and %f”, 7, 3.1415)。

Below is an example of a text with customized size and color. Result on the screen is shown in Figure 2.

如下为具体示例和输出结果:

核心语句

double pi = 3.1415926;
cvui::printf(frame, 100, 80, 1.2, 0xffff00, "PI = %.7f", pi);

完整代码

#define CVUI_IMPLEMENTATION
#define CVUI_DISABLE_COMPILATION_NOTICES
#include "cvui.h"

#include <iostream>

#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

#define WINDOW_NAME "CVUI Test"

int main(int argc, char** argv)
{
	cvui::init(WINDOW_NAME);

	cv::Mat frame = cv::Mat(cv::Size(600, 200), CV_8UC3);
	frame = cv::Scalar(49, 52, 200);

	double pi = 3.1415926;
	cvui::printf(frame, 100, 80, 1.2, 0xffff00, "PI = %.7f", pi);

	cvui::imshow(WINDOW_NAME, frame);

	cv::waitKey(0);
	return 0;
}

运行结果
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值