主题
指定bmp图片识字(自定义模型) - OcrFromBmpDataEx
函数简介
对 BMP 内存数据进行 OCR,使用指定 OCR 模型。
接口名称
OcrFromBmpDataExDLL 调用
long OcrFromBmpDataEx(long ola, long ptr, int size, long modelHandle);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。 |
| ptr | 长整数型 | BMP 图像数据指针。 |
| size | 整数型 | BMP 数据字节长度。 |
| modelHandle | 长整数型 | 模型句柄;内置 mobile 为 0,自定义包为 OcrLoadModel 返回值。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
long modelHandle = ola.OcrLoadModel("models/ocr.olam", "your_password", 0);
if (modelHandle == 0) {
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
string text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle);
// text 为识别到的文字csharp
using OLAPlug;
var ola = new OLAPlugServer();
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
long modelHandle = ola.OcrLoadModel("models/ocr.olam", "your_password", 0);
if (modelHandle == 0)
{
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
string text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle);
// text 为识别到的文字python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
# 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
modelHandle = ola.OcrLoadModel("models/ocr.olam", "your_password", 0)
if modelHandle == 0:
# 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
pass
# bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
bmpPtr = bmpData
bmpSize = 102400
text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle)
# text 为识别到的文字java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
long modelHandle = ola.OcrLoadModel("models/ocr.olam", "your_password", 0);
if (modelHandle == 0) {
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
String text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle);
// text 为识别到的文字go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
modelHandle := ola.OcrLoadModel("models/ocr.olam", "your_password", 0)
if modelHandle == 0 {
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
bmpPtr := bmpData
bmpSize := 102400
text := ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle)
// text 为识别到的文字rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
let modelHandle = ola.ocr_load_model("models/ocr.olam", "your_password", 0);
if modelHandle == 0 {
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
let bmpPtr = bmpData;
let bmpSize = 102400;
let text = ola.ocr_from_bmp_data_ex(bmpPtr, &bmpSize, modelHandle);
// text 为识别到的文字cpp
var ola = com("OlaPlug.OlaSoft")
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
var modelHandle = ola.OcrLoadModel("models/ocr.olam", "your_password", 0)
if (modelHandle == 0) {
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
var bmpPtr = bmpData
var bmpSize = 102400
var text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle)
// text 为识别到的文字vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
modelHandle = ola.OcrLoadModel("models/ocr.olam", "your_password", 0)
If modelHandle = 0 Then
' 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
End If
' bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
bmpPtr = bmpData
bmpSize = 102400
text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle)
' text 为识别到的文字text
.局部变量 ola, OLAPlug
ola.创建 ()
' 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
modelHandle = ola.OcrLoadModel(“models/ocr.olam“, “your_password“, 0)
.如果真 (modelHandle = 0)
' 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
.如果真结束
' bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
bmpPtr = bmpData
bmpSize = 102400
text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle)
' text 为识别到的文字aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
var modelHandle = ola.OcrLoadModel("models/ocr.olam", "your_password", 0);
if (modelHandle == 0) {
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
var bmpPtr = bmpData;
var bmpSize = 102400;
var text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle);
// text 为识别到的文字text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
长整数 modelHandle = ola.OcrLoadModel("models/ocr.olam", "your_password", 0)
if (modelHandle == 0) {
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
长整数 bmpPtr = bmpData
整数 bmpSize = 102400
文本型 text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle)
// text 为识别到的文字cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
long modelHandle = ola.OcrLoadModel("models/ocr.olam", "your_password", 0);
if (modelHandle == 0) {
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
string text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, modelHandle);
// text 为识别到的文字原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
long modelHandle = OcrLoadModel(instance, "models/ocr.olam", "your_password", 0);
if (modelHandle == 0) {
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
long textPtr = OcrFromBmpDataEx(instance, bmpPtr, bmpSize, modelHandle);
if (textPtr != 0) {
char text[512] = {0};
GetStringFromPtr(textPtr, text, sizeof(text));
FreeStringPtr(textPtr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[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 CreateCOLAPlugInterFace();
long instance = CreateCOLAPlugInterFace();
// 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
long modelHandle = OcrLoadModel(instance, "models/ocr.olam", "your_password", 0);
if (modelHandle == 0)
{
// 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
}
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
long textPtr = OcrFromBmpDataEx(instance, bmpPtr, bmpSize, modelHandle);
if (textPtr != 0) {
StringBuilder text = new StringBuilder(GetStringSize(textPtr) + 1);
GetStringFromPtr(textPtr, text, text.Capacity);
FreeStringPtr(textPtr);
string textStr = text.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()
# 加载 OCR 加密模型包;内置 mobile 模型可直接使用 modelHandle=0
modelHandle = OcrLoadModel(instance, "models/ocr.olam", "your_password", 0)
if modelHandle == 0:
# 加载失败请检查路径与密码,或改用内置模型 modelHandle=0
pass
# bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
bmpPtr = bmpData
bmpSize = 102400
textPtr = OcrFromBmpDataEx(instance, bmpPtr, bmpSize, modelHandle)
if textPtr:
buf = create_string_buffer(512)
ola.GetStringFromPtr(textPtr, buf, 512)
ola.FreeStringPtr(textPtr)
text = buf.value.decode("utf-8")返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 字符串指针,识别文本。须 FreeStringPtr 释放。 |
注意事项
| 项目 | 说明 |
|---|---|
| 格式 | ptr 须为完整 BMP 文件字节流(含文件头)。 |
