官方文档链接:https://dovyski.github.io/cvui/components/checkbox/
Checkbox
cvui::checkbox() 渲染一个复选框,函数声明如下:
bool checkbox (
cv::Mat& theWhere,
int theX,
int theY,
const cv::String& theLabel,
bool *theState,
unsigned int theColor = 0xCECECE
)
theWhere 是要渲染图像的图像/帧,theX 是 X 的坐标,theY 是 Y 的坐标,theLabel 是可单击复选框方框旁边显示的文本,theState 描述复选框当前的状态(true 表示复选框已选中),theColor 是标签的颜色,格式为 0xRRGGBB,例如 0xff0000 表示红色。
cvui::checkbox() 返回一个布尔值,表示复选框的当前状态:如果选中则为 true,否则为 false。
下面是使用 cvui::checkbox 的示例以及结果展示:
#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);
bool checked1 = false;
bool checked2 = true;
while (true)
{
cvui::checkbox(frame, 100, 90, "Checkbox 1", &checked1);
cvui::checkbox(frame, 100, 120, "Checkbox 2", &checked2);
cvui::imshow(WINDOW_NAME, frame);
if (cv::waitKey(20) == 27)
break;
}
return 0;
}
运行结果