OCR工具

Windows OCR引擎与Tesseract(OCR功能比较)

发布 2024年四月3日
分享:

在当今的数字时代,光学字符识别技术 (光学字符识别) 技术已成为各行各业不可或缺的一部分,可将图像和扫描文件转换为可编辑和可搜索的文本。

在众多 OCR 软件中,如 Google Cloud Vision (云视觉应用程序接口)Adobe Acrobat Pro DC、ABBYY Finereader 等等,Windows OCR 引擎与 Tesseract 的对比,以及 Adobe Acrobat Pro DC 与 ABBYY Finereader 的对比。 IronOCR 在竞争中脱颖而出,各自提供独特的功能和性能来帮助文档分析。

本文旨在对这三种 OCR 引擎进行全面的比较分析,评估它们的准确性、性能和易集成性。

1.OCR 引擎简介

OCR 引擎是一种软件工具,用于识别和提取图像、PDF 和其他扫描文档中的纯文本。它们采用复杂的算法和机器学习技术来准确识别字符,并将其转换为机器可读的文本文件。Windows OCR Engine、Tesseract 和 IronOCR 是三种广泛使用的 OCR 解决方案,各有其优势和应用。

2.Windows OCR 引擎

識別 Windows OCR 引擎该软件集成到 Windows 操作系统中,为从输入图像和扫描文档中提取文本提供了一个方便且用户友好的解决方案。利用先进的图像处理技术,它可以准确识别各种语言和字体风格的文本。Windows OCR 引擎可通过 Windows Runtime API 访问,从而实现与 Windows 应用程序的无缝集成,并具备命令行工具的功能。

2.1 Windows OCR 引擎的主要功能

  • 语言支持:Windows OCR 引擎支持多种语言,因此适用于多语言文档。
  • 图像处理:它采用先进的图像处理算法,即使在低质量图像中也能提高印刷文本识别的准确性。

  • 与 Windows 应用程序集成:Windows OCR 引擎可与 Windows 应用程序无缝集成,允许开发人员将 OCR 功能完全整合到自己的软件中。

2.2 代码示例

using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static async Task Main(string [] args)
    {
        // Provide the path to the image file
        string imagePath = "sample.png";
        try
        {
            // Instantiate the program class
            Program program = new Program();
            // Call the ExtractText method to extract text from the image
            string extractedText = await program.ExtractText(imagePath);
            // Display the extracted text
            Console.WriteLine("Extracted Text:");
            Console.WriteLine(extractedText);
        }
        catch (Exception ex)
        {
            Console.WriteLine("An error occurred: " + ex.Message);
        }
    }
    public async Task<string> ExtractText(string image)
    {
        // Initialize StringBuilder to store extracted text
        StringBuilder text = new StringBuilder();
        try
        {
            // Open the image file stream
            using (var fileStream = System.IO.File.OpenRead(image))
            {
                Console.WriteLine("Extracted Text:");
                // Create a BitmapDecoder from the image file stream
                var bmpDecoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(fileStream.AsRandomAccessStream());
                // Get the software bitmap from the decoder
                var softwareBmp = await bmpDecoder.GetSoftwareBitmapAsync();
                // Create an OCR engine from user profile languages
                var ocrEngine = Windows.Media.Ocr.OcrEngine.TryCreateFromUserProfileLanguages();
                // Recognize text from the software bitmap
                var ocrResult = await ocrEngine.RecognizeAsync(softwareBmp);
                // Append each line of recognized text to the StringBuilder
                foreach (var line in ocrResult.Lines)
                {
                    text.AppendLine(line.Text);
                }
            }
        }
        catch (Exception ex)
        {
            throw ex; // Propagate the exception
        }
        // Return the extracted text
        return text.ToString();
    }
}
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static async Task Main(string [] args)
    {
        // Provide the path to the image file
        string imagePath = "sample.png";
        try
        {
            // Instantiate the program class
            Program program = new Program();
            // Call the ExtractText method to extract text from the image
            string extractedText = await program.ExtractText(imagePath);
            // Display the extracted text
            Console.WriteLine("Extracted Text:");
            Console.WriteLine(extractedText);
        }
        catch (Exception ex)
        {
            Console.WriteLine("An error occurred: " + ex.Message);
        }
    }
    public async Task<string> ExtractText(string image)
    {
        // Initialize StringBuilder to store extracted text
        StringBuilder text = new StringBuilder();
        try
        {
            // Open the image file stream
            using (var fileStream = System.IO.File.OpenRead(image))
            {
                Console.WriteLine("Extracted Text:");
                // Create a BitmapDecoder from the image file stream
                var bmpDecoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(fileStream.AsRandomAccessStream());
                // Get the software bitmap from the decoder
                var softwareBmp = await bmpDecoder.GetSoftwareBitmapAsync();
                // Create an OCR engine from user profile languages
                var ocrEngine = Windows.Media.Ocr.OcrEngine.TryCreateFromUserProfileLanguages();
                // Recognize text from the software bitmap
                var ocrResult = await ocrEngine.RecognizeAsync(softwareBmp);
                // Append each line of recognized text to the StringBuilder
                foreach (var line in ocrResult.Lines)
                {
                    text.AppendLine(line.Text);
                }
            }
        }
        catch (Exception ex)
        {
            throw ex; // Propagate the exception
        }
        // Return the extracted text
        return text.ToString();
    }
}
Imports System
Imports System.IO
Imports System.Text
Imports System.Threading.Tasks
Friend Class Program
	Shared Async Function Main(ByVal args() As String) As Task
		' Provide the path to the image file
		Dim imagePath As String = "sample.png"
		Try
			' Instantiate the program class
			Dim program As New Program()
			' Call the ExtractText method to extract text from the image
			Dim extractedText As String = Await program.ExtractText(imagePath)
			' Display the extracted text
			Console.WriteLine("Extracted Text:")
			Console.WriteLine(extractedText)
		Catch ex As Exception
			Console.WriteLine("An error occurred: " & ex.Message)
		End Try
	End Function
	Public Async Function ExtractText(ByVal image As String) As Task(Of String)
		' Initialize StringBuilder to store extracted text
		Dim text As New StringBuilder()
		Try
			' Open the image file stream
			Using fileStream = System.IO.File.OpenRead(image)
				Console.WriteLine("Extracted Text:")
				' Create a BitmapDecoder from the image file stream
				Dim bmpDecoder = Await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(fileStream.AsRandomAccessStream())
				' Get the software bitmap from the decoder
				Dim softwareBmp = Await bmpDecoder.GetSoftwareBitmapAsync()
				' Create an OCR engine from user profile languages
				Dim ocrEngine = Windows.Media.Ocr.OcrEngine.TryCreateFromUserProfileLanguages()
				' Recognize text from the software bitmap
				Dim ocrResult = Await ocrEngine.RecognizeAsync(softwareBmp)
				' Append each line of recognized text to the StringBuilder
				For Each line In ocrResult.Lines
					text.AppendLine(line.Text)
				Next line
			End Using
		Catch ex As Exception
			Throw ex ' Propagate the exception
		End Try
		' Return the extracted text
		Return text.ToString()
	End Function
End Class
VB   C#

2.2.1 输出

Windows OCR 引擎与 Tesseract(OCR 功能比较):图 1 - Windows OCR 引擎代码的控制台输出

3.魔方

魔方谷歌开发的开放源码 OCR 引擎因其准确性和多功能性而广受欢迎。它支持 100 多种语言,可以处理各种图像格式,包括 TIFF、JPEG 和 PNG。Tesseract OCR Engine 采用了深度学习算法和神经网络来实现高水平的文本识别准确性,因此适用于多种应用。

3.1 魔方的主要功能

  • 语言支持:Tesseract 引擎支持 100 多种语言,包括阿拉伯语和中文等复杂脚本。
  • 图像预处理:它提供广泛的图像预处理功能,包括纠偏、二值化和降噪,以提高文本识别的准确性。

  • 自定义选项:Tesseract 允许用户微调 OCR 参数,并针对特定用例训练自定义模型,从而提高准确性和性能。

3.2 代码示例

using Patagames.Ocr;
using (var api = OcrApi.Create())
{
    api.Init(Patagames.Ocr.Enums.Languages.English);
    string plainText = api.GetTextFromImage(@"C:\Users\buttw\source\repos\ironqr\ironqr\bin\Debug\net5.0\Iron.png");
    Console.WriteLine(plainText);
}
using Patagames.Ocr;
using (var api = OcrApi.Create())
{
    api.Init(Patagames.Ocr.Enums.Languages.English);
    string plainText = api.GetTextFromImage(@"C:\Users\buttw\source\repos\ironqr\ironqr\bin\Debug\net5.0\Iron.png");
    Console.WriteLine(plainText);
}
Imports Patagames.Ocr
Using api = OcrApi.Create()
	api.Init(Patagames.Ocr.Enums.Languages.English)
	Dim plainText As String = api.GetTextFromImage("C:\Users\buttw\source\repos\ironqr\ironqr\bin\Debug\net5.0\Iron.png")
	Console.WriteLine(plainText)
End Using
VB   C#

3.2.1 输出

Windows OCR 引擎与 Tesseract(OCR 功能比较):图 2 - Tesserat 代码的控制台输出

4.IronOCR

IronOCR由 Iron Software 开发的强大 OCR 引擎以其卓越的准确性、易用性和多语言支持而独树一帜。它提供内部部署 OCR 功能,支持超过 127 种语言,适合全球应用。IronOCR 利用先进的机器学习算法和云视觉技术提供精确的文本识别结果,即使在具有挑战性的场景中也不例外。

4.1 IronOCR 的主要功能

  • 高准确度:IronOCR 的文本识别准确度在行业内处于领先地位,可确保在各种文档类型和语言中获得可靠的识别结果。
  • 多语言支持:它支持超过 127 种语言,并提供全面的语言包,可实现无缝的多语言文本识别。

  • 集成简单:IronOCR 与.NET 应用程序直接集成,具有直观的应用程序接口(API)和丰富的文档,可简化预处理和后处理原始图像以提取文本的开发流程。

4.2 安装 IronOCR

在进入编码示例之前,让我们来看看如何使用 NuGet 软件包管理器安装 IronOCR。

1.在 Visual Studio 中进入 "工具 "菜单,选择 "NuGet 包管理器"。

2.会出现一个新列表,在此选择解决方案的 NuGet 包管理器。

Windows OCR Engine 与 Tesseract(OCR 功能比较):图 3 - 如何找到 Visual Studio NuGet 软件包管理器

3.这时会出现一个新窗口,进入 "浏览 "选项卡,然后在搜索栏中输入 "IronOCR"。

4.这时会出现软件包列表 选择最新的 IronOCR 软件包并点击安装。

Windows OCR 引擎与 Tesseract(OCR 功能比较):图 4 - 安装 IronOCR 软件包

4.3 代码示例 (C&num;)

using IronOcr;
var ocr = new IronTesseract();
ocr.Language = OcrLanguage.English;
var result = ocr.Read("C:\\Users\\buttw\\source\\repos\\ironqr\\ironqr\\bin\\Debug\\net5.0\\Iron.png");
Console.WriteLine(result.Text);
using IronOcr;
var ocr = new IronTesseract();
ocr.Language = OcrLanguage.English;
var result = ocr.Read("C:\\Users\\buttw\\source\\repos\\ironqr\\ironqr\\bin\\Debug\\net5.0\\Iron.png");
Console.WriteLine(result.Text);
Imports IronOcr
Private ocr = New IronTesseract()
ocr.Language = OcrLanguage.English
Dim result = ocr.Read("C:\Users\buttw\source\repos\ironqr\ironqr\bin\Debug\net5.0\Iron.png")
Console.WriteLine(result.Text)
VB   C#

4.3.1 输出

Windows OCR 引擎与 Tesseract(OCR 功能比较):图 5 - IronOCR 代码的控制台输出

5.比较评估

5.1 准确性和性能

  • Windows OCR 引擎和 Tesseract 可提供不错的准确性,但在处理复杂布局和手写文本时可能会有困难。
  • IronOCR:在准确性方面表现出色,可为各种文档类型和语言(包括手写文本和嘈杂图像)提供可靠的结果。

5.2 易于整合

  • Windows OCR 引擎:可与 Windows 应用程序无缝集成,但缺乏自定义选项。
  • Tesseract:需要额外的配置和依赖关系才能集成,但提供广泛的自定义选项。

  • IronOCR:可与.NET 应用程序简单集成,具有直观的应用程序接口和全面的文档。

5.3 语言支持

  • 与 Tesseract 和 IronOCR 相比,Windows OCR 引擎和 Tesseract 支持的语言数量有限。
  • IronOCR:支持超过 127 种语言,适合全球应用。

6.结论

总之,Windows OCR Engine 和 Tesseract 是文本识别的热门选择、 IronOCR 成为最准确、功能最全面的 OCR 引擎。其业界领先的准确性、广泛的语言支持和简单的集成使其成为企业和开发人员寻求可靠 OCR 功能的杰出解决方案。利用 IronOCR,企业可以简化文档处理工作流程,提高数据提取的准确性,并从扫描文档和图像中获取有价值的信息。

IronOCR 提供 免费试用.要了解有关 IronOCR 及其功能的更多信息,请访问 *这里***.

< 前一页
基于云的OCR(OCR功能比较)
下一步 >
Azure OCR 与 Google OCR(OCR 功能对比)

准备开始了吗? 版本: 2024.9 刚刚发布

免费NuGet下载 总下载量: 2,319,721 查看许可证 >