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 递减,需要将语句写在循环中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值