[OpenCV-Python] cvui counter

Counter of CVUI

cvui::counter()Renders a counter for an integer or double value, which can be clicked up or down to increase or decrease the value.

insert image description here

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

prototype

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

Parameters
theWhere: the canvas
theX: the drawn X
theY: the drawn Y
theValue: the value
theStep: the interval
theFormat: the formatted value or number. For example, %d or %.2f.
theFontScale: font size
theInsideColor: color

example

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

【reference】

cvui counter

Guess you like

Origin blog.csdn.net/zhoujinwang/article/details/130007961