using IronOcr;
using System;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
// First load all image(s)
ocrInput.LoadImage(@"images\image.png");
// Note: You don't need all of them; most users only need Deskew() and occasionally DeNoise()
ocrInput.WithTitle("My Document");
ocrInput.Binarize();
ocrInput.Contrast();
ocrInput.Deskew();
ocrInput.DeNoise();
ocrInput.Despeckle();
ocrInput.Dilate();
ocrInput.EnhanceResolution(300);
ocrInput.Invert();
ocrInput.Rotate(90);
ocrInput.Scale(150);
ocrInput.Sharpen();
ocrInput.ToGrayScale();
ocrInput.Erode();
// WIZARD - If you are unsure use the debug-wizard to test all combinations:
string codeToRun = OcrInputFilterWizard.Run(@"images\image.png", out double confidence, ocrTesseract);
Console.WriteLine(codeToRun);
// Optional: Export modified images so you can view them.
foreach (var page in ocrInput.GetPages())
{
page.SaveAsImage($"filtered_{page.Index}.bmp");
}
var ocrResult = ocrTesseract.Read(ocrInput);
Console.WriteLine(ocrResult.Text);
Imports IronOcr
Imports System
Private ocrTesseract = New IronTesseract()
Private ocrInput = New OcrInput()
' First load all image(s)
ocrInput.LoadImage("images\image.png")
' Note: You don't need all of them; most users only need Deskew() and occasionally DeNoise()
ocrInput.WithTitle("My Document")
ocrInput.Binarize()
ocrInput.Contrast()
ocrInput.Deskew()
ocrInput.DeNoise()
ocrInput.Despeckle()
ocrInput.Dilate()
ocrInput.EnhanceResolution(300)
ocrInput.Invert()
ocrInput.Rotate(90)
ocrInput.Scale(150)
ocrInput.Sharpen()
ocrInput.ToGrayScale()
ocrInput.Erode()
' WIZARD - If you are unsure use the debug-wizard to test all combinations:
Dim confidence As Double
Dim codeToRun As String = OcrInputFilterWizard.Run("images\image.png", confidence, ocrTesseract)
Console.WriteLine(codeToRun)
' Optional: Export modified images so you can view them.
For Each page In ocrInput.GetPages()
page.SaveAsImage($"filtered_{page.Index}.bmp")
Next page
Dim ocrResult = ocrTesseract.Read(ocrInput)
Console.WriteLine(ocrResult.Text)
Install-Package IronOcr
Filtros de optimización de imágenes OCR
La clase OcrInput proporciona un control granular a los desarrolladores de C# y .NET para preprocesar antes la entrada de imágenes para mayor velocidad y precisión.
Esto anula la práctica habitual de utilizar secuencias de comandos por lotes de Photoshop o ImageMagick para preparar las imágenes para el OCR.
Cómo utilizar alternativamente el filtro OCR en Tesseract