跳至頁尾內容
與其他組件的比較

Tesseract vs Microsoft OCR:頭對頭比較

開發者經常在選擇使用Tesseract OCR工具還是Microsoft OCR引擎來進行C#的光學文字辨識(OCR)時陷入兩難。 儘管這兩者具備不同的能力、效率、整合性以及易用性,它們都是從照片或掃描文件中擷取文字的有效OCR工具。 在C#開發的框架內,我們將在本文中徹底檢視不同OCR工具(例如Tesseract與Microsoft OCR)的優點、缺點及適用性。

什麼是OCR?

光學文字辨識稱為OCR。 這是一項技術,可以將各種文件格式(如掃描的影像文件、PDF檔案或數位相機照片)轉換為可編輯和可搜尋的資料。 為了將影像的形狀和模式轉換為機器可讀的文字,不同的OCR工具如Google Cloud Vision或Google Vision OCR會分析這些影像。 利用這項技術,使用者可以從照片中提取文字,並像處理數位文件一樣編輯、搜尋及更改內容。

Tesseract OCR

Tesseract OCR是一個開源的光學文字辨識(OCR)引擎,有時簡稱為Tesseract。 Tesseract最初由Hewlett-Packard實驗室於1980年代建立,現在由Google維護,是當前最受歡迎的OCR引擎之一。

Tesseract的主要功能是識別圖片或處理掃描文件中的文字,並將其翻譯為機器可讀的文字。 這使得文字可編輯、可搜尋和可操作,允許使用者從各種來源中提取文字,包括掃描文件分析、照片和PDF文件。

Tesseract OCR的主要特點

  • 開源: Tesseract在Apache License 2.0條款下可自由使用、修改和分發。它的開源設計大大促成了其廣泛的採用和持續的改進,這要歸功於社群的貢獻。
  • 語言支援: Tesseract除了可以識別語言外,還能識別超過100種不同的腳本和字元集。 由於多語言能力,它適合於各種語言和地理區域的廣泛OCR應用。
  • 準確性: Tesseract因其出色的文字識別準確性而聞名,特別是在正確設定且用相關資料訓練的情況下。 它能夠可靠地從具有多種問題的照片中提取文字,包括扭曲的角度、低質量和不充分的照明。
  • 選項: Tesseract提供了大量的配置和自訂選項。 對於特定的使用案例,使用者可以調整若干參數以最大化OCR性能。 此外,Tesseract可以與各種平台和電腦語言(例如Java、C++、Python和C#)結合,讓開發者在廣泛的應用程式中利用其功能。
  • Tesseract持續開發和維護,定期新增新的功能以提高其準確性、性能和語言支援。 Tesseract的開源社群支援其持續開發,保證它始終是一個最先進的OCR工具。

為.NET安裝Tesseract OCR

在您的電腦上安裝Tesseract OCR是第一步。您可以從官方Tesseract的GitHub資料庫中獲取Tesseract安裝程式:https://github.com/tesseract-ocr/tesseract

要在您的電腦上安裝Tesseract OCR,請按照與您的作業系統(Windows、macOS或Linux)特定的安裝說明進行操作。 在安裝Tesseract OCR後,使用Visual Studio的NuGet套件管理器將Tesseract.NET包裝器新增到您的C#項目中。

開啟您的C#項目後,導航到工具選單 -> NuGet套件管理器 -> 專案解決方案的NuGet套件管理, 在NuGet套件管理器中,您應可以通過搜尋"Tesseract"找到名為"Tesseract"或"Tesseract.NET"的套件。 要將該套件包括在您的專案中,請選擇它並點擊安裝。

Tesseract vs Microsoft OCR(OCR功能比較):圖1 - Tesseract

Tesseract OCR using C

按照以下步驟在您的C#專案中使用Tesseract:

using Tesseract;

class Program
{
    static void Main(string[] args)
    {
        // Initialize the Tesseract engine with the path to your Tesseract installation and the desired language(s)
        using (var engine = new TesseractEngine(@"path_to_tesseract_folder", "eng", EngineMode.Default))
        {
            // Load the image from which to extract text
            using (var img = Pix.LoadFromFile("image.png"))
            {
                // Process the image and extract the text
                using (var page = engine.Process(img))
                {
                    // Get the extracted text
                    var text = page.GetText();
                    Console.WriteLine(text); // Print the extracted text
                }
            }
        }
    }
}
using Tesseract;

class Program
{
    static void Main(string[] args)
    {
        // Initialize the Tesseract engine with the path to your Tesseract installation and the desired language(s)
        using (var engine = new TesseractEngine(@"path_to_tesseract_folder", "eng", EngineMode.Default))
        {
            // Load the image from which to extract text
            using (var img = Pix.LoadFromFile("image.png"))
            {
                // Process the image and extract the text
                using (var page = engine.Process(img))
                {
                    // Get the extracted text
                    var text = page.GetText();
                    Console.WriteLine(text); // Print the extracted text
                }
            }
        }
    }
}
Imports Tesseract

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' Initialize the Tesseract engine with the path to your Tesseract installation and the desired language(s)
		Using engine = New TesseractEngine("path_to_tesseract_folder", "eng", EngineMode.Default)
			' Load the image from which to extract text
			Using img = Pix.LoadFromFile("image.png")
				' Process the image and extract the text
				Using page = engine.Process(img)
					' Get the extracted text
					Dim text = page.GetText()
					Console.WriteLine(text) ' Print the extracted text
				End Using
			End Using
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

要做到這一點,請在TesseractEngine構造函式選項中提供Tesseract安裝目錄的位置及您希望使用的語言或語言。 將"path_to_tesseract_folder"替換為實際的Tesseract安裝目錄路徑。

在您的C#專案中設置好Tesseract後,您現在可以使用其OCR功能從圖片中提取文字。 TesseractEngine實例可以在使用Pix類載入圖片後處理圖片以提取文字或在影像文件上運行OCR,將"image.png"替換為影像文件的路徑。

什麼是Microsoft OCR?

Microsoft的認知服務套件包括Microsoft OCR,有時也稱為Microsoft光學字元識別。 Microsoft Azure提供一種基於雲的光學字元識別(OCR)解決方案,能夠從文件和照片中提取文字,並具備增強的文字識別能力。 Microsoft OCR使用深度神經網路和機器學習技術從多種來源中識別文字,並且具有卓越的準確性。

關鍵特性

  • 與Azure認知服務的整合: Microsoft OCR與Azure認知服務協同工作,這是一組由AI驅動的Microsoft Azure API和服務。 透過這種連接,開發者可以通過使用REST API、SDK和客戶端庫,輕鬆將Microsoft OCR功能整合到應用程式和工作流程中。
  • 高準確性和性能: 由於其訓練了大量資料集的先進機器學習模型,Microsoft OCR提供高準確性和性能的字元識別。 由於能夠從具有複雜佈局和各種型別的照片中準確提取文字,它適用於廣泛的OCR應用寺。
  • 可擴展性和可靠性:身為Azure 認知服務的一部分,Microsoft OCR提供可擴展性和依賴性,這使得它作為一個適合不同處理需求的應用程式。 它可以藉由保證正常運行時間和穩定性能來有效地處理高數量的文件和多個請求。
  • 多語言支持:如其他OCR程式一樣,Microsoft OCR 允許多語言識別,使使用者可以從多種語言和字集的照片中提取文字。 因為它具有多語言支持,它適用於廣泛的應用程式,滿足不同的語言需求。

您必須將Microsoft OCR 與Azure 認知服務(更具體地說是計算機視覺API)結合起來才能在您的C#專案中使用它。 以下是您可以開始使用的方法:

建立Azure帳戶

如果您還沒有Azure帳戶,必須建立一個。 您可以建立一個免費的Azure帳戶,在試用期間可存取多種服務。

配置Azure認知服務

當您有了Azure帳戶後,需要在Azure認知服務中配置計算機視覺服務。

  • 開啟 Azure入口網站
  • 在"建立資源"中搜尋"計算機視覺"。
  • 選擇計算機視覺服務後,點擊"建立"。 -根據提示選擇訂閱和價格層以配置服務。
  • 在建立服務後,轉到資源並保存訂閱金鑰和端點URL; 您需要它們來驗證您的查詢的真實性。

安裝Azure認知服務SDK

可使用Microsoft Azure。 在您的C#項目中使用CognitiveServices.Vision.ComputerVision NuGet軟體包。

開啟您的C#項目後,導航到工具 -> NuGet Package Manager -> 管理解決方案中的NuGet軟體包。

透過搜尋"Microsoft.Azure.CognitiveServices.Vision.ComputerVision"來安裝這個軟體包。

Tesseract vs Microsoft OCR(OCR功能比較):圖2 - Microsoft.Azure.CognitiveServices.Vision.ComputerVision

Microsoft OCR Using C

安裝SDK後,您可以使用計算機視覺API進行OCR操作。 以下是一些使用計算機視覺API進行OCR的簡單範例:

using System;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        // Set your endpoint and subscription key for authentication
        var endpoint = "YOUR_ENDPOINT";
        var subscriptionKey = "YOUR_SUBSCRIPTION_KEY";

        // Create a new instance of the ComputerVisionClient
        var client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(subscriptionKey))
        {
            Endpoint = endpoint
        };

        // Perform OCR on the specified image
        var result = await client.RecognizePrintedTextInStreamAsync(true, "image.png");

        // Iterate over the results and print the recognized text
        foreach (var region in result.Regions)
        {
            foreach (var line in region.Lines)
            {
                foreach (var word in line.Words)
                {
                    Console.WriteLine(word.Text);
                }
            }
        }
    }
}
using System;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        // Set your endpoint and subscription key for authentication
        var endpoint = "YOUR_ENDPOINT";
        var subscriptionKey = "YOUR_SUBSCRIPTION_KEY";

        // Create a new instance of the ComputerVisionClient
        var client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(subscriptionKey))
        {
            Endpoint = endpoint
        };

        // Perform OCR on the specified image
        var result = await client.RecognizePrintedTextInStreamAsync(true, "image.png");

        // Iterate over the results and print the recognized text
        foreach (var region in result.Regions)
        {
            foreach (var line in region.Lines)
            {
                foreach (var word in line.Words)
                {
                    Console.WriteLine(word.Text);
                }
            }
        }
    }
}
Imports System
Imports Microsoft.Azure.CognitiveServices.Vision.ComputerVision
Imports Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models
Imports System.Threading.Tasks

Friend Class Program
	Shared Async Function Main(ByVal args() As String) As Task
		' Set your endpoint and subscription key for authentication
		Dim endpoint = "YOUR_ENDPOINT"
		Dim subscriptionKey = "YOUR_SUBSCRIPTION_KEY"

		' Create a new instance of the ComputerVisionClient
		Dim client = New ComputerVisionClient(New ApiKeyServiceClientCredentials(subscriptionKey)) With {.Endpoint = endpoint}

		' Perform OCR on the specified image
		Dim result = Await client.RecognizePrintedTextInStreamAsync(True, "image.png")

		' Iterate over the results and print the recognized text
		For Each region In result.Regions
			For Each line In region.Lines
				For Each word In line.Words
					Console.WriteLine(word.Text)
				Next word
			Next line
		Next region
	End Function
End Class
$vbLabelText   $csharpLabel

要在影像文件上執行OCR,請將上面的程式碼樣本中的"image.png"替換為影像文件的路徑。 該程式碼通過發送該影像到計算機視覺API來獲取影像中識別出的文字。 在Azure認知服務中配置計算機視覺服務後,您收到的端點URL和訂閱金鑰應替換"YOUR_SUBSCRIPTION_KEY"

什麼是IronOCR?

開發者可以在他們的C#或VB.NET應用程式中整合文字識別功能與IronOCR ,這是一個 .NET OCR庫。 它提供了一個使用者友好的API,用於從PDF、圖片和其他型別的媒體中提取文字。 Iron Software,一家專注於.NET元件與庫的軟體開發公司,建立並維護IronOCR。

IronOCR的關鍵功能

  • 簡單整合:可以輕鬆透過使用NuGet套件或直接在您的專案中存取該程式庫來將IronOCR整合到您的C#或VB.NET專案中。
  • 多功能OCR: IronOCR能夠識別來自廣泛來源的文字,如截圖、掃描的文件、PDF文件及照片。它能夠處理幾種影像型別,包括BMP、TIFF、PNG和JPEG。
  • 準確的文字識別: IronOCR使用先進的OCR算法提供卓越的文字識別準確性。 它能夠可靠地從解析度不同、字體不同以及背景不同的圖片中提取文字。
  • 對多種語言的支援: IronOCR適合多語言應用程式,因為它能夠識別多種語言。 它支持定制語言訓練,並且附有常用語言的內建語言包。
  • PDF文字提取:掃描及基於影像的PDF都能透過IronOCR提取文字。 從PDF文件中提取文字時,它可以保持內容的原始格式和佈局。
  • 圖像預處理:在OCR處理之前,IronOCR可以透過圖像預處理功能提高傳入影像的質量。 這包括例如糾偏、對比度修改以及降噪等任務。

IronOCR Using C

這是一個使用IronOCR的基本C#範例:

// Create an instance of IronTesseract
var Ocr = new IronTesseract(); // nothing to configure
// Set the language and Tesseract version to be used for OCR
Ocr.Language = OcrLanguage.EnglishBest;
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;

// Prepare the image input and perform OCR
using (var Input = new OcrInput())
{
    // Add the image for OCR processing
    Input.AddImage(@"Demo.png");
    // Read the text from the image
    var Result = Ocr.Read(Input);
    // Print the recognized text
    Console.WriteLine(Result.Text);
    Console.ReadKey(); // Wait for user input before closing
}
// Create an instance of IronTesseract
var Ocr = new IronTesseract(); // nothing to configure
// Set the language and Tesseract version to be used for OCR
Ocr.Language = OcrLanguage.EnglishBest;
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;

// Prepare the image input and perform OCR
using (var Input = new OcrInput())
{
    // Add the image for OCR processing
    Input.AddImage(@"Demo.png");
    // Read the text from the image
    var Result = Ocr.Read(Input);
    // Print the recognized text
    Console.WriteLine(Result.Text);
    Console.ReadKey(); // Wait for user input before closing
}
' Create an instance of IronTesseract
Dim Ocr = New IronTesseract() ' nothing to configure
' Set the language and Tesseract version to be used for OCR
Ocr.Language = OcrLanguage.EnglishBest
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5

' Prepare the image input and perform OCR
Using Input = New OcrInput()
	' Add the image for OCR processing
	Input.AddImage("Demo.png")
	' Read the text from the image
	Dim Result = Ocr.Read(Input)
	' Print the recognized text
	Console.WriteLine(Result.Text)
	Console.ReadKey() ' Wait for user input before closing
End Using
$vbLabelText   $csharpLabel

使用上述程式碼,我們可以達到最高OCR精度地從圖像中提取資料。 此外,IronOCR還促進了從文件中提取的文字轉換為可編輯文件格式,如Word。 我們也可以將掃描的文件轉換成為可搜尋的PDF。 使用IronOCR,結果可以以各種OCR輸出格式保存。 欲了解有關於程式碼的更多資訊,請參考這裡

來源影像:

Tesseract vs Microsoft OCR(OCR功能比較):圖3 - 輸入影像

結果:

Tesseract vs Microsoft OCR(OCR功能比較):圖4 - 控制台輸出

結論

結論是,Tesseract和Microsoft OCR都為C#開發者提供強大的OCR功能,分別具有獨特的優勢和缺點。 由於Tesseract提供了定制和靈活性,它是需要高度調整的應用的良好選擇。 然而,微軟OCR憑借其高精度、可擴展性及與Azure服務的無縫連結,是需要高階字元識別功能的C#應用最好的選擇。 開發人員應針對其個別需求、修訂要求及財務上限權衡考量後,在Tesseract或Microsoft OCR之間作出選擇。

最後,IronOCR是一個卓越的OCR解決方案,提供了出色的整合、靈活性和準確性。 由於其無與倫比的準確性、先進的演算法及識別各種型別文件的能力,IronOCR當之無愧是當前市場上最好的OCR解決方案。 因為IronOCR可以順利跨越多種文件和常見計算機語言進行整合,它確保了開發者的可及性,同時保持簡潔明了的介面。

您可以免費嘗試IronOCR的實惠的開發版本,如果您購買IronOCR套件,則可以取得一個終身授權。 IronOCR套件以$999起的價格提供多台裝置的單價,是一個絕佳的價值選擇。 欲了解更多有關成本的資訊,請造訪IronOCR的網站。 點擊這個連結瞭解更多Iron Software產品。

請注意Tesseract和Microsoft OCR皆是其各自所有者的註冊商標。 本網站與Tesseract或Microsoft OCR無關,並未獲其認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供資訊用途,並反映撰寫時獲得的公開資訊。

常見問題

Tesseract 和 Microsoft OCR 在語言支援方面的比較如何?

Tesseract 支援超過 100 種語言,並提供廣泛的語言資料自訂選項,使其具高度通用性。Microsoft OCR 也透過 Azure Cognitive Services 提供多語言支援,允許透過雲端進行可擴展的語言處理。

哪個 OCR 工具提供更好的 C# 專案整合?

Microsoft OCR 可透過 Azure Cognitive Services 無縫整合至 C# 專案,提供基於雲端的可擴展性。Tesseract 可以使用 Tesseract.NET 包裝器進行整合。或者,IronOCR 提供簡易的 C# 專案整合,並包含為 .NET 開發者量身定制的額外功能。

using Microsoft OCR 的主要優勢是什麼?

Microsoft OCR 通過其基於雲端的 Azure Cognitive Services 系統,使用深度神經網路進行文字識別,提供高準確性、可擴展性和多語言支援。

是什麼讓 Tesseract OCR 適合自訂呢?

Tesseract OCR 是開源的,並提供廣泛的自訂選項,使開發者能夠根據各種專案需求進行調整。其允許進行自訂語言訓練和識別設置的微調。

與 Tesseract 和 Microsoft OCR 相比,IronOCR 如何增強 C# 專案?

IronOCR 提供簡便的整合、高準確性和多語言支援,具有高級功能如圖像預處理和 PDF 文字提取。它專為 .NET 應用程式的無縫使用設計,提供開發者直觀的接口。

選擇 C# 的 OCR 工具時應考慮哪些因素?

選擇 C# 的 OCR 工具時,需考慮如語言支援、整合便利性、自訂選項、可擴展性及具體專案要求等因素。Tesseract 適合自訂,Microsoft OCR 適合基於雲端的可擴展性,而 IronOCR 則適合於 .NET 的整合便利。

IronOCR 可以用於將圖像轉換成 C# 應用程式的文字嗎?

是的,IronOCR 可以用於將圖像轉換成 C# 應用程式的文字。它支持多種圖像格式並提供高準確的文字識別,是開發者的可靠之選。

Kannaopat Udonpant
軟體工程師
在成為軟體工程師之前,Kannapat在日本北海道大學完成了環境資源博士學位。在攻讀學位期間,Kannapat還成為車輛機器人實驗室的一員,該實驗室隸屬於生產工程系。在2022年,他憑藉C#技能加入了Iron Software的工程團隊,專注於IronPDF。Kannapat珍視他的工作,因為他能直接向撰寫大部分IronPDF程式碼的開發者學習。除了同儕學習,Kannapat還喜歡在Iron Software工作的社交方面。不寫程式碼或文件時,Kannapat通常在他的PS5上玩遊戲或重看The Last of Us。

Iron 支援團隊

我們線上24小時,每週5天。
聊天
電子郵件
給我打電話