Skip to content

打包NCNN模型为OCR加密包 - OcrEncryptModel

函数简介

将 PP-OCR NCNN 四文件(det/rec 的 .param / .bin)及可选识别字典打成欧拉 OCR 加密包并写入磁盘。

接口名称

OcrEncryptModel

DLL 调用

int OcrEncryptModel(long ola, string detParamPath, string detBinPath, string recParamPath, string recBinPath, string dictPath, string password, string savePath);

参数说明

参数名类型说明
ola长整数型OLAPlug 对象指针。
detParamPath字符串检测模型 .param,如 PP_OCRv6_tiny_det.ncnn.param
detBinPath字符串检测模型 .bin
recParamPath字符串识别模型 .param
recBinPath字符串识别模型 .bin
dictPath字符串识别字典 UTF-8 文本(一行一字); 则不写入包内字典。
password字符串加密密码(UTF-8,不可为空)。
savePath字符串输出加密包路径。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");
csharp
using OLAPlug;

var ola = new OLAPlugServer();
int ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
int ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ret := ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let ret = ola.ocr_encrypt_model("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");
cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")
text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.OcrEncryptModel(“C:\\test.txt”, “C:\\test.txt”, “C:\\test.txt”, “C:\\test.txt”, “C:\\test.txt”, “value”, “C:\\test.txt”)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int32_t ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
OcrEncryptModel(instance, "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");
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 OcrEncryptModel(long ola, string detParamPath, string detBinPath, string recParamPath, string recBinPath, string dictPath, string password, string savePath);

long instance = CreateCOLAPlugInterFace();
OcrEncryptModel(instance, "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");
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.OcrEncryptModel(instance, "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")

返回值

返回值说明
(返回值)整数型:1 成功,0 失败。

注意事项

项目说明
包类型产出为 OCR 专用欧拉加密包,与 YOLO 加密包格式不同。
dictPath 为空为 v1 包(四段模型dictPath 为空为 v1 包(四段模型);非空为 v2 包(四段模型 + 字典)。
character_dict自定义 rec 须与训练时 character_dict / keys 一致;未打包字典时加载后使用内置 ppocrv6_keys
Paddle 导出常见字典ppocr_keys_v1.txtdict.txtkey_list.txt(每行一字,index 0 为 CTC blank)。