LocalAI.Ocr
0.6.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package LocalAI.Ocr --version 0.6.0
NuGet\Install-Package LocalAI.Ocr -Version 0.6.0
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="LocalAI.Ocr" Version="0.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LocalAI.Ocr" Version="0.6.0" />
<PackageReference Include="LocalAI.Ocr" />
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 LocalAI.Ocr --version 0.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LocalAI.Ocr, 0.6.0"
#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 LocalAI.Ocr@0.6.0
#: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=LocalAI.Ocr&version=0.6.0
#tool nuget:?package=LocalAI.Ocr&version=0.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LocalAI.Ocr
A simple .NET library for local OCR (Optical Character Recognition) with automatic model downloading from HuggingFace. Features a 2-stage detection + recognition pipeline using PaddleOCR ONNX models.
Features
- 2-Stage Pipeline: Text detection (DBNet) followed by text recognition (CRNN with CTC decoding)
- Multi-language Support: 40+ languages including English, Korean, Chinese, Japanese, Arabic, and more
- Automatic Model Download: Models are downloaded on-demand from HuggingFace (~10MB default)
- GPU Acceleration: Supports CUDA, DirectML, and CoreML
- Pure C# Implementation: No Python dependencies or external processes
- Polygon Support: Precise text region boundaries for rotated or curved text
Quick Start
using LocalAI.Ocr;
// Load default OCR pipeline (English)
await using var ocr = await LocalOcr.LoadAsync();
// Recognize text in an image
var result = await ocr.RecognizeAsync("document.png");
// Get all text
Console.WriteLine(result.FullText);
// Access individual text regions
foreach (var region in result.Regions)
{
Console.WriteLine($"[{region.Confidence:P0}] {region.Text}");
Console.WriteLine($" Location: {region.BoundingBox}");
}
Language-Specific OCR
// Load OCR for Korean text
await using var ocr = await LocalOcr.LoadForLanguageAsync("ko");
// Or specify the recognition model explicitly
await using var ocr = await LocalOcr.LoadAsync(
detectionModel: "default",
recognitionModel: "crnn-korean-v3");
Supported Languages
| Model | Languages |
|---|---|
crnn-en-v3 |
English |
crnn-korean-v3 |
Korean |
crnn-chinese-v3 |
Chinese (Simplified/Traditional) |
crnn-japan-v3 |
Japanese |
crnn-latin-v3 |
Spanish, French, German, Italian, Portuguese, etc. |
crnn-arabic-v3 |
Arabic |
crnn-cyrillic-v3 |
Russian, Ukrainian, Bulgarian, etc. |
crnn-devanagari-v3 |
Hindi, Marathi, Nepali, Sanskrit |
Configuration Options
var options = new OcrOptions
{
LanguageHint = "en", // Language hint for auto model selection
DetectionThreshold = 0.5f, // Minimum detection confidence
RecognitionThreshold = 0.5f, // Minimum recognition confidence
BinarizationThreshold = 0.3f, // DBNet binarization threshold
UnclipRatio = 1.5f, // Polygon expansion ratio
UsePolygon = true, // Use polygon coordinates
Provider = ExecutionProvider.Auto, // GPU acceleration
CacheDirectory = null // Custom cache directory
};
await using var ocr = await LocalOcr.LoadAsync(options: options);
Detection Only
// Get text regions without recognition
var regions = await ocr.DetectAsync("document.png");
foreach (var region in regions)
{
Console.WriteLine($"Found text at: {region.BoundingBox}");
}
Layout-Aware Text Extraction
var result = await ocr.RecognizeAsync("document.png");
// Get text with layout preserved (same-line regions joined with spaces)
var layoutText = result.GetTextWithLayout(lineTolerancePixels: 10);
Model Information
The library uses PaddleOCR ONNX models from HuggingFace:
- Repository:
monkt/paddleocr-onnx - Detection model: DBNet (~2.3MB)
- Recognition models: CRNN (~7-13MB depending on language)
Models are cached locally after first download.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.
-
net10.0
- LocalAI.Vision.Core (>= 0.6.0)
- System.Numerics.Tensors (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.