官方文檔鏈接: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;
}