SeasonOCR for EasyOCR Models is a .NET OCR library for ONNX models converted from the EasyOCR Python project.
If you prefer to build the ONNX models yourself, clone the repository and run the workflow logic locally.
1using System.Text;
2using Microsoft.ML.OnnxRuntime;
3using SeasonOCR;
4using StbImageSharp;
5
6SeasonOcr.EnableDebugOutput = true;
7
8var detectorBytes = File.ReadAllBytes(@"craft_mlt_25k.onnx");
9using var detectorSession = new InferenceSession(detectorBytes);
10
11var recognizerBytes = File.ReadAllBytes(@"recognizer_ch_sim.onnx");
12using var recognizerSession = new InferenceSession(recognizerBytes);
13
14using var stream = File.OpenRead(@"chinese.jpg");
15var image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlue);
16
17var result = SeasonOcr.Detect(
18 detectorSession,
19 recognizerSession,
20 image,
21 createAnnotatedImage: true);
22
23Console.WriteLine(result.Summary);
24
25foreach (var paragraph in result.Paragraphs)
26{
27 Console.WriteLine($"{paragraph.Confidence:P0}: {paragraph.Text}");
28}
29
30if (result.AnnotatedImage.Length > 0)
31 File.WriteAllBytes(@"output.jpg", result.AnnotatedImage);
32
33if (!string.IsNullOrWhiteSpace(result.DebugReport))
34 File.WriteAllText(@"output.debug.txt", result.DebugReport, Encoding.UTF8);
For the first release, the recommended runtime target is CPU execution.
1public static SeasonOcrResult Detect(
2 InferenceSession detectorSession,
3 InferenceSession recognizerSession,
4 ImageResult imageResult,
5 bool enableWordBeamSearch = false,
6 bool allowRotatedRecognition = false,
7 bool createAnnotatedImage = false,
8 int beamWidth = 5,
9 string? dictionary = null)