设置OCR配置 - SetOcrConfig
函数简介
通过JSON格式的配置字符串批量设置OCR(光学字符识别)的配置参数。
接口名称
SetOcrConfig
DLL调用
int SetOcrConfig(long instance, string configStr);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| configStr | 字符串 | JSON格式的配置字符串,包含多个OCR配置参数 |
示例
// 基本GPU配置
string gpuConfig = "{\"OcrUseGpu\":true,\"OcrGpuId\":0,\"OcrGpuMem\":4000}";
int result = SetOcrConfig(ola, gpuConfig);
// 检测模型配置
string detConfig = "{\"OcrDetModelDir\":\"./OCRv5_model/PP-OCRv5_mobile_det_infer/\",\"OcrDetDbThresh\":0.3,\"OcrDetDbBoxThresh\":0.6}";
result = SetOcrConfig(ola, detConfig);
// 完整配置示例
string fullConfig = "{\"OcrUseGpu\":false,\"OcrCpuThreads\":8,\"OcrDetModelDir\":\"./OCRv5_model/PP-OCRv5_mobile_det_infer/\",\"OcrRecModelDir\":\"./OCRv5_model/PP-OCRv5_mobile_rec_infer/\",\"OcrDetDbThresh\":0.3,\"OcrRecBatchNum\":6}";
result = SetOcrConfig(ola, fullConfig);
返回值
1 成功,0 失败。
注意事项
- 配置字符串必须为有效的JSON格式
- 与 GetOcrConfig 和 SetOcrConfigByKey 函数配合使用
- 支持的配置参数包括:
- GPU相关:OcrUseGpu、OcrUseTensorrt、OcrGpuId、OcrGpuMem
- CPU相关:OcrCpuThreads、OcrEnableMkldnn
- 推理相关:OcrPrecision、OcrBenchmark、OcrOutput、OcrImageDir、OcrType
- 检测相关:OcrDetModelDir、OcrLimitType、OcrLimitSideLen、OcrDetDbThresh、OcrDetDbBoxThresh、OcrDetDbUnclipRatio、OcrUseDilation、OcrDetDbScoreMode、OcrVisualize
- 识别相关:OcrRecModelDir、OcrRecBatchNum、OcrRecCharDictPath、OcrRecImgH、OcrRecImgW
- 分类相关:OcrUseAngleCls、OcrClsModelDir、OcrClsThresh、OcrClsBatchNum
- 布局相关:OcrLayoutModelDir、OcrLayoutDictPath、OcrLayoutScoreThreshold、OcrLayoutNmsThreshold
- 表格相关:OcrTableModelDir、OcrTableMaxLen、OcrTableBatchNum、OcrMergeNoSpanStructure、OcrTableCharDictPath
- 前向相关:OcrDet、OcrRec、OcrCls、OcrTable、OcrLayout
