13. CVUI 2.7.0 组件:Sparkline(官方文档翻译)

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


Sparkline

cvui::sparkline() 将 std::vector 的值渲染成图,函数声明如下:

void sparkline (
    cv::Mat& theWhere,
    std::vector<double>& theValues,
    int theX,
    int theY,
    int theWidth,
    int theHeight,
    unsigned int theColor = 0x00FF00
)

theWhere 是渲染图像的图像/帧,theX 是 X 坐标,theY 是 Y 坐标,theWidth 是 sparkline 的宽度, theHeight 是 sparkline 的高度,theColor 是 sparkline 的颜色,格式为 0xRRGGBB,例如:0xff0000 表示红色。

提示:如果提供给 cvui::sparkline() 函数一个空的 std::vector ,则会提示缺少数据。

下面是 sparkline 的示例和输出结果:

核心语句

std::vector<double> values;
for (int i = 0; i < 30; i++)
	values.push_back(rand() + 0.);

cvui::sparkline(frame, values, 10, 10, 280, 100);

输出结果
在这里插入图片描述

完整代码

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

#include <iostream>
#include <vector>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgcodecs/imgcodecs.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, 150), CV_8UC3);

	frame = cv::Scalar(100, 100, 100);

	std::vector<double> values;
	for (int i = 0; i < 30; i++)
		values.push_back(rand() + 0.);

	cvui::sparkline(frame, values, 10, 10, 280, 100);

	cvui::imshow(WINDOW_NAME, frame);

	cv::waitKey(0);
	return 0;
}
发布了73 篇原创文章 · 获赞 14 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/wangyuankl123/article/details/105411870
今日推荐