Skip to content

指定bmp图片详细信息(自定义模型) - OcrFromBmpDataDetailsEx

函数简介

对 BMP 内存数据 OCR 并返回 JSON 详情,使用指定模型。

接口名称

OcrFromBmpDataDetailsEx

DLL 调用

long OcrFromBmpDataDetailsEx(long ola, long ptr, int size, long modelHandle);

参数说明

参数名类型说明
ola长整数型OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。
ptr长整数型BMP 图像数据指针。
size整数型BMP 数据字节长度。
modelHandle长整数型模型句柄;内置 mobile 为 0

示例

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;
auto detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle);
// detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
// 各字段说明见 OcrDetails 返回值文档
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;
var detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle);
// detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
// 各字段说明见 OcrDetails 返回值文档
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
detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle)
# detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
# 各字段说明见 OcrDetails 返回值文档
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;
var detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle);
// detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
// 各字段说明见 OcrDetails 返回值文档
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
auto detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle)
// detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
// 各字段说明见 OcrDetails 返回值文档
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;
auto detail = ola.ocr_from_bmp_data_details_ex(bmpPtr, &bmpSize, modelHandle)
// detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
// 各字段说明见 OcrDetails 返回值文档
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 detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle)
// detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
// 各字段说明见 OcrDetails 返回值文档
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
detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle)
' detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
' 各字段说明见 OcrDetails 返回值文档
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
detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle)
' detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
' 各字段说明见 OcrDetails 返回值文档
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 detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle);
// detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
// 各字段说明见 OcrDetails 返回值文档
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
自动 detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle)
// detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
// 各字段说明见 OcrDetails 返回值文档
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;
auto detail = ola.OcrFromBmpDataDetailsEx(bmpPtr, bmpSize, modelHandle);
// detail.Regions 为识别框列表,detail.Text 为合并后的识别文本
// 各字段说明见 OcrDetails 返回值文档

原生 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 detailJsonPtr = OcrFromBmpDataDetailsEx(instance, bmpPtr, bmpSize, modelHandle);
if (detailJsonPtr != 0) {
    char detailJson[512] = {0};
    GetStringFromPtr(detailJsonPtr, detailJson, sizeof(detailJson));
    FreeStringPtr(detailJsonPtr);
}
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 detailJsonPtr = OcrFromBmpDataDetailsEx(instance, bmpPtr, bmpSize, modelHandle);
if (detailJsonPtr != 0) {
    StringBuilder detailJson = new StringBuilder(GetStringSize(detailJsonPtr) + 1);
    GetStringFromPtr(detailJsonPtr, detailJson, detailJson.Capacity);
    FreeStringPtr(detailJsonPtr);
    string detailJsonStr = detailJson.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
detailJsonPtr = OcrFromBmpDataDetailsEx(instance, bmpPtr, bmpSize, modelHandle)
if detailJsonPtr:
    buf = create_string_buffer(512)
    ola.GetStringFromPtr(detailJsonPtr, buf, 512)
    ola.FreeStringPtr(detailJsonPtr)
    detailJson = buf.value.decode("utf-8")

返回值

返回值说明
(返回值)字符串指针,JSON 字段说明与 OcrFromBmpDataDetails 相同。 须 FreeStringPtr 释放。