跳至页脚内容
OCR 工具

Windows OCR 引擎与 Tesseract:详细比较

在当今的数字时代,光学字符识别(OCR)技术已成为各行各业的重要组成部分,使图像和扫描文档转化为可编辑和可搜索的文本成为可能。

在众多可用的OCR软件中,如Google Cloud Vision(Cloud Vision API)、Adobe Acrobat Pro DC、ABBYY Finereader、Windows OCR Engine、Tesseract和IronOCR作为重要的竞争者脱颖而出,每个软件都提供独特的功能和能力来帮助文档分析。

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

1. OCR引擎介绍

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

2. Windows OCR引擎

Windows OCR引擎集成在Windows操作系统中,提供了一种便利且用户友好的解决方案,用于从输入图像和扫描文档中提取文本。 利用先进的图像处理技术,它能够准确识别各种语言和字体样式的文本。 Windows OCR引擎通过Windows运行时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;
using Windows.Graphics.Imaging;
using Windows.Media.Ocr;

class Program
{
    static async Task Main(string[] args)
    {
        // Provide the path to the image file
        string imagePath = "sample.png";
        try
        {
            // Call the ExtractText method to extract text from the image
            string extractedText = await ExtractText(imagePath);
            // Display the extracted text
            Console.WriteLine("Extracted Text:");
            Console.WriteLine(extractedText);
        }
        catch (Exception ex)
        {
            Console.WriteLine("An error occurred: " + ex.Message);
        }
    }

    public static 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 = File.OpenRead(image))
            {
                // Create a BitmapDecoder from the image file stream
                var bmpDecoder = await 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 = 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)
        {
            Console.WriteLine("Error during OCR process: " + ex.Message);
        }
        // Return the extracted text
        return text.ToString();
    }
}
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Windows.Graphics.Imaging;
using Windows.Media.Ocr;

class Program
{
    static async Task Main(string[] args)
    {
        // Provide the path to the image file
        string imagePath = "sample.png";
        try
        {
            // Call the ExtractText method to extract text from the image
            string extractedText = await ExtractText(imagePath);
            // Display the extracted text
            Console.WriteLine("Extracted Text:");
            Console.WriteLine(extractedText);
        }
        catch (Exception ex)
        {
            Console.WriteLine("An error occurred: " + ex.Message);
        }
    }

    public static 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 = File.OpenRead(image))
            {
                // Create a BitmapDecoder from the image file stream
                var bmpDecoder = await 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 = 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)
        {
            Console.WriteLine("Error during OCR process: " + ex.Message);
        }
        // Return the extracted text
        return text.ToString();
    }
}
Imports System
Imports System.IO
Imports System.Text
Imports System.Threading.Tasks
Imports Windows.Graphics.Imaging
Imports Windows.Media.Ocr

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
			' Call the ExtractText method to extract text from the image
			Dim extractedText As String = Await 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 Shared 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 = File.OpenRead(image)
				' Create a BitmapDecoder from the image file stream
				Dim bmpDecoder = Await 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 = 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
			Console.WriteLine("Error during OCR process: " & ex.Message)
		End Try
		' Return the extracted text
		Return text.ToString()
	End Function
End Class
$vbLabelText   $csharpLabel

2.2.1 输出

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

3. 超立方体

Tesseract是由Google开发的开源OCR引擎,以其准确性和多功能性获得了广泛的关注。 它支持超过100种语言,可以处理多种图像格式,包括TIFF、JPEG和PNG。 Tesseract OCR引擎使用深度学习算法和神经网络来实现高度的文本识别准确性,使其适用于广泛的应用场合。

3.1 Tesseract的关键功能

  • 语言支持: Tesseract引擎支持超过100种语言,包括复杂的文字如阿拉伯语和中文。
  • 图像预处理: 它提供了广泛的图像预处理功能,包括去斜、二值化和噪声减少,以提高文字识别的准确性。
  • 自定义选项: Tesseract允许用户微调OCR参数并为特定用例训练自定义模型,从而提高准确性和性能。

3.2 代码示例

using Patagames.Ocr;

class TesseractExample
{
    static void Main(string[] args)
    {
        // Create an OCR API instance
        using (var api = OcrApi.Create())
        {
            // Initialize the OCR engine for the English language
            api.Init(Patagames.Ocr.Enums.Languages.English);
            // Extract text from the image
            string plainText = api.GetTextFromImage(@"C:\Users\buttw\source\repos\ironqr\ironqr\bin\Debug\net5.0\Iron.png");
            // Display the extracted text
            Console.WriteLine(plainText);
        }
    }
}
using Patagames.Ocr;

class TesseractExample
{
    static void Main(string[] args)
    {
        // Create an OCR API instance
        using (var api = OcrApi.Create())
        {
            // Initialize the OCR engine for the English language
            api.Init(Patagames.Ocr.Enums.Languages.English);
            // Extract text from the image
            string plainText = api.GetTextFromImage(@"C:\Users\buttw\source\repos\ironqr\ironqr\bin\Debug\net5.0\Iron.png");
            // Display the extracted text
            Console.WriteLine(plainText);
        }
    }
}
Imports Patagames.Ocr

Friend Class TesseractExample
	Shared Sub Main(ByVal args() As String)
		' Create an OCR API instance
		Using api = OcrApi.Create()
			' Initialize the OCR engine for the English language
			api.Init(Patagames.Ocr.Enums.Languages.English)
			' Extract text from the image
			Dim plainText As String = api.GetTextFromImage("C:\Users\buttw\source\repos\ironqr\ironqr\bin\Debug\net5.0\Iron.png")
			' Display the extracted text
			Console.WriteLine(plainText)
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

3.2.1 输出

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

4. 铁氧体

IronOCR,由Iron Software开发的强大OCR引擎,以其卓越的准确性、易用性和多语言支持而区别于其他产品。 它提供本地OCR功能,支持超过125种语言,适用于全球应用。 IronOCR利用先进的机器学习算法和云视觉技术,即使在具有挑战性的情况下也能提供精确的文本识别结果。

4.1 IronOCR 的主要特点

  • 高准确性: IronOCR提供行业领先的文本识别准确性,确保在各种文档类型和语言中获得可靠的结果。
  • 多功能语言支持: 它支持超过125种语言,并提供综合的语言包,以实现无缝的多语言文本识别。
  • 简单的集成: IronOCR提供与.NET应用程序的简单集成,具有直观的API和广泛的文档,以便简化开发过程,包括预处理和后处理原始图像以提取文本。

4.2 安装IronOCR

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

  1. 在Visual Studio中,转到工具菜单并选择NuGet软件包管理器。
  2. 将出现一个新的列表,在此选择针对解决方案的NuGet软件包管理器。

Windows OCR引擎 vs Tesseract (OCR功能比较): 图 3 - 在何处找到Visual Studio NuGet包管理器

  1. 将出现一个新窗口,转到'浏览'选项卡并在搜索栏中键入'IronOCR'。
  2. 将出现软件包列表。 选择最新的IronOCR包并单击安装。

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

4.3 代码示例(C#)

using IronOcr;

class IronOCRExample
{
    static void Main(string[] args)
    {
        // Create an IronTesseract instance
        var ocr = new IronTesseract();
        // Set the language for OCR recognition
        ocr.Language = OcrLanguage.English;
        // Perform OCR on the specified image
        var result = ocr.Read(@"C:\Users\buttw\source\repos\ironqr\ironqr\bin\Debug\net5.0\Iron.png");
        // Display the extracted text
        Console.WriteLine(result.Text);
    }
}
using IronOcr;

class IronOCRExample
{
    static void Main(string[] args)
    {
        // Create an IronTesseract instance
        var ocr = new IronTesseract();
        // Set the language for OCR recognition
        ocr.Language = OcrLanguage.English;
        // Perform OCR on the specified image
        var result = ocr.Read(@"C:\Users\buttw\source\repos\ironqr\ironqr\bin\Debug\net5.0\Iron.png");
        // Display the extracted text
        Console.WriteLine(result.Text);
    }
}
Imports IronOcr

Friend Class IronOCRExample
	Shared Sub Main(ByVal args() As String)
		' Create an IronTesseract instance
		Dim ocr = New IronTesseract()
		' Set the language for OCR recognition
		ocr.Language = OcrLanguage.English
		' Perform OCR on the specified image
		Dim result = ocr.Read("C:\Users\buttw\source\repos\ironqr\ironqr\bin\Debug\net5.0\Iron.png")
		' Display the extracted text
		Console.WriteLine(result.Text)
	End Sub
End Class
$vbLabelText   $csharpLabel

4.3.1 输出

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

5. 对比评估

5.1 准确性和性能

  • Windows OCR引擎Tesseract提供了相当的准确性,但可能在复杂布局中遇到困难。
  • IronOCR: 在准确性方面表现出色,在各种文档类型和语言中提供可靠的结果,包括噪声图片。

5.2 集成便捷性

  • Windows OCR引擎: 无缝集成到Windows应用程序中,但缺乏自定义选项。
  • Tesseract: 需要额外配置和依赖项以进行集成,但提供广泛的自定义选项。
  • IronOCR: 提供与.NET应用程序的简单集成,具有直观的API和全面的文档。

5.3 语言支持

  • Windows OCR引擎相比Tesseract和IronOCR支持的语言数量有限。
  • Tesseract: 支持100多种语言。
  • IronOCR: 支持超过125种语言,使其适用于全球应用。

6.结论

总之,虽然Windows OCR引擎和Tesseract是文本识别的热门选择,但IronOCR是最准确和多功能的OCR引擎。其行业领先的准确性、广泛的语言支持和简单的集成使其成为企业和开发者寻求可靠OCR功能的出色解决方案。 通过使用IronOCR,组织可以简化文档处理工作流程,提高数据提取的准确性,并从扫描文档和图像中获取有价值的见解。

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

Kannaopat Udonpant
软件工程师
在成为软件工程师之前,Kannapat 在日本北海道大学完成了环境资源博士学位。在攻读学位期间,Kannapat 还成为了车辆机器人实验室的成员,隶属于生物生产工程系。2022 年,他利用自己的 C# 技能加入 Iron Software 的工程团队,专注于 IronPDF。Kannapat 珍视他的工作,因为他可以直接从编写大多数 IronPDF 代码的开发者那里学习。除了同行学习外,Kannapat 还喜欢在 Iron Software 工作的社交方面。不撰写代码或文档时,Kannapat 通常可以在他的 PS5 上玩游戏或重温《最后生还者》。