This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2227|Reply: 1

[Source] .NET/C# uses FastDeploy to deploy OCR models to recognize text

[Copy link]
Posted on 2024-12-31 13:23:43 | | | |
Requirements: I have used PaddleOCR to recognize the text on the image before, but python has opened an http interface to call the interface through C# to obtain the result. How do I use C# for direct OCR text recognition? This article will use .NET 8 to call the PaddleOCR model to recognize graphics and text.

FastDeploy is an all-scenario, flexible, and extremely efficient AI inference deployment tool that supports cloud-edge deployment. Address:The hyperlink login is visible.

Review:

.NET Core calls Baidu PaddleOCR to recognize images and texts
https://www.itsvse.com/thread-9590-1-1.html


Download and install the FastDeploy library

First, download and install the FastDeploy library, the official provides some compiled ones, not provided, you need to compile it yourself, the compilation tutorial is as follows:

Download the FastDeploy source code compilation for Windows
https://www.itsvse.com/thread-10892-1-1.html


Taking Windows CPU deployment as an example, download address:The hyperlink login is visible.

Extract the package to the D:\temp folder and run the following command:




Compile the FastDeployCsharpSdk class library

Create a new .NET 8 library named FastDeployCsharpSdkThe hyperlink login is visible.Copy the source code to the bottom of this library and modify a few places:

int64_t -> Int64
Otherwise, an error is reported: Parameter 1: Unable to convert from "nint" to "string"
new Mat(result_ptr); -> Mat.FromNativePointer(result_ptr);
"fastdeploy.dll" -> "fastdeploy"


Meanwhile, the .csproj project references the following:



Successfully compile the library!

Download the PaddleOCR model

Download the ch_PP-OCRv3 model at:The hyperlink login is visible.Text box detection, direction classification model, text recognition, and dictionary files must be downloaded. thereintoThe encoding format of ppocr_keys_v1.txt has been modified from UTF-8 to ANSI formatYes, otherwise the recognition result will be garbled.

OCR recognition test

Create a new console project, reference the FastDeployCsharpSdk library, and test the code as follows:



After running, it will crash and you need to modify the FastDeployCsharpSdk class library\vision\ocr\model.csThe Predict method in the file will comment the following code:


Regarding calling Visualize.VisOcr exception exit, just don't use it, you already have a result set, you can implement it yourself, refer to the following:

.NET/C# uses OpenCvSharp4, SixLabors.ImageSharp to frame the image
https://www.itsvse.com/thread-10888-1-1.html


Original:



The effect after recognition (due toOpenCvSharp4 adds Chinese garbled characters, everyone understands the meaning):



FastDeployCsharpSdk source code and finished product download:

Tourists, if you want to see the hidden content of this post, pleaseReply


Reference:

The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.




Previous:Angular Removal Zone.js Explore new Zoneless solutions
Next:【zip】. NET/C# uses built-in System.IO.Compression to compress and decompress
Posted on 2025-6-2 00:44:34 |
Prompt:Authors are banned or removed content is automatically blocked
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com