在實際環境中測試
在生產環境中測試無浮水印。
在任何需要的地方都能運作。
在今天的數位時代,光學文字辨識 (光學字符識別) 技術已成為各行各業不可或缺的一部分,使圖像和掃描文件轉換為可編輯和可搜索的文本。
在眾多OCR軟件中,如Google Cloud Vision (云端视觉 API),Adobe Acrobat Pro DC、ABBYY Finereader 和許多其他,Windows OCR 引擎 vs Tesseract,和 IronOCR 脫穎而出,成為突出的競爭者,每個都提供獨特的功能和能力來幫助文件分析。
本文旨在對這三個OCR引擎進行全面比較分析,評估其準確性、性能和集成的便利性。
OCR 引擎是設計用來識別和提取圖像、PDF 和其他掃描文件中的純文字的軟件工具。它們採用複雜的算法和機器學習技術來準確識別字符,並將其轉換為機器可讀的文本文件。Windows OCR Engine、Tesseract 和 IronOCR 代表了三種廣泛使用的 OCR 解決方案,每個都有其優勢和應用。
Windows OCR 引擎集成到 Windows 操作系統提供了一個方便且使用者友好的解決方案,用於從輸入影像和掃描文件中提取文本。利用先進的影像處理技術,它能夠準確識別多種語言和字體樣式的文本。Windows OCR 引擎可通過 Windows Runtime API 訪問,實現無縫整合到具有命令列工具功能的 Windows 應用程式中。
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
Tesseract,Google開發的一個開源 OCR 引擎,因其準確性和多功能性而廣受歡迎。它支持超過 100 種語言,並且可以處理各種圖像格式,包括 TIFF、JPEG 和 PNG。Tesseract OCR 引擎使用深度學習算法和神經網絡來實現高水平的文本識別準確性,使其適用於廣泛的應用。
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
IronOCR由 Iron Software 開發的強大 OCR 引擎,以其卓越的準確性、易用性和多語言支持脫穎而出。它提供內部部署的 OCR 功能,支持超過127種語言,使其適用於全球應用。IronOCR 利用先進的機器學習算法和雲端視覺技術,即使在具有挑戰性的場景中也能提供精確的文本識別結果。
在進行程式碼範例之前,讓我們看看如何使用 NuGet 套件管理工具安裝 IronOCR。
在 Visual Studio 中,進入工具選單並選擇 NuGet 套件管理工具。
將會出現一個新窗口,前往「瀏覽」標籤頁,在搜索欄中輸入「IronOCR」。
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)
6. 結論
總而言之,雖然 Windows OCR 引擎和 Tesseract 是文本識別的熱門選擇, IronOCR 成為最準確且多功能的OCR引擎。其業界領先的準確性、廣泛的語言支持以及簡單的整合,讓它成為企業和開發者尋求可靠OCR功能的卓越解決方案。通過利用IronOCR,組織可以簡化文件處理工作流程,提高數據提取的準確性,並從掃描的文件和圖像中解鎖有價值的見解。