Skip to content

模型预热 - OcrWarmupModel

函数简介

对指定 OCR 模型做热身推理。创建欧拉对象 不会 自动预热,也不会阻塞 CreateCOLAPlugInterFace。需要时请在创建之后自行调用本接口。

YoloWarmup 同类:加载/创建走主流程,预热由调用方决定同步还是异步。

接口名称

OcrWarmupModel

DLL 调用

int OcrWarmupModel(long ola, long modelHandle, int iterations, int async);

参数说明

参数名类型说明
ola长整数型OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。
modelHandle长整数型模型句柄;内置 mobile 为 0,自定义包为 OcrLoadModel 返回值。
iterations整数型热身次数;<=0 时按 1 次处理。
async整数型0=同步,等到预热结束;非 0=立即返回,后台预热。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 创建对象立刻返回,不加载 OCR
ola.OcrWarmupModel(0, 1, 1); // 异步预热内置模型,不挡主流程
// 需要等就绪时再调一次同步预热:ola.OcrWarmupModel(0, 1, 0);
string text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, 0);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
ola.OcrWarmupModel(0, 1, 1); // 异步预热
string text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, 0);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ola.OcrWarmupModel(0, 1, 1)  # 异步预热
text = ola.OcrFromBmpDataEx(bmpPtr, bmpSize, 0)
text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.OcrWarmupModel (0, 1, 1)  ' 异步预热,创建对象不会卡住

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
OcrWarmupModel(instance, 0, 1, 1); // async=1,立即返回
// 主流程继续;识别前若预热未完成,识别会等到模型就绪
csharp
long instance = CreateCOLAPlugInterFace();
OcrWarmupModel(instance, 0, 1, 1);

返回值

返回值说明
1成功。异步表示已启动或已在预热。
0失败。可用 OLAGetLastError 查看原因。

注意事项

项目说明
不阻塞创建CreateCOLAPlugInterFace 不加载、不预热 OCR。YOLO-only 场景不受 OCR 初始化影响。
异步后再同步async=1 之后再调 async=0,会等待那次后台预热结束。
未预热直接识别第一次识别会懒加载并等待就绪,首帧仍可能较慢。
热身统计完成后可通过 OcrGetModelInfoWarmup 字段查看。
批量多模型见 OcrWarmupModels,JSON 可设 "Async":true
全局自动预热OcrLoadModel 成功后仍受 OcrAutoWarmup 控制;与本接口独立。