在 C# 和 VB.NET 中开始使用 OCR
IronOCR 是一个 C# 软件库,允许 .NET 平台软件开发人员从图像和 PDF 文档中识别和读取文本。 这是一个纯粹的 .NET OCR 库,使用了目前已知的最先进的 Tesseract 引擎。
安装
使用 NuGet 包管理器进行安装
在 Visual Studio 中或通过 NuGet 包管理器在命令行中安装 IronOCR。 在 Visual Studio 中,用以下命令导航到控制台:
- 工具 ->
- NuGet 包管理器 ->
- 软件包管理器控制台
还有更多关于版本更新和安装的信息,请查看IronOCR on NuGet。
还有其他适用于不同平台的 IronOCR NuGet 包:
- Windows: https://www.nuget.org/packages/IronOcr
- Linux: https://www.nuget.org/packages/IronOcr.Linux
- MacOS: https://www.nuget.org/packages/IronOcr.MacOs
- MacOS (ARM): https://www.nuget.org/packages/IronOcr.MacOs.ARM
IronOcr.Extensions.AdvancedScan(适用于 Linux 和 macOS)
此软件包适用于使用 Linux 和 Mac 的用户,并希望为 IronOCR 使用高级功能。
- Linux: https://www.nuget.org/packages/IronOcr.Extensions.AdvancedScan.Linux
- MacOS: https://www.nuget.org/packages/IronOcr.Extensions.AdvancedScan.MacOs
故障排除
在此软件包的新版本更新中,IronOCR 将 OpenCV 依赖项合并到软件包内,以简化软件包,因此,如果当前导入 OpenCV 依赖项的开发人员会出现以下错误。
The type of namespace name `OpenCvSharp` could not be found(are you missing a using directive or an assembly reference)
您可以放心地删除 OpenCV 命名空间,问题就会得到解决。
下载 IronOCR .ZIP 文件
您也可以选择通过.ZIP文件下载IronOCR。 点击直接下载 DLL。 下载 .zip 文件后,您可以
.NET Framework 4.0+安装说明:
-
将 IronOcr.dll 加入 net40 文件夹
-
然后添加装配参考:
- 系统配置
- 系统绘图
- 系统网络
.NET Standard和.NET Core 2.0+以及.NET 5的安装说明:
-
将 netstandard2.0 文件夹中的 IronOcr.dll 包含到您的项目中
-
然后添加一个 NuGet 包引用到:
- 系统绘图.Common 4.7 或更高版本
下载IronOCR安装程序(仅限Windows)
另一种方法是下载我们的 IronOCR 安装程序,该程序将安装 IronOCR 开箱即用所需的所有资源。 请注意,此选项仅适用于 Windows 系统。 要下载安装程序,请点击这里。 下载 .zip 文件后,您可以
.NET Framework 4.0+安装说明:
-
将 IronOcr.dll 加入 net40 文件夹
-
然后添加装配参考:
- 系统配置
- 系统绘图
- 系统网络
.NET Standard和.NET Core 2.0+以及.NET 5的安装说明:
-
将 netstandard2.0 文件夹中的 IronOcr.dll 包含到您的项目中
-
然后添加一个 NuGet 包引用到:
- 系统绘图.Common 4.7 或更高版本
为什么选择IronOCR?
IronOCR for .NET 是一个易于安装、功能完备且文档齐全的 .NET 软件库。
选择 IronOCR 可实现 99.8%+ OCR 精确度,而无需使用任何外部网络服务、持续收费或通过互联网发送机密文件。
为什么 C# 开发者选择 IronOCR 而不是普通的 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 上部署
- 读取条形码和二维码
- 将 OCR 结果导出为 XHTML
- 将 OCR 输出为可搜索的 PDF 文档
- 多线程支持
- 125 种国际语言,全部通过 NuGet 或 OcrData 文件管理
- 提取图像、坐标、统计数据和字体。 不仅仅是文字。
- 可用于在商业和专有应用程序中重新发布 Tesseract OCR。
在处理真实世界的图像和不完美的文档(如照片或可能存在数字噪声或瑕疵的低分辨率扫描件)时,_IronOCR 可大显身手。
其他适用于.NET平台的免费OCR库,如其他.NET Tesseract API和网络服务,在这些实际应用案例中表现不佳。
使用 Tesseract 5 进行 OCR - 开始用 C# 编写代码
下面的代码示例显示了使用 C# 或 VB .NET 从图像中读取文本是多么容易。
一行代码
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;Dim Text As String = (New IronTesseract()).Read("img\Screenshot.png").TextDim Text As String = (New IronTesseract()).Read("img\Screenshot.png").Text可配置的Hello World
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// Add multiple images
input.LoadImage("images/sample.jpeg");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// Add multiple images
input.LoadImage("images/sample.jpeg");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' Add multiple images
input.LoadImage("images/sample.jpeg")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' Add multiple images
input.LoadImage("images/sample.jpeg")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)C# PDF OCR
相同的方法也可以用来从任何PDF文档中提取文本。
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// We can also select specific PDF page numbers to OCR
input.LoadPdf("example.pdf", Password: "password");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
// 1 page for every page of the PDF
Console.WriteLine($"{result.Pages.Length} Pages");using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// We can also select specific PDF page numbers to OCR
input.LoadPdf("example.pdf", Password: "password");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
// 1 page for every page of the PDF
Console.WriteLine($"{result.Pages.Length} Pages");Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' We can also select specific PDF page numbers to OCR
input.LoadPdf("example.pdf", Password:= "password")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
' 1 page for every page of the PDF
Console.WriteLine($"{result.Pages.Length} Pages")Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' We can also select specific PDF page numbers to OCR
input.LoadPdf("example.pdf", Password:= "password")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
' 1 page for every page of the PDF
Console.WriteLine($"{result.Pages.Length} Pages")用于多页 TIFF 的OCR
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("multi-frame.tiff", pageindices);
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("multi-frame.tiff", pageindices);
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("multi-frame.tiff", pageindices)
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("multi-frame.tiff", pageindices)
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)条形码和QR
IronOCR 的一个独特功能是它可以在扫描文本的同时读取文档中的条形码和二维码。 OcrResult.OcrBarcode类的实例为开发人员提供有关每个扫描条形码的详细信息。
using IronOcr;
IronTesseract ocr = new IronTesseract();
ocr.Configuration.ReadBarCodes = true;
using OcrInput input = new OcrInput();
input.LoadImage("img/Barcode.png");
OcrResult Result = ocr.Read(input);
foreach (var Barcode in Result.Barcodes)
{
// type and location properties also exposed
Console.WriteLine(Barcode.Value);
}using IronOcr;
IronTesseract ocr = new IronTesseract();
ocr.Configuration.ReadBarCodes = true;
using OcrInput input = new OcrInput();
input.LoadImage("img/Barcode.png");
OcrResult Result = ocr.Read(input);
foreach (var Barcode in Result.Barcodes)
{
// type and location properties also exposed
Console.WriteLine(Barcode.Value);
}Imports IronOcr
Private ocr As New IronTesseract()
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
input.LoadImage("img/Barcode.png")
Dim Result As OcrResult = ocr.Read(input)
For Each Barcode In Result.Barcodes
' type and location properties also exposed
Console.WriteLine(Barcode.Value)
Next Barcode
End UsingImports IronOcr
Private ocr As New IronTesseract()
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
input.LoadImage("img/Barcode.png")
Dim Result As OcrResult = ocr.Read(input)
For Each Barcode In Result.Barcodes
' type and location properties also exposed
Console.WriteLine(Barcode.Value)
Next Barcode
End Using对图像特定区域进行OCR
IronOCR 的所有扫描和阅读方法都能准确指定我们希望从页面的哪个或哪些部分读取文本。 当我们查看标准化表单时,这非常有用,可以节省大量时间并提高效率。
要使用裁剪区域,我们需要添加一个系统引用到System.Drawing,以便可以使用System.Drawing.Rectangle对象。
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// Dimensions are in pixel
var contentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
input.LoadImage("document.png", contentArea);
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// Dimensions are in pixel
var contentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
input.LoadImage("document.png", contentArea);
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' Dimensions are in pixel
Private contentArea = New System.Drawing.Rectangle() With {
.X = 215,
.Y = 1250,
.Height = 280,
.Width = 1335
}
input.LoadImage("document.png", contentArea)
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' Dimensions are in pixel
Private contentArea = New System.Drawing.Rectangle() With {
.X = 215,
.Y = 1250,
.Height = 280,
.Width = 1335
}
input.LoadImage("document.png", contentArea)
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)用于低质量扫描的OCR
IronOCR的OcrInput类可以修复普通Tesseract无法读取的扫描。
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageindices);
// fixes digital noise and poor scanning
input.DeNoise();
// fixes rotation and perspective
input.Deskew();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageindices);
// fixes digital noise and poor scanning
input.DeNoise();
// fixes rotation and perspective
input.Deskew();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\Potter.tiff", pageindices)
' fixes digital noise and poor scanning
input.DeNoise()
' fixes rotation and perspective
input.Deskew()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\Potter.tiff", pageindices)
' fixes digital noise and poor scanning
input.DeNoise()
' fixes rotation and perspective
input.Deskew()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)将 OCR 结果导出为可搜索的 PDF 文件
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.Title = "Quarterly Report";
input.LoadImage("image1.jpeg");
input.LoadImage("image2.png");
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("image3.gif", pageindices);
OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable.pdf");using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.Title = "Quarterly Report";
input.LoadImage("image1.jpeg");
input.LoadImage("image2.png");
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("image3.gif", pageindices);
OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable.pdf");Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.Title = "Quarterly Report"
input.LoadImage("image1.jpeg")
input.LoadImage("image2.png")
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("image3.gif", pageindices)
Dim result As OcrResult = ocr.Read(input)
result.SaveAsSearchablePdf("searchable.pdf")Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.Title = "Quarterly Report"
input.LoadImage("image1.jpeg")
input.LoadImage("image2.png")
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("image3.gif", pageindices)
Dim result As OcrResult = ocr.Read(input)
result.SaveAsSearchablePdf("searchable.pdf")TIFF转可搜索PDF转换
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("example.tiff", pageindices);
ocr.Read(input).SaveAsSearchablePdf("searchable.pdf");using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("example.tiff", pageindices);
ocr.Read(input).SaveAsSearchablePdf("searchable.pdf");Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("example.tiff", pageindices)
ocr.Read(input).SaveAsSearchablePdf("searchable.pdf")Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("example.tiff", pageindices)
ocr.Read(input).SaveAsSearchablePdf("searchable.pdf")将OCR结果导出为HTML
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.Title = "Html Title";
input.LoadImage("image1.jpeg");
OcrResult Result = ocr.Read(input);
Result.SaveAsHocrFile("results.html");using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.Title = "Html Title";
input.LoadImage("image1.jpeg");
OcrResult Result = ocr.Read(input);
Result.SaveAsHocrFile("results.html");Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.Title = "Html Title"
input.LoadImage("image1.jpeg")
Dim Result As OcrResult = ocr.Read(input)
Result.SaveAsHocrFile("results.html")Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.Title = "Html Title"
input.LoadImage("image1.jpeg")
Dim Result As OcrResult = ocr.Read(input)
Result.SaveAsHocrFile("results.html")OCR图像增强滤镜
IronOCR为OcrInput对象提供独特的滤镜,以提高OCR性能。
图像增强代码示例
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.LoadImage("LowQuality.jpeg");
// fixes digital noise and poor scanning
input.DeNoise();
// fixes rotation and perspective
input.Deskew();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.LoadImage("LowQuality.jpeg");
// fixes digital noise and poor scanning
input.DeNoise();
// fixes rotation and perspective
input.Deskew();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.LoadImage("LowQuality.jpeg")
' fixes digital noise and poor scanning
input.DeNoise()
' fixes rotation and perspective
input.Deskew()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.LoadImage("LowQuality.jpeg")
' fixes digital noise and poor scanning
input.DeNoise()
' fixes rotation and perspective
input.Deskew()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)OCR 图像过滤器列表
IronOCR 内置的用于提高 OCR 性能的输入过滤器包括
OcrInput.Rotate(double degrees)- 顺时针旋转图像若干度数。要逆时针旋转,请使用负数。OcrInput.Binarize()- 此滤镜将每个像素转换为黑色或白色,没有中间色,可能在对比度极低的图像中提高OCR性能。OcrInput.ToGrayScale()- 将每个像素转换为灰度阴影。 这可能不会提高准确性,但可以提高速度。OcrInput.Contrast()- 自动增加对比度,通常在对比度低的扫描中提高速度和准确性。OcrInput.DeNoise()- 移除数字噪音,仅在预期有噪音时建议使用。OcrInput.Invert()- 反转每种颜色(白色变为黑色,反之亦然)。OcrInput.Dilate()- 提升形态,增加像素到对象边界,与蚀刻相反。OcrInput.Erode()- 提升形态,从对象边界移除像素,与扩张相反。OcrInput.Deskew()- 旋转图像以正确定向。 这很有用,因为Tesseract的偏斜容忍度是有限的。OcrInput.EnhanceResolution- 提高低质量图像的分辨率。 该设置通常用于自动管理低 DPI 输入。EnhanceResolution检测低分辨率图像(低于275 dpi),放大并锐化文本以获得更好的OCR结果。 虽然耗时,但通常可以缩短整个 OCR 操作时间。Language- 支持从22种国际语言包中选择。Strategy- 允许根据单词的统计关系在快速和不精确或高级(使用 AI 提高准确性)策略之间选择。ColorSpace- 选择以灰度或彩色进行OCR; 通常,灰度最佳,但某些对比度情况下彩色更优.DetectWhiteTextOnDarkBackgrounds- 调整负片图像,自动检测并读取暗背景上的白色文字。InputImageType- 指导OCR库,指定是用于完整文档还是片段。RotateAndStraighten- 允许IronOCR正确处理旋转或受透视失真影响的文档。ReadBarcodes- 在文本扫描的同时自动读取条形码和QR码,无显著增加时间。ColorDepth- 确定在OCR过程中颜色深度的每像素位数。 更高的深度可以提高质量,但也会增加处理时间。
125种语言包
IronOCR通过语言包支持125种国际语言,这些语言包以DLL形式分发,可从本网站下载,或从NuGet Package Manager下载。
语言包括德语、法语、英语、中文、日语等。 专业语言包适用于MRZ、MICR支票、财务数据、车牌等。此外,可以使用自定义Tesseract“ .traineddata”文件。
语言示例
using IronOcr;
// PM> Install IronOcr.Languages.Arabic
IronTesseract ocr = new IronTesseract();
ocr.Language = OcrLanguage.Arabic;
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("img/arabic.gif", pageindices);
// Add image filters if needed
// In this case, even thought input is very low quality
// IronTesseract can read what conventional Tesseract cannot.
OcrResult result = ocr.Read(input);
// Console can't print Arabic on Windows easily.
// Let's save to disk instead.
result.SaveAsTextFile("arabic.txt");using IronOcr;
// PM> Install IronOcr.Languages.Arabic
IronTesseract ocr = new IronTesseract();
ocr.Language = OcrLanguage.Arabic;
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("img/arabic.gif", pageindices);
// Add image filters if needed
// In this case, even thought input is very low quality
// IronTesseract can read what conventional Tesseract cannot.
OcrResult result = ocr.Read(input);
// Console can't print Arabic on Windows easily.
// Let's save to disk instead.
result.SaveAsTextFile("arabic.txt");Imports IronOcr
' PM> Install IronOcr.Languages.Arabic
Private ocr As New IronTesseract()
ocr.Language = OcrLanguage.Arabic
Using input As New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img/arabic.gif", pageindices)
' Add image filters if needed
' In this case, even thought input is very low quality
' IronTesseract can read what conventional Tesseract cannot.
Dim result As OcrResult = ocr.Read(input)
' Console can't print Arabic on Windows easily.
' Let's save to disk instead.
result.SaveAsTextFile("arabic.txt")
End UsingImports IronOcr
' PM> Install IronOcr.Languages.Arabic
Private ocr As New IronTesseract()
ocr.Language = OcrLanguage.Arabic
Using input As New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img/arabic.gif", pageindices)
' Add image filters if needed
' In this case, even thought input is very low quality
' IronTesseract can read what conventional Tesseract cannot.
Dim result As OcrResult = ocr.Read(input)
' Console can't print Arabic on Windows easily.
' Let's save to disk instead.
result.SaveAsTextFile("arabic.txt")
End Using多语言示例
还可以同时使用多种语言进行 OCR。这可以增强对 Unicode 文档中的英文元数据和 URL 的 OCR 识别。
using IronOcr;
// PM> Install IronOcr.Languages.ChineseSimplified
IronTesseract ocr = new IronTesseract();
ocr.Language = OcrLanguage.ChineseSimplified;
// We can add any number of languages
ocr.AddSecondaryLanguage(OcrLanguage.English);
using OcrInput input = new OcrInput();
input.LoadPdf("multi-language.pdf");
OcrResult result = ocr.Read(input);
result.SaveAsTextFile("results.txt");using IronOcr;
// PM> Install IronOcr.Languages.ChineseSimplified
IronTesseract ocr = new IronTesseract();
ocr.Language = OcrLanguage.ChineseSimplified;
// We can add any number of languages
ocr.AddSecondaryLanguage(OcrLanguage.English);
using OcrInput input = new OcrInput();
input.LoadPdf("multi-language.pdf");
OcrResult result = ocr.Read(input);
result.SaveAsTextFile("results.txt");Imports IronOcr
' PM> Install IronOcr.Languages.ChineseSimplified
Private ocr As New IronTesseract()
ocr.Language = OcrLanguage.ChineseSimplified
' We can add any number of languages
ocr.AddSecondaryLanguage(OcrLanguage.English)
Using input As New OcrInput()
input.LoadPdf("multi-language.pdf")
Dim result As OcrResult = ocr.Read(input)
result.SaveAsTextFile("results.txt")
End UsingImports IronOcr
' PM> Install IronOcr.Languages.ChineseSimplified
Private ocr As New IronTesseract()
ocr.Language = OcrLanguage.ChineseSimplified
' We can add any number of languages
ocr.AddSecondaryLanguage(OcrLanguage.English)
Using input As New OcrInput()
input.LoadPdf("multi-language.pdf")
Dim result As OcrResult = ocr.Read(input)
result.SaveAsTextFile("results.txt")
End Using详细的OCR结果对象
IronOCR 会为每次操作返回一个 OCR 结果对象。 通常,开发人员访问Text属性以获取扫描文本。 不过,结果对象包含的信息要详细得多。
using IronOcr;
IronTesseract ocr = new IronTesseract();
// Must be set to true to read barcode
ocr.Configuration.ReadBarCodes = true;
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\sample.tiff", pageindices);
OcrResult result = ocr.Read(input);
var pages = result.Pages;
var words = pages[0].Words;
var barcodes = result.Barcodes;
// Explore here to find a massive, detailed API:
// - Pages, Blocks, Paraphaphs, Lines, Words, Chars
// - Image Export, Fonts Coordinates, Statistical Data, Tablesusing IronOcr;
IronTesseract ocr = new IronTesseract();
// Must be set to true to read barcode
ocr.Configuration.ReadBarCodes = true;
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\sample.tiff", pageindices);
OcrResult result = ocr.Read(input);
var pages = result.Pages;
var words = pages[0].Words;
var barcodes = result.Barcodes;
// Explore here to find a massive, detailed API:
// - Pages, Blocks, Paraphaphs, Lines, Words, Chars
// - Image Export, Fonts Coordinates, Statistical Data, TablesImports IronOcr
Private ocr As New IronTesseract()
' Must be set to true to read barcode
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\sample.tiff", pageindices)
Dim result As OcrResult = ocr.Read(input)
Dim pages = result.Pages
Dim words = pages(0).Words
Dim barcodes = result.Barcodes
' Explore here to find a massive, detailed API:
' - Pages, Blocks, Paraphaphs, Lines, Words, Chars
' - Image Export, Fonts Coordinates, Statistical Data, Tables
End UsingImports IronOcr
Private ocr As New IronTesseract()
' Must be set to true to read barcode
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\sample.tiff", pageindices)
Dim result As OcrResult = ocr.Read(input)
Dim pages = result.Pages
Dim words = pages(0).Words
Dim barcodes = result.Barcodes
' Explore here to find a massive, detailed API:
' - Pages, Blocks, Paraphaphs, Lines, Words, Chars
' - Image Export, Fonts Coordinates, Statistical Data, Tables
End Using性能
IronOCR 开箱即用,无需调整性能或修改图像。
速度惊人:IronOCR.2020+的速度最快可达旧版本的10倍,并且错误率减少超过250%。
了解更多
要了解更多关于C#、VB、F#或任何其他.NET语言的OCR,请阅读我们的社区教程,这些教程提供了IronOCR的实际使用示例,并展示了优化库的细微之处。
还提供了完整的.NET开发者API参考。
Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。