預處理
改善低品質掃描和照片的輸入。使用我們的預處理濾鏡來清潔、拉直和增強困難的圖像,以達到最大的OCR精度。
輸入顏色校正濾鏡
1
二值化
在IronOCR中輕鬆二值化您的輸入,將圖像轉換為清晰的黑白版本。這個濾鏡有效地將文字從複雜的背景中隔離出來,降低噪聲,使文字提取更輕鬆、更可靠。
瞭解如何使用:修正.NET C#中的閱讀圖像顏色using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Apply binarize affect
imageInput.Binarize();
// Export the modified image
imageInput.SaveAsImages("binarize.jpg");Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("sample.jpg")
' Apply binarize affect
imageInput.Binarize()
' Export the modified image
imageInput.SaveAsImages("binarize.jpg")
End Using2
灰度
將彩色圖像轉換為灰度 - 是為更先進的預處理濾鏡準備圖像的重要步驟。
瞭解如何使用:修正.NET C#中的閱讀圖像顏色using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Apply grayscale affect
imageInput.ToGrayScale();
// Export the modified image
imageInput.SaveAsImages("grayscale.jpg");Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("sample.jpg")
' Apply grayscale affect
imageInput.ToGrayScale()
' Export the modified image
imageInput.SaveAsImages("grayscale.jpg")
End Using3
更改像素顏色
替換圖像中的特定顏色范圍,使您可以在OCR之前去除水印、彩色背景或其他分心元素。
瞭解如何使用:修正.NET C#中的閱讀圖像顏色using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("sample.jpg");
IronSoftware.Drawing.Color currentColor = new IronSoftware.Drawing.Color("#DB645C");
IronSoftware.Drawing.Color newColor = IronSoftware.Drawing.Color.DarkCyan;
// Replace color
imageInput.ReplaceColor(currentColor, newColor, 80);
// Export the modified image
imageInput.SaveAsImages("replaceColor");Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("sample.jpg")
Dim currentColor As New IronSoftware.Drawing.Color("#DB645C")
Dim newColor As IronSoftware.Drawing.Color = IronSoftware.Drawing.Color.DarkCyan
' Replace color
imageInput.ReplaceColor(currentColor, newColor, 80)
' Export the modified image
imageInput.SaveAsImages("replaceColor")
End Using
輸入形態操作
1
膨脹
加厚圖像中的字元,這有助於連接文字中的斷線,提高對淡或細字體的識別。
瞭解如何使用:使用濾鏡修正圖像以供閱讀using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Apply Dilate filter
imageInput.Dilate();
// Export filtered image
imageInput.SaveAsImages("dilate.jpg");Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("sample.jpg")
' Apply Dilate filter
imageInput.Dilate()
' Export filtered image
imageInput.SaveAsImages("dilate.jpg")
End Using2
侵蝕
削弱圖像中的字元,這對分隔接觸或混合的字元很有用。
瞭解如何使用:使用濾鏡修正圖像以供閱讀using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Apply Erode filter
imageInput.Erode();
// Export filtered image
imageInput.SaveAsImages("erode.jpg");Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("sample.jpg")
' Apply Erode filter
imageInput.Erode()
' Export filtered image
imageInput.SaveAsImages("erode.jpg")
End Using3
更改像素顏色
替換圖像中的特定顏色范圍,使您可以在OCR之前去除水印、彩色背景或其他分心元素。
瞭解如何使用:修正.NET C#中的閱讀圖像顏色using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("sample.jpg");
IronSoftware.Drawing.Color currentColor = new IronSoftware.Drawing.Color("#DB645C");
IronSoftware.Drawing.Color newColor = IronSoftware.Drawing.Color.DarkCyan;
// Replace color
imageInput.ReplaceColor(currentColor, newColor, 80);
// Export the modified image
imageInput.SaveAsImages("replaceColor");Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("sample.jpg")
Dim currentColor As New IronSoftware.Drawing.Color("#DB645C")
Dim newColor As IronSoftware.Drawing.Color = IronSoftware.Drawing.Color.DarkCyan
' Replace color
imageInput.ReplaceColor(currentColor, newColor, 80)
' Export the modified image
imageInput.SaveAsImages("replaceColor")
End Using
輸入方向操作
1
去傾斜
自動檢測和拉直傾斜或歪斜的圖像,極大地提高了對不完美掃描的OCR準確率。
瞭解如何使用:修正.NET C#中的閱讀圖像方向using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("paragraph_skewed.png");
// Apply Deskew filter
imageInput.Deskew();Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("paragraph_skewed.png")
' Apply Deskew filter
imageInput.Deskew()
End Using2
旋轉
以任何角度程式化旋轉圖像,以確保文字正確定向供OCR引擎使用。
瞭解如何使用:修正.NET C#中的閱讀圖像方向using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("paragraph_skewed.png");
// Rotate the image 180 degrees clockwise
imageInput.Rotate(180);
// Export the modified image
imageInput.SaveAsImages("rotate");Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput = New OcrImageInput("paragraph_skewed.png")
' Rotate the image 180 degrees clockwise
imageInput.Rotate(180)
' Export the modified image
imageInput.SaveAsImages("rotate")
End Using3
檢測方向
自動確定頁面方向(0、90、180、270度),這在OCR之前的方向矯正中很有用。即使文件是上下顛倒掃描的,也能保證高精度。
瞭解如何使用:檢測頁面旋轉using IronOcr;
using var input = new OcrInput();
// Load PDF document
input.LoadPdf("Clockwise90.pdf");
// Detect page rotation
var results = input.DetectPageOrientation();
// Ouput result
foreach(var result in results)
{
Console.WriteLine(result.PageNumber);
Console.WriteLine(result.HighConfidence);
Console.WriteLine(result.RotationAngle);
}Imports IronOcr
Dim Input As New OcrInput()
' Load PDF document
Input.LoadPdf("Clockwise90.pdf")
' Detect page rotation
Dim Results = Input.DetectPageOrientation()
' Output result
For Each Result In Results
Console.WriteLine(Result.PageNumber)
Console.WriteLine(Result.HighConfidence)
Console.WriteLine(Result.RotationAngle)
Next
輸入解析度控制
1
比例
將圖像重新設置為OCR的最佳解析度,顯著提高低解析度原始文件的準確性。
瞭解如何使用:修正.NET C#中的閱讀圖像方向using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("paragraph_skewed.png");
// Apply scale
imageInput.Scale(70);
// Export the modified image
imageInput.SaveAsImages("rotate");Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("paragraph_skewed.png")
' Apply scale
imageInput.Scale(70)
' Export the modified image
imageInput.SaveAsImages("rotate")
End Using2
DPI設置
手動設置低解析圖像或缺少元資料的掃描的每英寸點數(DPI)。提供DPI值可引導OCR引擎,顯著提高識別質量。
瞭解如何使用:C# Tesseract圖像DPIusing IronOcr;
using System;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
ocrInput.TargetDPI = 300;
ocrInput.LoadImage(@"images\image.png");
var ocrResult = ocrTesseract.Read(ocrInput);
Console.WriteLine(ocrResult.Text);Imports IronOcr
Imports System
Dim ocrTesseract = New IronTesseract()
Using ocrInput = New OcrInput()
ocrInput.TargetDPI = 300
ocrInput.LoadImage("images\image.png")
Dim ocrResult = ocrTesseract.Read(ocrInput)
Console.WriteLine(ocrResult.Text)
End Using3
增強解析度
通過算法有效提高低解析度圖像的清晰度和清晰度,以從模糊或像素化的輸入中恢復文字。
瞭解如何使用:使用濾鏡修正圖像以供閱讀using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Apply enhance resolution filter
imageInput.EnhanceResolution();
// Export filtered image
imageInput.SaveAsImages("sharpen.jpg");Imports IronOcr
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Add image
Using imageInput As New OcrImageInput("sample.jpg")
' Apply enhance resolution filter
imageInput.EnhanceResolution()
' Export filtered image
imageInput.SaveAsImages("sharpen.jpg")
End Using4
濾鏡嚮導
使用一個智能方法應用預處理濾鏡的精選鏈。 濾鏡向導會自動分析輸入圖像並應用最佳的更正序列以達到最佳的OCR結果。
瞭解如何使用:濾鏡嚮導using IronOcr;
var ocrTesseract = new IronTesseract();
// WIZARD - If you are unsure which filters to use,
// use the debug-wizard to test all combinations:
string codeToRun = OcrInputFilterWizard.Run(@"images\image.png", out double confidence, ocrTesseract);
Console.WriteLine($"Confidence: {confidence}");
Console.WriteLine(codeToRun);Imports IronOcr
Dim ocrTesseract = New IronTesseract()
' WIZARD - If you are unsure which filters to use,
' 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($"Confidence: {confidence}")
Console.WriteLine(codeToRun)5
OCR 圖像區域
通過僅針對包含文字的圖像的特定區域來節省處理時間。 只需定義一個矩形區域即可從表單、表格或雜亂背景中隔離並提取文字。
瞭解如何使用:在C#中指定圖像區域的Tesseract OCRusing IronOcr;
using IronSoftware.Drawing;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
var ContentArea = new Rectangle(x: 215, y: 1250, width: 1335, height: 280);
ocrInput.LoadImage("img/example.png", ContentArea);
var ocrResult = ocrTesseract.Read(ocrInput);
Console.WriteLine(ocrResult.Text);Imports IronOcr
Imports IronSoftware.Drawing
Dim ocrTesseract = New IronTesseract()
Using ocrInput = New OcrInput()
Dim ContentArea = New Rectangle(x:=215, y:=1250, width:=1335, height:=280)
ocrInput.LoadImage("img/example.png", ContentArea)
Dim ocrResult = ocrTesseract.Read(ocrInput)
Console.WriteLine(ocrResult.Text)
End Using準備開始了嗎?
Nuget Downloads 6,236,385|版本:2026.9剛剛發布