获取OCR配置 - GetOcrConfig
函数简介
获取OCR(光学字符识别)的配置参数。此函数可以读取PP-OCRv5模型的各种配置参数,包括GPU设置、检测参数、识别参数、分类参数等。适用于需要查看或验证当前OCR配置的场景。
接口名称
GetOcrConfig
DLL调用
long GetOcrConfig(long instance, string configKey)
参数说明
参数名 | 类型 | 说明 |
---|---|---|
instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
configKey | 字符串 | 配置键名称,支持所有OCR配置参数 |
示例
// 获取GPU相关配置
long gpuConfig = GetOcrConfig(ola, "OcrUseGpu");
if (gpuConfig != 0) {
char* gpuStr = (char*)gpuConfig;
printf("GPU使用状态: %s\n", gpuStr);
free(gpuStr);
}
// 获取检测模型路径
long detModelPath = GetOcrConfig(ola, "OcrDetModelDir");
if (detModelPath != 0) {
char* pathStr = (char*)detModelPath;
printf("检测模型路径: %s\n", pathStr);
free(pathStr);
}
// 获取识别模型路径
long recModelPath = GetOcrConfig(ola, "OcrRecModelDir");
if (recModelPath != 0) {
char* pathStr = (char*)recModelPath;
printf("识别模型路径: %s\n", pathStr);
free(pathStr);
}
// 获取CPU线程数配置
long cpuThreads = GetOcrConfig(ola, "OcrCpuThreads");
if (cpuThreads != 0) {
char* threadsStr = (char*)cpuThreads;
printf("CPU线程数: %s\n", threadsStr);
free(threadsStr);
}
// 获取检测阈值配置
long detThresh = GetOcrConfig(ola, "OcrDetDbThresh");
if (detThresh != 0) {
char* threshStr = (char*)detThresh;
printf("检测DB阈值: %s\n", threshStr);
free(threshStr);
}
// 获取识别批处理数量
long recBatchNum = GetOcrConfig(ola, "OcrRecBatchNum");
if (recBatchNum != 0) {
char* batchStr = (char*)recBatchNum;
printf("识别批处理数量: %s\n", batchStr);
free(batchStr);
}
// 获取推理精度配置
long precision = GetOcrConfig(ola, "OcrPrecision");
if (precision != 0) {
char* precisionStr = (char*)precision;
printf("推理精度: %s\n", precisionStr);
free(precisionStr);
}
// 获取GPU内存配置
long gpuMem = GetOcrConfig(ola, "OcrGpuMem");
if (gpuMem != 0) {
char* memStr = (char*)gpuMem;
printf("GPU内存大小: %s MB\n", memStr);
free(memStr);
}
// 获取分类阈值配置
long clsThresh = GetOcrConfig(ola, "OcrClsThresh");
if (clsThresh != 0) {
char* threshStr = (char*)clsThresh;
printf("分类阈值: %s\n", threshStr);
free(threshStr);
}
// 获取字符字典路径
long charDictPath = GetOcrConfig(ola, "OcrRecCharDictPath");
if (charDictPath != 0) {
char* dictStr = (char*)charDictPath;
printf("字符字典路径: %s\n", dictStr);
free(dictStr);
}
返回值
long: 返回配置值的字符串指针,需要手动释放内存
注意事项
- 返回的字符串需要手动释放内存
- 支持所有OCR配置参数,包括:
GPU相关参数
- OcrUseGpu (bool): 是否使用GPU推理,false使用CPU,true使用GPU,默认false
- OcrUseTensorrt (bool): 是否使用TensorRT加速,默认false
- OcrGpuId (int): GPU设备ID,0表示第一个GPU,默认0
- OcrGpuMem (int): GPU内存大小(MB),默认4000
CPU相关参数
- OcrCpuThreads (int): CPU线程数,默认8
- OcrEnableMkldnn (bool): 是否启用MKL-DNN加速,默认true
推理相关参数
- OcrPrecision (string): 推理精度,可选fp32/fp16/int8,默认"int8"
- OcrBenchmark (bool): 是否启用性能基准测试,默认false
- OcrOutput (string): 基准测试日志保存路径,默认"./output/"
- OcrImageDir (string): 输入图像目录,默认""
- OcrType (string): 执行类型,ocr或structure,默认"ocr"
检测相关参数
- OcrDetModelDir (string): 检测模型路径,默认"./OCRv5_model/PP-OCRv5_mobile_det_infer/"
- OcrLimitType (string): 输入图像限制类型,max或min,默认"max"
- OcrLimitSideLen (int): 输入图像限制边长,默认960
- OcrDetDbThresh (double): 检测DB阈值,范围0.0-1.0,默认0.3
- OcrDetDbBoxThresh (double): 检测DB框阈值,范围0.0-1.0,默认0.6
- OcrDetDbUnclipRatio (double): 检测DB未裁剪比例,默认1.5
- OcrUseDilation (bool): 是否对输出图使用膨胀操作,默认false
- OcrDetDbScoreMode (string): 检测DB评分模式,fast或slow,默认"slow"
- OcrVisualize (bool): 是否显示检测结果,默认true
识别相关参数
- OcrRecModelDir (string): 识别模型路径,默认"./OCRv5_model/PP-OCRv5_mobile_rec_infer/"
- OcrRecBatchNum (int): 识别批处理数量,默认6
- OcrRecCharDictPath (string): 识别字符字典路径,默认"./ppocr/utils/ppocr_keys_v1.txt"
- OcrRecImgH (int): 识别图像高度,默认48
- OcrRecImgW (int): 识别图像宽度,默认320
分类相关参数
- OcrUseAngleCls (bool): 是否使用角度分类,默认false
- OcrClsModelDir (string): 分类模型路径,默认""
- OcrClsThresh (double): 分类阈值,范围0.0-1.0,默认0.9
- OcrClsBatchNum (int): 分类批处理数量,默认1
布局相关参数
- OcrLayoutModelDir (string): 布局模型路径,默认""
- OcrLayoutDictPath (string): 布局字典路径,默认"./ppocr/utils/dict/layout_dict/layout_publaynet_dict.txt"
- OcrLayoutScoreThreshold (double): 布局评分阈值,范围0.0-1.0,默认0.5
- OcrLayoutNmsThreshold (double): 布局NMS阈值,范围0.0-1.0,默认0.5
表格相关参数
- OcrTableModelDir (string): 表格结构模型路径,默认""
- OcrTableMaxLen (int): 表格最大长度,默认488
- OcrTableBatchNum (int): 表格批处理数量,默认1
- OcrMergeNoSpanStructure (bool): 是否合并无跨度结构,默认true
- OcrTableCharDictPath (string): 表格字符字典路径,默认"./ppocr/utils/dict/table_structure_dict_ch.txt"
前向相关参数
- OcrDet (bool): 是否使用检测,默认true
- OcrRec (bool): 是否使用识别,默认true
- OcrCls (bool): 是否使用分类,默认false
- OcrTable (bool): 是否使用表格结构,默认false
- OcrLayout (bool): 是否使用布局分析,默认false
注意事项
- 配置值以JSON字符串形式返回,需要根据参数类型进行转换
- 与 SetOcrConfig 和 SetOcrConfigByKey 函数配合使用
- 适用于OCR配置管理和调试场景