主题
从字库中识别文字 - OcrFromDictDetails
函数简介
从字库中识别指定区域的文字并返回详细信息,需提前加载数据库。x1、y1、x2、y2 传 0, 0, 0, 0 为窗口整个客户区。支持多个字库同时识别,多个字库用 \| 分割,如 dict1\|dict2。
接口名称
OcrFromDictDetailsDLL调用
long OcrFromDictDetails(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 | 字符串 | 字库名称,为空时搜索所有字库;多个字库用 | 分割,如 dict1|dict2 |
| matchVal | 双精度浮点数 | 匹配值。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
auto result = ola.OcrFromDictDetails(0, 0, 0, 0, "value", "num", 0.9);
// result 含 Regions、Text 等字段,SDK 已解析为对象csharp
using OLAPlug;
var ola = new OLAPlugServer();
var result = ola.OcrFromDictDetails(0, 0, 0, 0, "value", "num", 0.9);
// result 含 Regions、Text 等字段,SDK 已解析为对象python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
result = ola.OcrFromDictDetails(0, 0, 0, 0, "value", "num", 0.9)
# result 含 Regions、Text 等字段,SDK 已解析为对象java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
var result = ola.OcrFromDictDetails(0, 0, 0, 0, "value", "num", 0.9);
// result 含 Regions、Text 等字段,SDK 已解析为对象cpp
var ola = com("OlaPlug.OlaSoft")
var result = ola.OcrFromDictDetails(0, 0, 0, 0, "value", "num", 0.9)
// result 含 Regions、Text 等字段,SDK 已解析为对象vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
result = ola.OcrFromDictDetails(0, 0, 0, 0, "value", "num", 0.9)
' result 含 Regions、Text 等字段,SDK 已解析为对象text
.局部变量 ola, OLAPlug
ola.创建 ()
result = ola.OcrFromDictDetails(0, 0, 0, 0, "value", "num", 0.9)
' result 含 Regions、Text 等字段,SDK 已解析为对象aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var result = ola.OcrFromDictDetails(0, 0, 0, 0, "value", "num", 0.9);
// result 含 Regions、Text 等字段,SDK 已解析为对象text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
自动 result = ola.OcrFromDictDetails(0, 0, 0, 0, "value", "num", 0.9)
// result 含 Regions、Text 等字段,SDK 已解析为对象cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
auto result = ola.OcrFromDictDetails(0, 0, 0, 0, "value", "num", 0.9);
// result 含 Regions、Text 等字段,SDK 已解析为对象原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long ptr = OcrFromDictDetails(instance, 0, 0, 0, 0, "value", "num", 0.9);
if (ptr != 0) {
char buffer[512] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long OcrFromDictDetails(long ola, int x1, int y1, int x2, int y2, string colorJson, string dict_name, int matchVal);
long instance = CreateCOLAPlugInterFace();
long ptr = OcrFromDictDetails(instance, 0, 0, 0, 0, "value", "num", 0.9);
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string result = sb.ToString();
}python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.OcrFromDictDetails(instance, 0, 0, 0, 0, "value", "num", 0.9)
if ptr:
buf = create_string_buffer(512)
ola.GetStringFromPtr(ptr, buf, 512)
ola.FreeStringPtr(ptr)
result = buf.value.decode("utf-8")返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 字符串指针地址,返回识别到的JSON字符串,如:。 |
json
{
"Regions": [
{
"Score": 0,
"Text": "bbbbbb",
"Center": { "x": 100, "y": 200 },
"Vertices": [
{ "x": 75, "y": 190 },
{ "x": 125, "y": 190 },
{ "x": 125, "y": 210 },
{ "x": 75, "y": 210 }
],
"Angle": 0
}
],
"Text": "bbbbbb"
}| 字段名 | 类型 | 说明 |
|---|---|---|
| Regions | 数组 | Regions 结果列表,详见下方字段说明。 |
| Text | 字符串 | 识别文本。 |
Regions 元素字段说明:
| 字段名 | 类型 | 说明 |
|---|---|---|
| Score | 整数 | 识别置信度分值。 |
| Text | 字符串 | 识别文本。 |
| Center | 对象 | 中心点坐标对象。 |
| Vertices | 数组 | 顶点坐标集合。 |
| Angle | 整数 | 角度值。 |
Regions[].Center 字段说明:
| 字段名 | 类型 | 说明 |
|---|---|---|
| x | 整数 | X 坐标。 |
| y | 整数 | Y 坐标。 |
Regions[].Vertices 元素字段说明:
| 字段名 | 类型 | 说明 |
|---|---|---|
| x | 整数 | X 坐标。 |
| y | 整数 | Y 坐标。 |
- Regions:所有识别到的数据集
- Score:识别评分,分值越高越准确
- Center:识别结果中心点
- Vertices:识别结果的4个顶点
- Angle:识别结果角度
返回的字符串指针需调用 FreeStringPtr 释放内存。
