RapidOCRSharpOnnx 1.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package RapidOCRSharpOnnx --version 1.3.1
                    
NuGet\Install-Package RapidOCRSharpOnnx -Version 1.3.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RapidOCRSharpOnnx" Version="1.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RapidOCRSharpOnnx" Version="1.3.1" />
                    
Directory.Packages.props
<PackageReference Include="RapidOCRSharpOnnx" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RapidOCRSharpOnnx --version 1.3.1
                    
#r "nuget: RapidOCRSharpOnnx, 1.3.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RapidOCRSharpOnnx@1.3.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RapidOCRSharpOnnx&version=1.3.1
                    
Install as a Cake Addin
#tool nuget:?package=RapidOCRSharpOnnx&version=1.3.1
                    
Install as a Cake Tool

RapidOCRSharpOnnx

RapidOCRSharpOnnx

PP-OCRv4 PP-OCRv5 PP-OCRv6 C# .NET Version ONNX Runtime OpenCV GitHub license Release NuGet NuGet Downloads GitHub last commit GitHub commit activity

🚀a high performance, cross-platform PaddleOCR C# inference library base on OpenCV and ONNX Runtime. Referring to the RapidOCR project, it is a python version of the C# implementation with a redesigned and optimized architecture.

Features

  • Supported Languages PP-OCRv6 built on the newly designed PPLCNetV4 unified backbone, a single model supports 50 languages including Chinese, English, Japanese, and 46 Latin-script languages., please refer to the documentation: PP-OCRv6 Introduction.
  • Execution Provider CPU, CUDA / TensorRT, OpenVINO, CoreML, DirectML
  • Batch processing images Preprocess and Inference are executed asynchronously with Producer/Consumer pattern
  • High Performance Inference Memory reuse, GPU Inference with I/O Binding
  • Image Processing OpenCvSharp4
  • Draw Result Image SkiaSharp
  • Inference Engine ONNX Runtime is a cross-platform inference and training machine-learning accelerator.
  • PP-OCR Versions Includes support for: PP-OCRv6, PP-OCRv5, PP-OCRv4

Example Images:

<div align="center">

OCR Demo
<img src="https://github.com/meloht/RapidOCRSharpOnnx/blob/master/ExampleImages/res_book.png?raw=true" height="411" >
<img src="https://github.com/meloht/RapidOCRSharpOnnx/blob/master/ExampleImages/res_csharp.png?raw=true" height="750">
<img src="https://github.com/meloht/RapidOCRSharpOnnx/blob/master/ExampleImages/res_yongledadian.png?raw=true" height="787">

</div>

Usage

1. Export model to ONNX format:

For convert the pre-trained PP-OCR model to ONNX format, please refer to the the documentation: Obtaining ONNX Models, or download from rapid-ocr Model List.

Official download of PP-OCRv6 onnx format

huggingface download

modelscope download

2. Load the ONNX model with C#:

Install Nuget packages RapidOCRSharpOnnx, OnnxRuntime, OpenCvSharp4.runtime

CPU Inference
dotnet add package RapidOCRSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Microsoft.ML.OnnxRuntime
using RapidOCRSharp ocr = new RapidOCRSharp(new ExecutionProviderCPU(new OcrConfig(detectPath, recPath, LangRec.CH, OCRVersion.PPOCRV5, clsMobilePath)));
CoreML Inference
dotnet add package RapidOCRSharpOnnx
dotnet add package OpenCvSharp4.runtime.osx.10.15-x64
dotnet add package Microsoft.ML.OnnxRuntime
using RapidOCRSharp ocr = new RapidOCRSharp(new ExecutionProviderCoreML(new OcrConfig(detectPath, recPath, LangRec.CH, OCRVersion.PPOCRV5, clsMobilePath)));
CUDA/TensorRT Inference
dotnet add package RapidOCRSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Microsoft.ML.OnnxRuntime.Gpu.Windows
using RapidOCRSharp ocr = new RapidOCRSharp(new ExecutionProviderCUDA(new OcrConfig(detectPath, recogPath, LangRec.CH, OCRVersion.PPOCRV5, clsPath), deviceId));
using RapidOCRSharp ocr = new RapidOCRSharp(new ExecutionProviderTensorRT(new OcrConfig(detectPath, recogPath, LangRec.CH, OCRVersion.PPOCRV5, clsPath), deviceId));
DirectML Inference
dotnet add package RapidOCRSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Microsoft.ML.OnnxRuntime.DirectML
using RapidOCRSharp ocr = new RapidOCRSharp(new ExecutionProviderDirectML(new OcrConfig(detectPath, recogPath, LangRec.EN, OCRVersion.PPOCRV5, clsPath), deviceId));
OpenVINO Inference
dotnet add package RapidOCRSharpOnnx
dotnet add package OpenCvSharp4.runtime.win
dotnet add package Intel.ML.OnnxRuntime.OpenVino
using RapidOCRSharp ocr = new RapidOCRSharp(new ExecutionProviderOpenVINO(new OcrConfig(detectPath, recogPath, LangRec.EN, OCRVersion.PPOCRV5, clsPath), IntelDeviceType.NPU));
Use the following C# code to load the model and run basic prediction
using RapidOCRSharp ocr = new RapidOCRSharp(new ExecutionProviderDirectML(new OcrConfig(detectPath, recogPath, LangRec.EN, OCRVersion.PPOCRV5, clsPath), _deviceId));
string savePath = $"res_{Path.GetFileName(imgPath)}";
var result = ocr.RecognizeText(imgPath, savePath);
Console.WriteLine($"result: {result.ToString()}");

Batch processing images

 using RapidOCRSharp ocr = new RapidOCRSharp(new ExecutionProviderDirectML(new OcrConfig(detectPath, recogPath, LangRec.CH, OCRVersion.PPOCRV5, clsPath), _deviceId));
 var list = Directory.GetFiles(@"C:\code\model\OCRTestImages");
 Stopwatch sw = new Stopwatch();
 sw.Start();
 var resPath = ocr.BatchParallelAsync(list.ToList(), saveDir, receiveAction: ReceiveResult);
 sw.Stop();
 Console.WriteLine($"BatchAsync Time: {sw.ElapsedMilliseconds} ms");

private static void ReceiveResult(OcrBatchResult batchResult)
{
    Console.WriteLine(batchResult.ToString());
    Console.WriteLine("------------------------------------------------------------");
}
Batch processing images foreach api
using RapidOCRSharp ocr = new RapidOCRSharp(new ExecutionProviderDirectML(new OcrConfig(detectPath, recogPath, LangRec.CH, OCRVersion.PPOCRV5, clsPath), _deviceId));
var list = Directory.GetFiles(@"D:\code\model\OCRTestImages");
var resPaths = ocr.BatchForeachAsync(list.ToList(), @"D:\code\model\OCRTestImagesResults");

await foreach (var item in resPaths)
{
    Console.WriteLine(item.TextBlocks);
}

Custom font to draw result image
private static void TestImage()
{
     string imgPath = @"E:\Hp\ai-image\ADFtools\headerText.png";
     string detectPath = @"D:\code\RapidOCRSharpOnnx\RapidOCRSharpOnnx.TestCommon\Models\ch_PP-OCRv5_det_mobile.onnx";
     string recogPath = @"D:\code\RapidOCRSharpOnnx\RapidOCRSharpOnnx.TestCommon\Models\ch_PP-OCRv5_rec_mobile.onnx";
     string clsPath = @"D:\code\RapidOCRSharpOnnx\RapidOCRSharpOnnx.TestCommon\Models\ch_PP-LCNet_x0_25_textline_ori_cls_mobile.onnx";

     string font = @"C:\Windows\Fonts\msyh.ttc";
     using RapidOCRSharp ocr = new RapidOCRSharp(new ExecutionProviderDirectML(new OcrConfig(detectPath, recogPath, font, OCRVersion.PPOCRV5, clsPath), _deviceId));

     string savePath = $"res_{Path.GetFileName(imgPath)}";
     var result = ocr.RecognizeText(imgPath, savePath);
     Console.WriteLine($"result: {result.ToString()}");
}

Performance Test

OCR library Version language Inference Engine
PaddleSharp 3.0.1 Paddle Inference C API .NET binding Sdcb.PaddleInference
PaddleOCR 3.5.0 python paddlepaddle
RapidOCR 3.8.1 python openvino
RapidOCRSharpOnnx 1.0.0 C# Intel.ML.OnnxRuntime.OpenVino
RapidOcrNet 3.0.0 C# Intel.ML.OnnxRuntime.OpenVino
PaddleOcrNet 1.0.0 C# Microsoft.ML.OnnxRuntime

Performance Test PC

Hardware Summary
Windows Windows 11 Pro OS Version 25H2
CPU Intel Core Ultra 9 285k 3.7GHz
RAM DDR5 128GB speed 4400MT/s
Storage SSD 2TB

Performance Test Data

Images: 60 images (image size: 1180x92)

PP-OCR Model: ch_PP-OCRv5_det_mobile, ch_PP-OCRv5_rec_mobile, ch_PP-LCNet_x0_25_textline_ori_cls_mobile

PaddleSharp test result

CPU inference time: 48.1769278s

<img width="1331" height="847" alt="image" src="https://github.com/user-attachments/assets/87515077-e9c2-48b2-9e43-6b145e1c7a7a" />

RapidOCRSharpOnnx test result

CPU inference time: 9.2447871s

<img width="1477" height="874" alt="image" src="https://github.com/user-attachments/assets/eee41ffe-f0a7-48af-b934-74e290ee6196" />

PaddleOCR test result

CPU inference time: 62.668516899924725s

<img width="1009" height="911" alt="image" src="https://github.com/user-attachments/assets/b367749f-3c37-4326-bb30-ea4fcb52315d" />

RapidOCR test result

CPU inference time: 17.963430000003427 s

<img width="997" height="1093" alt="image" src="https://github.com/user-attachments/assets/79ab7dd5-0311-42ea-aa03-ed5695ff5fae" />

RapidOcrNet test result

CPU inference time: 78.2841902 s

<img width="1011" height="669" alt="image" src="https://github.com/user-attachments/assets/dd982a69-ea18-4b14-8002-44b1d5bbdaa6" />

PaddleOcrNet test result

CPU inference time: 55.2006584 s

<img width="1190" height="594" alt="image" src="https://github.com/user-attachments/assets/70178779-27ff-4cc5-8a20-e8d72c8ce49d" />

Performance Test Result

OCR library Version language Inference Engine Elapsed Time
PaddleSharp 3.0.1 Paddle Inference C API .NET binding Sdcb.PaddleInference.runtime.win64.mkl version 3.1.0.54 CPU 48.1769s
PaddleOCR 3.5.0 python paddlepaddle version 3.2.0 CPU 62.6685s
RapidOCR 3.8.1 python openvino version 2026.1.0 21367 CPU 17.9634s
RapidOCRSharpOnnx 1.0.0 C# Intel.ML.OnnxRuntime.OpenVino CPU version 1.24.1 9.2447s
RapidOcrNet 3.0.0 C# Intel.ML.OnnxRuntime.OpenVino CPU version 1.24.1 78.2841s
PaddleOcrNet 1.0.0 C# Microsoft.ML.OnnxRuntime CPU version 1.27.0 55.2006s
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on RapidOCRSharpOnnx:

Repository Stars
TrustNTE/TrustNTE
TrustNTE让异环解放双手!异环自动化后台静默运行工具 | NTE辅助脚本。支持粉爪大劫案、自动钓鱼、自动战斗、自动打副本、异环刷材料(自动锄地)。基于YOLO AI视觉,全分辨率适配,开源免费的解放双手工具。
Version Downloads Last Updated
1.4.0 297 11/9/2026
1.3.1 2,557 9/7/2026
1.3.0 723 8/21/2026
1.2.5 208 8/11/2026
1.2.4 437 7/17/2026
1.2.3 178 7/8/2026
1.2.2 259 6/17/2026
1.2.1 163 6/17/2026
1.2.0 186 6/16/2026
1.1.1 199 5/29/2026
1.0.9 146 5/13/2026
1.0.8 146 5/13/2026
1.0.7 180 5/10/2026
1.0.6 147 5/9/2026
1.0.5 160 5/9/2026
1.0.4 145 5/7/2026
1.0.3 147 5/7/2026
1.0.2 139 5/6/2026
Loading failed

RapidOCRSharpOnnx 1.3.1 onnxruntime 1.29.0