9. CVUI 2.7.0 组件:Counter (官方文档翻译)

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


counter

cvui::counter() 可以为整数或双精度浮点数提供一个计算器,用户可以通过单击上下箭头来增加/减少该计数器。函数声明如下:

int counter (
    cv::Mat& theWhere,
    int theX,
    int theY,
    int *theValue,
    int theStep = 1,
    const char *theFormat = "%d"
)
double counter (
    cv::Mat& theWhere,
    int theX,
    int theY,
    double *theValue,
    double theStep = 0.5,
    const char *theFormat = "%.2f"
)

theWhere 是用于渲染图像的图像/帧,theX 是 X 坐标,theY 是 Y 坐标,theValue 是计数器的当前值,theStep 是用户与 counter 按钮交互时递增和递减的量,theFormat 是 counter 显示值的方式,因为它是由 stdio 的 printf() 输出的,"%d" 表示值将以整数形式显示,"%0d" 表示带一个前导 0 的整数,等等。

cvui::counter() 返回与计数器当前值相对应的数字。

如下是计数器的示例和显示结果:

核心语句

int count = 2;
cvui::counter(frame, 280, 90, &count);

完整代码

#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);

	int count = 2;

	while (true)
	{
		cvui::counter(frame, 280, 90, &count);

		cvui::imshow(WINDOW_NAME, frame);
		
		if (cv::waitKey(20) == 27)
			break;
	}

	return 0;
}

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

注意

因为 cvui::imshow 只是显示当前图像的结果,所以为了实现 counter 的交互,即实现点击加号 value 递增,点击减号 value 递减,需要将语句写在循环中。

发布了73 篇原创文章 · 获赞 14 · 访问量 3万+

猜你喜欢

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