CVUI 之 计数器
cvui::counter()
为一个整型或者double值渲染一个计数器,可以点击向上或向下增加或减少值。
Python
import numpy as np
import cv2
import cvui
def counter_test():
WINDOW_NAME = 'Counter-Test'
# 创建画布
frame = np.zeros((400, 600, 3), np.uint8)
# 读取图像
cvui.init(WINDOW_NAME)
#
cntvalue = [1.0]
while True:
# 画布填色
frame[:] = (100, 128, 128)
'''
> theWhere: 画布
> theX: 绘制的 X
> theY: 绘制的 Y
> theValue: 值
> theStep: 间隔
> theFormat: 格式化的值或数字。例如,% d或 % .2f。
> theFontScale: 字体大小
> theInsideColor: 颜色
'''
cvui.counter(frame, 10, 10, cntvalue, 2, "%d")
# 显示
cvui.imshow(WINDOW_NAME, frame)
# ESC 退出
if cv2.waitKey(20) == 27:
break
if __name__ == '__main__':
counter_test()
CPP
原型
int counter(cv::Mat& theWhere, int theX, int theY, int *theValue, int theStep = 1, const char *theFormat = "%d", double theFontScale = DEFAULT_FONT_SCALE, unsigned int theInsideColor = DEFAULT_BUTTON_COLOR);
double counter(cv::Mat& theWhere, int theX, int theY, double *theValue, double theStep = 0.5, const char *theFormat = "%.2f", double theFontScale = DEFAULT_FONT_SCALE, unsigned int = DEFAULT_BUTTON_COLOR);
参数
theWhere: 画布
theX: 绘制的 X
theY: 绘制的 Y
theValue: 值
theStep: 间隔
theFormat: 格式化的值或数字。例如,%d或%.2f。
theFontScale: 字体大小
theInsideColor: 颜色
实例
int count = 2;
cvui::counter(frame, 90, 50, &count);