快速识别数字 - FastNumberOcr
函数简介
快速识别指定窗口区域内的数字,使用预定义的数字图片模板进行匹配识别。
接口名称
FastNumberOcr
DLL调用
int FastNumberOcr(long instance, int x1, int y1, int x2, int y2, string numbers, string colorJson, double matchVal);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| x1 | 整数型 | 区域左上角X坐标 |
| y1 | 整数型 | 区域左上角Y坐标 |
| x2 | 整数型 | 区域右下角X坐标 |
| y2 | 整数型 | 区域右下角Y坐标 |
| numbers | 字符串 | 0~9数字图片地址,多个数字用 ` |
| colorJson | 字符串 | 颜色模型配置字符串,用于限定图像匹配中的颜色范围,格式说明见 颜色模型说明 - ColorModel。JSON格式示例:[{"StartColor":"3278FA","EndColor":"6496FF","Type":0}];简化格式示例:`3278FA-000000 |
| matchVal | 双精度浮点数 | 识别率阈值,范围 0.0-1.0 |
示例
int64_t instance = CreateCOLAPlugInterFace();
BindWindow(instance, "记事本", "normal", "normal", "", 0);
const char* numbers = "img/0.png|img/1.png|img/2.png|img/3.png|img/4.png|img/5.png|img/6.png|img/7.png|img/8.png|img/9.png";
const char* colorJson = "[{\"StartColor\": \"3278FA\", \"EndColor\": \"6496FF\", \"Type\": 0}]";
int32_t result = FastNumberOcr(instance, 100, 100, 200, 150, numbers, colorJson, 0.8);
if (result >= 0) {
printf("识别到的数字: %d\n", result);
}
DestroyCOLAPlugInterFace(instance);
返回值
整数型,返回识别到的数字,识别失败返回 -1。
注意事项
- 需要预先准备0-9数字的二值化图片模板
- 数字图片路径用
|符号分隔 - matchVal 参数控制识别精度,值越高要求匹配度越精确
- 使用前需要先绑定窗口
- 坐标范围为窗口客户区坐标
