从字库中识别文字 - OcrFromDict
函数简介
从字库中识别指定区域的文字,需提前加载数据库。x1、y1、x2、y2 传 0, 0, 0, 0 为窗口整个客户区。支持多个字库同时识别,多个字库用 | 分割,如 dict1|dict2。
接口名称
OcrFromDict
DLL调用
long OcrFromDict(long instance, int x1, int y1, int x2, int y2, string colorJson, string dict_name, double matchVal);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| x1 | 整数型 | 左上角x坐标 |
| y1 | 整数型 | 左上角y坐标 |
| x2 | 整数型 | 右下角x坐标 |
| y2 | 整数型 | 右下角y坐标 |
| colorJson | 字符串 | 颜色模型配置字符串,用于限定图像匹配中的颜色范围,格式说明见 颜色模型说明 - ColorModel。JSON格式示例:[{"StartColor":"3278FA","EndColor":"6496FF","Type":0}];简化格式示例:`3278FA-000000 |
| dict_name | 字符串 | 字库名称,为空时搜索所有字库,也可以传入字库文件如 dict.txt |
| matchVal | 双精度浮点数 | 匹配值 |
示例
C++
long instance = CreateCOLAPlugInterFace();
BindWindow(instance, hwnd, 0, 0, 0);
// 从字库"mydict"中识别窗口全区域文字
long resultPtr = OcrFromDict(instance, 0, 0, 0, 0, "FFFFFF-101010", "mydict", 0.85);
char* text = GetStringFromPtr(instance, resultPtr);
FreeStringPtr(instance, resultPtr);
Python
# 待补充
返回值
字符串指针地址,返回识别到的文字。返回的字符串指针需调用 FreeStringPtr 释放内存。
