预处理
改进来自低质量扫描和照片的输入。使用我们的预处理滤波器清理、拉直和增强困难图像,以获得最佳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 Image 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 OCR 识别图像的特定区域using 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刚刚发布