Skip to content

快速识别数字 - FastNumberOcrFromPtr

函数简介

快速识别指定图片中的数字,使用预定义的数字图片模板进行匹配识别。

接口名称

FastNumberOcrFromPtr

DLL调用

int FastNumberOcrFromPtr(long instance, long source, string numbers, string colorJson, double matchVal);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
source长整数型源图片对象的指针。
numbers字符串0~9 数字图片路径,用 | 分隔。默认任一模板不存在或加载失败时识别失败(返回 -1);可通过 SetConfigByKey 设置 MultiTemplateAbortOnInvalidImage=false 跳过无效模板。
colorJson字符串颜色模型配置字符串,用于限定图像匹配中的颜色范围,格式说明见 颜色模型说明 - ColorModel。JSON格式示例:[{"StartColor":"3278FA","EndColor":"6496FF","Type":0}];简化格式示例:3278FA-000000|6496FF-2020203278FA~6496FFFF0000|00FF00
matchVal双精度浮点数识别率阈值,范围 0.0-1.0。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int ret = ola.FastNumberOcrFromPtr(imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
int ret = ola.FastNumberOcrFromPtr(imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ret = ola.FastNumberOcrFromPtr(imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
int ret = ola.FastNumberOcrFromPtr(imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9);
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ret := ola.FastNumberOcrFromPtr(imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9)
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let ret = ola.fast_number_ocr_from_ptr(img_ptr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9);
cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.FastNumberOcrFromPtr(imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.FastNumberOcrFromPtr(imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9)
text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.FastNumberOcrFromPtr(imgPtr, “img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp“, “000000”, 0.9)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.FastNumberOcrFromPtr(imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.FastNumberOcrFromPtr(imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int32_t ret = ola.FastNumberOcrFromPtr(imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
FastNumberOcrFromPtr(instance, imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9);
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 FastNumberOcrFromPtr(long ola, long source, string numbers, string colorJson, double matchVal);

long instance = CreateCOLAPlugInterFace();
FastNumberOcrFromPtr(instance, imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9);
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()
ola.FastNumberOcrFromPtr(instance, imgPtr, "img/0.bmp|img/1.bmp|img/2.bmp|img/3.bmp|img/4.bmp|img/5.bmp|img/6.bmp|img/7.bmp|img/8.bmp|img/9.bmp", "000000", 0.9)

返回值

返回值说明
(返回值)整数型,返回识别到的数字,识别失败返回 -1。

注意事项

项目说明
需要预先准备0-9数字的二值化图片模板需要预先准备0-9数字的二值化图片模板。
路径数字图片路径用 | 分隔。默认任一模板不存在则识别失败(返回 -1)。
matchVal 参数控制识别精度matchVal 参数控制识别精度,值越高要求匹配度越精确。

相关配置

配置项类型默认说明
MultiTemplateAbortOnInvalidImagebooltrue多模板路径 | 分隔时,某一图不存在或加载失败:true默认)整次返回空;false 跳过无效模板继续匹配(全局配置,见 SetConfigByKey)。