C#和.NET的中文OCR
本文档的其他版本:
IronOCR是C#软件组件,允许.NET编码人员以126种语言(包括简体和繁体中文)从图像和PDF文档中读取文本。语言包有简体和繁体中文字符。
它是Tesseract的高级分支,专门为.NET开发人员构建,在速度和准确性方面均经常优于其他Tesseract引擎。
IronOcr语言中文的内容
该软件包包含352种.NET的OCR语言:
- 简体中文
- 简体中文最佳
- 简体中文快速
- 中文简体垂直
- 简体中文垂直最佳
- 简体中文垂直快速
- 中国传统的
- 中国传统最佳
- 中国传统快
- 中文繁体垂直
- 中国传统垂直最佳
- 中文繁体垂直快速
下载
中文语言包[中文(Zhōngwén)]
* Download as 压缩
* Install with as https://www.nuget.org/packages/IronOcr.Languages.Chinese/'> NuGet
安装
我们要做的第一件事是将我们的中文OCR软件包安装到您的.NET项目中。
PM> Install-Package IronOCR.Languages.Chinese
代码示例
此C#代码示例从Image或PDF文档中读取简体中文文本。
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Use an OcrInput to load the image
using (var Input = new OcrInput(@"images\Chinese.png"))
{
// Perform OCR on the input image
var Result = Ocr.Read(Input);
// Retrieve the recognized text
var AllText = Result.Text;
// Output the recognized text to the console
Console.WriteLine(AllText);
}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Use an OcrInput to load the image
using (var Input = new OcrInput(@"images\Chinese.png"))
{
// Perform OCR on the input image
var Result = Ocr.Read(Input);
// Retrieve the recognized text
var AllText = Result.Text;
// Output the recognized text to the console
Console.WriteLine(AllText);
}
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Use an OcrInput to load the image
Using Input = New OcrInput("images\Chinese.png")
' Perform OCR on the input image
Dim Result = Ocr.Read(Input)
' Retrieve the recognized text
Dim AllText = Result.Text
' Output the recognized text to the console
Console.WriteLine(AllText)
End Using
为什么选择IronOCR?
IronOCR是易于安装,完整且文档证明的.NET软件库。
选择IronOCR可获得99.8%+的OCR准确性,而无需使用任何外部Web服务,持续的费用或通过Internet发送机密文档。
为什么C#开发人员选择IronOCR而不是Vanilla Tesseract:
- 作为单个DLL或Nuget安装
- 包括开箱即用的Tesseract 5、4和3发动机。
- 准确率 99.8% 明显优于常规Tesseract。
- 燃烧速度和多线程
- 兼容MVC,WebApp,桌面,控制台和服务器应用程序
- 没有可以使用的Exes或C ++代码
- 完整的PDF OCR支持
- 对几乎所有图像文件或PDF执行OCR
- 全面的.NET Core,Standard和FrameWork支持
- 在Windows,Mac,Linux,Azure,Docker,Lambda,AWS上部署
- 读取条形码和QR码
- 将OCR导出为XHTML
- 将OCR导出到可搜索的PDF文档
- 多线程支持
- 通过Nuget或OcrData文件管理的126种国际语言
- 提取图像,坐标,统计信息和字体。 不只是文字。
- 可用于在商业和专有应用程序中重新分发Tesseract OCR。
当处理真实世界的图像和不完善的文档(例如照片)或具有数字噪点或不完美的低分辨率扫描时,IronOCR会发光。
.NET平台的其他免费OCR库(例如其他.net tesseract API和Web服务)在这些实际使用案例中的性能不佳。
带Tesseract 5的OCR-在C#中开始编码
下面的代码示例显示了使用C#或VB .NET从图像读取文本是多么容易。
OneLiner: 最简单的一行代码
// Quick one-liner to read text from image
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
// Quick one-liner to read text from image
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
' Quick one-liner to read text from image
Dim Text As String = (New IronTesseract()).Read("img\Screenshot.png").Text
可配置的Hello World
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Create and configure OcrInput
using (var Input = new OcrInput())
{
Input.AddImage("images/sample.jpeg");
// You can add multiple images
// Perform OCR on the input
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Create and configure OcrInput
using (var Input = new OcrInput())
{
Input.AddImage("images/sample.jpeg");
// You can add multiple images
// Perform OCR on the input
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Create and configure OcrInput
Using Input = New OcrInput()
Input.AddImage("images/sample.jpeg")
' You can add multiple images
' Perform OCR on the input
Dim Result = Ocr.Read(Input)
' Output the recognized text to the console
Console.WriteLine(Result.Text)
End Using
C#PDF OCR
可以类似地使用相同的方法从任何PDF文档中提取文本。
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from PDF
using (var input = new OcrInput())
{
input.AddPdf("example.pdf", "password");
// Optionally select specific PDF pages for OCR
var Result = Ocr.Read(input);
// Display the recognized text and page count
Console.WriteLine(Result.Text);
Console.WriteLine($"{Result.Pages.Count()} Pages");
// 1 page per PDF page
}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from PDF
using (var input = new OcrInput())
{
input.AddPdf("example.pdf", "password");
// Optionally select specific PDF pages for OCR
var Result = Ocr.Read(input);
// Display the recognized text and page count
Console.WriteLine(Result.Text);
Console.WriteLine($"{Result.Pages.Count()} Pages");
// 1 page per PDF page
}
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' OCR from PDF
Using input = New OcrInput()
input.AddPdf("example.pdf", "password")
' Optionally select specific PDF pages for OCR
Dim Result = Ocr.Read(input)
' Display the recognized text and page count
Console.WriteLine(Result.Text)
Console.WriteLine($"{Result.Pages.Count()} Pages")
' 1 page per PDF page
End Using
多页TIFF的OCR
OCR读取TIFF文件格式,包括多个页面文档。 TIFF也可以直接转换为带有可搜索文本的PDF文件。
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from multi-frame TIFF
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("multi-frame.tiff");
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from multi-frame TIFF
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("multi-frame.tiff");
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' OCR from multi-frame TIFF
Using Input = New OcrInput()
Input.AddMultiFrameTiff("multi-frame.tiff")
Dim Result = Ocr.Read(Input)
' Output the recognized text to the console
Console.WriteLine(Result.Text)
End Using
条码和QR
IronOCR的独特功能是在扫描文本时可以读取文档中的条形码和QR码。 OcrResult.OcrBarcode
类的实例为开发人员提供了有关每个扫描条形码的详细信息。
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing with barcode reading enabled
var Ocr = new IronTesseract();
Ocr.Configuration.ReadBarCodes = true;
// OCR with barcode scanning
using (var input = new OcrInput())
{
input.AddImage("img/Barcode.png");
var Result = Ocr.Read(input);
// Output recognized barcodes
foreach (var Barcode in Result.Barcodes)
{
Console.WriteLine(Barcode.Value);
// Type and location properties are also exposed
}
}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing with barcode reading enabled
var Ocr = new IronTesseract();
Ocr.Configuration.ReadBarCodes = true;
// OCR with barcode scanning
using (var input = new OcrInput())
{
input.AddImage("img/Barcode.png");
var Result = Ocr.Read(input);
// Output recognized barcodes
foreach (var Barcode in Result.Barcodes)
{
Console.WriteLine(Barcode.Value);
// Type and location properties are also exposed
}
}
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing with barcode reading enabled
Private Ocr = New IronTesseract()
Ocr.Configuration.ReadBarCodes = True
' OCR with barcode scanning
Using input = New OcrInput()
input.AddImage("img/Barcode.png")
Dim Result = Ocr.Read(input)
' Output recognized barcodes
For Each Barcode In Result.Barcodes
Console.WriteLine(Barcode.Value)
' Type and location properties are also exposed
Next Barcode
End Using
图像特定区域的OCR
IronOCR的所有扫描和读取方法均提供了准确指定要从中读取文本的页面的哪一部分的功能。 当我们查看标准化表格时,这非常有用,可以节省大量时间并提高效率。
要使用裁剪区域,我们将需要添加对System.Drawing
的系统引用,以便可以使用System.Drawing.Rectangle
对象。
// Import the IronOcr library
using IronOcr;
using System.Drawing; // Ensure this assembly reference is added
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from a specific area of an image
using (var Input = new OcrInput())
{
var ContentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
// Dimensions are in pixels
Input.Add("document.png", ContentArea);
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text); // Output the recognized text
}
// Import the IronOcr library
using IronOcr;
using System.Drawing; // Ensure this assembly reference is added
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from a specific area of an image
using (var Input = new OcrInput())
{
var ContentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
// Dimensions are in pixels
Input.Add("document.png", ContentArea);
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text); // Output the recognized text
}
' Import the IronOcr library
Imports IronOcr
Imports System.Drawing ' Ensure this assembly reference is added
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' OCR from a specific area of an image
Using Input = New OcrInput()
Dim ContentArea = New System.Drawing.Rectangle() With {
.X = 215,
.Y = 1250,
.Height = 280,
.Width = 1335
}
' Dimensions are in pixels
Input.Add("document.png", ContentArea)
Dim Result = Ocr.Read(Input)
Console.WriteLine(Result.Text) ' Output the recognized text
End Using
OCR用于低质量扫描
IronOCR OcrInput
类可以修复普通Tesseract无法读取的扫描。
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from low quality scan
using (var Input = new OcrInput(@"img\Potter.LowQuality.tiff"))
{
Input.DeNoise(); // Fix digital noise and bad scan quality
Input.Deskew(); // Correct the rotation and perspective
var Result = Ocr.Read(Input); // Perform the OCR
Console.WriteLine(Result.Text); // Output the recognized text
}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from low quality scan
using (var Input = new OcrInput(@"img\Potter.LowQuality.tiff"))
{
Input.DeNoise(); // Fix digital noise and bad scan quality
Input.Deskew(); // Correct the rotation and perspective
var Result = Ocr.Read(Input); // Perform the OCR
Console.WriteLine(Result.Text); // Output the recognized text
}
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' OCR from low quality scan
Using Input = New OcrInput("img\Potter.LowQuality.tiff")
Input.DeNoise() ' Fix digital noise and bad scan quality
Input.Deskew() ' Correct the rotation and perspective
Dim Result = Ocr.Read(Input) ' Perform the OCR
Console.WriteLine(Result.Text) ' Output the recognized text
End Using
将OCR结果导出为可搜索的PDF
带有可复制文本字符串的图像到PDF。 可以由搜索引擎和数据库建立索引。
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert OCR results to a searchable PDF
using (var Input = new OcrInput())
{
Input.Title = "Quarterly Report";
Input.AddImage("image1.jpeg");
Input.AddImage("image2.png");
Input.AddImage("image3.gif");
var Result = Ocr.Read(Input);
Result.SaveAsSearchablePdf("searchable.pdf"); // Save results as searchable PDF
}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert OCR results to a searchable PDF
using (var Input = new OcrInput())
{
Input.Title = "Quarterly Report";
Input.AddImage("image1.jpeg");
Input.AddImage("image2.png");
Input.AddImage("image3.gif");
var Result = Ocr.Read(Input);
Result.SaveAsSearchablePdf("searchable.pdf"); // Save results as searchable PDF
}
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Convert OCR results to a searchable PDF
Using Input = New OcrInput()
Input.Title = "Quarterly Report"
Input.AddImage("image1.jpeg")
Input.AddImage("image2.png")
Input.AddImage("image3.gif")
Dim Result = Ocr.Read(Input)
Result.SaveAsSearchablePdf("searchable.pdf") ' Save results as searchable PDF
End Using
TIFF到可搜索的PDF转换
将TIFF文档(或任何图像文件组)直接转换为可搜索的PDF,可通过Intranet,网站和google搜索引擎对其进行索引。
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert TIFF to searchable PDF
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("example.tiff");
Ocr.Read(Input).SaveAsSearchablePdf("searchable.pdf");
}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert TIFF to searchable PDF
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("example.tiff");
Ocr.Read(Input).SaveAsSearchablePdf("searchable.pdf");
}
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Convert TIFF to searchable PDF
Using Input = New OcrInput()
Input.AddMultiFrameTiff("example.tiff")
Ocr.Read(Input).SaveAsSearchablePdf("searchable.pdf")
End Using
将OCR结果导出为HTML
OCR图像到XHTML的转换。
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert OCR results to HTML format
using (var Input = new OcrInput())
{
Input.Title = "Html Title";
Input.AddImage("image1.jpeg");
var Result = Ocr.Read(Input);
Result.SaveAsHocrFile("results.html"); // Save results as HTML
}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert OCR results to HTML format
using (var Input = new OcrInput())
{
Input.Title = "Html Title";
Input.AddImage("image1.jpeg");
var Result = Ocr.Read(Input);
Result.SaveAsHocrFile("results.html"); // Save results as HTML
}
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Convert OCR results to HTML format
Using Input = New OcrInput()
Input.Title = "Html Title"
Input.AddImage("image1.jpeg")
Dim Result = Ocr.Read(Input)
Result.SaveAsHocrFile("results.html") ' Save results as HTML
End Using
OCR图像增强滤镜
IronOCR为OcrInput
对象提供了独特的过滤器,以提高OCR性能。
图像增强代码示例
使OCR输入图像质量更高,以产生更好,更快的OCR结果。
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Enhance low quality image for OCR
using (var Input = new OcrInput(@"LowQuality.jpeg"))
{
Input.DeNoise(); // Fix digital noise
Input.Deskew(); // Correct rotation and perspective
var Result = Ocr.Read(Input); // Perform the OCR
Console.WriteLine(Result.Text); // Output the recognized text
}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Enhance low quality image for OCR
using (var Input = new OcrInput(@"LowQuality.jpeg"))
{
Input.DeNoise(); // Fix digital noise
Input.Deskew(); // Correct rotation and perspective
var Result = Ocr.Read(Input); // Perform the OCR
Console.WriteLine(Result.Text); // Output the recognized text
}
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Enhance low quality image for OCR
Using Input = New OcrInput("LowQuality.jpeg")
Input.DeNoise() ' Fix digital noise
Input.Deskew() ' Correct rotation and perspective
Dim Result = Ocr.Read(Input) ' Perform the OCR
Console.WriteLine(Result.Text) ' Output the recognized text
End Using
OCR图像过滤器列表
IronOCR内置的用于增强OCR性能的输入滤波器包括:
Rotate -顺时针旋转图像数度。 对于逆时针,请使用负数。
Binarize -此图像过滤器将每个像素变为黑色或白色,而没有中间地线。可能会改善文本与背景对比度非常低的OCR性能。
ToGrayScale -此图像过滤器将每个像素变成灰度阴影。 不太可能提高OCR精度,但可能会提高速度
Contrast -自动增加对比度。 在低对比度扫描中,此过滤器通常可以提高OCR速度和准确性。
DeNoise -消除数字噪声。 该滤波器仅应在预期有噪声的地方使用。
Invert -反转每种颜色。 例如,白色变成黑色:黑色变成白色。
Dilate -高级形态。 膨胀将像素添加到图像中对象的边界。侵蚀对面
Erode -高级形态。 侵蚀去除了对象边界上的像素
Deskew -旋转图像,使其朝上且正交。 这对于OCR非常有用,因为Tesseract对倾斜扫描的公差可以低至5度。
DeepCleanBackgroundNoise-消除大量背景噪音。 仅在已知极端文档背景噪音的情况下使用此过滤器,因为此过滤器还会冒降低干净文档的OCR准确性的风险,并且CPU成本很高。
EnhanceResolution增强低质量图像的分辨率。 由于OcrInput.MinimumDPI和OcrInput.TargetDPI将自动捕获并解析低分辨率输入,因此通常不需要此过滤器。
CleanBackgroundNoise 这种设置有些耗时。 但是,它允许该库自动清除数字图像中的数字噪音,纸屑和其他瑕疵,否则将使其无法被其他OCR库读取。
EnhanceContrast 是一种设置,可使IronOCR自动增加文本与图像背景的对比度,从而提高OCR的准确性,并通常提高OCR的性能和速度。
EnhanceResolution 是一项设置,它将自动检测低分辨率图像(低于275dpi),并自动放大图像,然后对所有文本进行锐化处理,以便可以由OCR库完美读取。 尽管此操作本身很耗时,但通常会减少对图像进行OCR操作的总时间。
语言 IronOCR支持22种国际语言包,并且语言设置可用于选择一种或多种要用于OCR操作的多种语言。
策略 铁OCR支持两种策略。 我们可以选择对文档进行快速而不太准确的扫描,或者使用高级策略,该策略使用一些人工智能模型通过查看句子中单词彼此之间的统计关系来自动提高OCR文本的准确性。
ColorSpace是一种设置,通过该设置,我们可以选择灰度或彩色OCR。 通常,灰度是最佳选择。但是,有时当某些文本或背景的色相相似但颜色差异很大时,全色颜色空间会提供更好的效果。
DetectWhiteTextOnDarkBackgrounds 通常,所有OCR库都希望在白色背景上看到黑色文本。 此设置使IronOCR可以自动检测底片或带有白色文本的暗页并进行读取。
InputImageType 通过此设置,开发人员可以指导OCR库是查看完整文档还是片段(如屏幕截图)。
RotateAndStraighten 是一种高级设置,它使IronOCR具有读取不仅旋转而且还包含透视图的文档的独特功能,例如文本文档的照片。
ReadBarcodes 是一项有用的功能,它允许IronOCR在读取文本的同时自动读取页面上的条形码和QR码,而不会增加大量额外的时间负担。
颜色深度 此设置确定OCR库将使用每个像素多少位来确定颜色的深度。较高的色深可能会提高OCR质量,但也会增加OCR操作完成所需的时间。
126语言包
IronOCR通过以DLL形式分发的语言包支持126种国际语言,这些语言包可以从本网站下载,也可以从NuGet软件包管理器下载。
语言包括德语,法语,英语,中文,日语等。 存在用于护照MRZ,MICR支票,财务数据,车牌等的专业语言包。 您还可以使用任何tesseract“ .traineddata”文件-包括您自己创建的文件。
语言范例
使用其他OCR语言。
```csharp // Import the IronOcr library // Ensure the Arabic language package is installed via NuGet using IronOcr; // Create an instance of IronTesseract for OCR processing var Ocr = new IronTesseract(); Ocr.Language = OcrLanguage.Arabic; // Set language to Arabic // OCR using Arabic language using (var input = new OcrInput()) { input.AddImage("img/arabic.gif"); // Add image filters as needed // This can improve OCR accuracy even with lower quality inputs var Result = Ocr.Read(input); // Saving Arabic text to file, console may not display correctly Result.SaveAsTextFile("arabic.txt"); } ```多语言示例
也可以同时使用多种语言进行OCR。 这确实可以帮助获取Unicode文档中的英语元数据和URL。
```csharp // Import the IronOcr library // Ensure the Chinese Simplified and other required languages are installed via NuGet using IronOcr; // Create an instance of IronTesseract for OCR processing var Ocr = new IronTesseract(); Ocr.Language = OcrLanguage.ChineseSimplified; Ocr.AddSecondaryLanguage(OcrLanguage.Chinese); // You can add multiple secondary languages // OCR multi-language document using (var input = new OcrInput()) { input.Add("multi-language.pdf"); var Result = Ocr.Read(input); Result.SaveAsTextFile("results.txt"); // Save results } ```详细的OCR结果对象
IronOCR为每个OCR操作返回一个OCR结果对象。 通常,开发人员仅使用此对象的text属性来从图像中扫描文本。 但是,OCR结果DOM比这要先进得多。
```csharp // Import the IronOcr library using IronOcr; using System.Drawing; // Ensure assembly reference is added // Create an instance of IronTesseract for OCR processing var Ocr = new IronTesseract(); Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm; // Use both Tesseract and LSTM Ocr.Configuration.ReadBarCodes = true; // Enable barcode reading // OCR processing using (var Input = new OcrInput(@"images\sample.tiff")) { OcrResult Result = Ocr.Read(Input); var Pages = Result.Pages; var Words = Pages[0].Words; var Barcodes = Result.Barcodes; // Explore detailed API options here: // - Pages, Blocks, Paragraphs, Lines, Words, Characters // - Image Export, Font Coordinates, Statistics } ```性能
IronOCR开箱即用,无需性能调整或大量修改输入图像。
速度飞快:IronOcr.2020 +的速度提高了10倍,并且比以前的版本减少了250%以上的错误。
学到更多
要了解有关C#,VB,F#或任何其他.NET语言中OCR的更多信息,请阅读我们的社区教程,其中提供了有关如何使用Iron OCR的真实示例,并可能显示出如何从中获得最大收益的细微差别。 这个图书馆。
还提供了.NET开发人员的完整对象参考。