快速识别数字 - FastNumberOcrFromPtr
函数简介
快速识别图片中的数字,使用预定义的数字图片模板进行匹配识别。
接口名称
FastNumberOcrFromPtr
DLL调用
int32_t FastNumberOcrFromPtr(int64_t instance, int64_t source, const char* numbers, const char* colorJson, double matchVal)
参数定义:
instance
(长整型数): OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。source
(长整型数): 源图片对象的指针。numbers
(字符串): 0~9数字图片地址,多个数字用|分割,如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.pngcolorJson
(字符串): 颜色JSON配置,用于指定识别区域的颜色范围。格式为:[{"StartColor": "3278FA", "EndColor": "6496FF", "Type": 0}, {"StartColor": "3278FA", "EndColor": "6496FF", "Type": 1}]matchVal
(双精度浮点数): 识别率阈值,范围0.0-1.0。
示例:
// 快速识别数字示例
int64_t instance = CreateCOLAPlugInterFace();
int64_t source = CreateImage("screenshot.png");
// 设置数字图片路径
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";
// 设置颜色JSON配置
const char* colorJson = "[{\"StartColor\": \"3278FA\", \"EndColor\": \"6496FF\", \"Type\": 0}, {\"StartColor\": \"3278FA\", \"EndColor\": \"6496FF\", \"Type\": 1}]";
// 执行数字识别
double matchVal = 0.8;
int32_t result = FastNumberOcrFromPtr(instance, source, numbers, colorJson, matchVal);
if (result >= 0) {
printf("识别到的数字: %d\n", result);
} else {
printf("识别失败\n");
}
// 释放资源
DestroyCOLAPlugInterFace(instance);
返回值
整型数:
- 返回识别到的数字
- 如果识别失败返回-1
注意事项
- 需要预先准备0-9数字的二值化图片模板
- 数字图片路径用|符号分隔
- colorJson参数用于指定识别区域的颜色范围,提高识别准确性
- matchVal参数控制识别精度,值越高要求匹配度越精确
- 建议在识别前对图片进行预处理,提高识别成功率