OCR 圖像優化濾鏡
OcrInput 類別為 C# 和 .NET 開發者提供了細緻的控制,以便在處理圖像輸入之前提高速度和準確性。
這否定了使用Photoshop批處理腳本或ImageMagick來準備OCR圖片的常見做法。
如何在 Tesseract 中使用 OCR 篩選器替代方案
- 安裝 OCR 程式庫以使用 OCR 篩選器
- 使用圖像路徑創建一個
OcrInput對象 - (可選)使用濾鏡方法處理影像。
- 使用
Read方法。 - 使用
OcrResult's的 Text 屬性顯示結果。
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
OcrInput 類別為 C# 和 .NET 開發者提供了細緻的控制,以便在處理圖像輸入之前提高速度和準確性。
這否定了使用Photoshop批處理腳本或ImageMagick來準備OCR圖片的常見做法。
OcrInput對象Read方法。OcrResult's 的 Text 屬性顯示結果。