CoreOCROnnx.SDK
4.2.1
dotnet add package CoreOCROnnx.SDK --version 4.2.1
NuGet\Install-Package CoreOCROnnx.SDK -Version 4.2.1
<PackageReference Include="CoreOCROnnx.SDK" Version="4.2.1" />
<PackageVersion Include="CoreOCROnnx.SDK" Version="4.2.1" />
<PackageReference Include="CoreOCROnnx.SDK" />
paket add CoreOCROnnx.SDK --version 4.2.1
#r "nuget: CoreOCROnnx.SDK, 4.2.1"
#:package CoreOCROnnx.SDK@4.2.1
#addin nuget:?package=CoreOCROnnx.SDK&version=4.2.1
#tool nuget:?package=CoreOCROnnx.SDK&version=4.2.1
CoreOCROnnx.SDK
CoreOCROnnx.SDK 是 CoreOCROnnx 的 .NET 调用库,提供离线 PaddleOCR 文字识别和 YOLO 推理接口。SDK 只包含托管代码;实际推理还需要安装一个 CoreOCRRuntime.* 原生运行时包,并准备对应模型文件。
项目主页:PaddleOCRCore/CoreOCROnnx
支持范围
- .NET Standard 2.0
- .NET Framework 4.5、4.6.1、4.7、4.8
- .NET 6、7、8、9
- PaddleOCR PP-OCRv6、PP-OCRv5,并兼容 V4/V3 模型
- YOLO detect、pose、classification、seg、obb 和 Tensor 接口
- ONNX Runtime、OpenVINO、TensorRT 三类推理后端
当前 NuGet 运行时包按操作系统、架构和后端拆分。应用进程的平台必须与运行时包一致。
安装
先安装托管 SDK:
dotnet add package CoreOCROnnx.SDK
再根据部署环境选择且只选择一个运行时包,例如 Windows x64 CPU:
dotnet add package CoreOCRRuntime.Onnx.CPU.win-x64
可用运行时包包括:
| NuGet 包 | 平台 | 设备 |
|---|---|---|
CoreOCRRuntime.Onnx.CPU.win-x64 |
Windows x64 | CPU |
CoreOCRRuntime.Onnx.CPU.win-x86 |
Windows x86 | CPU |
CoreOCRRuntime.Onnx.CPU.linux-x64 |
Linux x64 | CPU |
CoreOCRRuntime.DirectML.win-x64 |
Windows x64 | DirectML GPU |
CoreOCRRuntime.DirectML.win-x86 |
Windows x86 | DirectML GPU |
CoreOCRRuntime.OpenVino.CPU.win-x64 |
Windows x64 | CPU |
CoreOCRRuntime.OpenVino.GPU.win-x64 |
Windows x64 | Intel GPU |
CoreOCRRuntime.TensorRT.GPU.win-x64 |
Windows x64 | NVIDIA GPU |
CoreOCRRuntime.TensorRT.GPU.linux-x64 |
Linux x64 | NVIDIA GPU |
不要在同一应用中同时安装多个后端运行时包,否则同名原生库可能产生冲突。TensorRT 运行时还要求兼容的 NVIDIA 驱动、CUDA 和 TensorRT 环境。
快速开始
准备检测、方向分类、文字识别模型和字典文件,然后初始化一次 OCRService:
using System;
using System.IO;
using CoreOCROnnx.SDK;
string modelDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "models");
var parameter = new InitParamater
{
det_infer = Path.Combine(modelDirectory, "PP-OCRv6_tiny_det.onnx"),
cls_infer = Path.Combine(modelDirectory, "ch_PP-LCNet_x0_25_textline_ori_cls_mobile.onnx"),
rec_infer = Path.Combine(modelDirectory, "PP-OCRv6_tiny_rec.onnx"),
keyFile = Path.Combine(modelDirectory, "ppocrv6tiny_dict.txt"),
paraType = EnumParaType.Class,
ocrpara = OCRParameter.CreateDefault()
};
var ocrService = new OCRService();
ocrService.Init(parameter);
OCRResult result = ocrService.Detect("test.jpg");
Console.WriteLine(result.StrRes);
Console.WriteLine(result.JsonText);
OCRService 也支持通过 byte[]、Base64 字符串和 OpenCV Mat 指针识别图片。
运行时与模型说明
- Windows NuGet 运行时通常位于输出目录的
runtimes/<rid>/native下,SDK 会自动查找并注册原生库目录。 - 发布应用时请检查原生运行时文件是否随发布结果一起输出,不要只复制
CoreOCROnnx.SDK.dll。 - ONNX Runtime 使用
.onnx模型。 - OpenVINO 支持
.onnx,也支持.xml与同名.bin组成的 IR 模型;初始化时应传具体.xml文件,不能传模型目录。 - TensorRT 支持
.onnx、.engine和.plan。首次从 ONNX 初始化可能生成与当前 GPU 和 TensorRT 环境绑定的 engine 缓存。 - TensorRT 后端始终使用 NVIDIA GPU,
use_gpu=false不会切换到 CPU。
如需调整运行时文件复制布局,可在应用项目中设置:
<PropertyGroup>
<CoreOCRRuntimeKeepNativeInRidFolder>true</CoreOCRRuntimeKeepNativeInRidFolder>
<CoreOCRRuntimeCopyNativeDllsToOutDir>true</CoreOCRRuntimeCopyNativeDllsToOutDir>
</PropertyGroup>
常见问题
无法加载 PaddleOCROnnx 或提示找不到指定模块
确认应用位数与运行时包一致,并检查 PaddleOCROnnx.dll 及该后端的依赖库都存在于发布输出中。Windows 下还可以使用 Dependencies 工具检查缺失 DLL。
OpenVINO 提示模型格式为空
请传入带扩展名的 .onnx 或 .xml 文件路径,不要传模型目录。使用 IR 模型时,确保 .xml 旁边存在同名 .bin。
TensorRT 初始化较慢
首次解析 ONNX 会构建 engine,耗时通常明显高于后续启动。确保模型目录可写,以便保存 engine 缓存。
更多资料
- 完整项目文档
- Release 与运行时下载
- 技术交流群:QQ群 475159576
本项目使用 Apache License 2.0 许可证。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 is compatible. net462 was computed. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- Newtonsoft.Json (>= 13.0.4)
-
.NETFramework 4.6.1
- Newtonsoft.Json (>= 13.0.4)
-
.NETFramework 4.7
- Newtonsoft.Json (>= 13.0.4)
-
.NETFramework 4.8
- Newtonsoft.Json (>= 13.0.4)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.4)
-
net10.0
- Newtonsoft.Json (>= 13.0.4)
-
net6.0
- Newtonsoft.Json (>= 13.0.4)
-
net7.0
- Newtonsoft.Json (>= 13.0.4)
-
net8.0
- Newtonsoft.Json (>= 13.0.4)
-
net9.0
- Newtonsoft.Json (>= 13.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.2.1 | 96 | 9/22/2026 |
| 4.1.0 | 145 | 7/15/2026 |
| 4.1.0-beta01 | 109 | 7/13/2026 |
See https://github.com/PaddleOCRCore/CoreOCROnnx/releases for release notes.