How to Tesseract OCR in C# Alternatives with IronOCR
想在您的 C# 應用程式中實作光學字元辨識功能嗎? 雖然 Google Tesseract 提供免費的 OCR 解決方案,但許多開發人員仍苦於其複雜的設定流程、在實際文件上的有限準確度,以及艱鉅的 C++ 互通性要求。 這份全面指南將向您展示如何透過 IronOCR 的增強版 Tesseract 實作,實現 99.8% 至 100% 的 OCR 準確度——這是一個原生 C# 程式庫,不僅免除了安裝的麻煩,更能提供卓越的成果。
無論您是從掃描文件中擷取文字、處理發票,還是建置文件自動化系統,您都將學會如何在數分鐘內(而非數週)實作可投入生產環境的 OCR 功能。
快速入門:使用 IronTesseract 進行單行 OCR 處理
using IronOCR 最簡便的 API,幾秒鐘內即可擷取文字。 此範例展示如何透過單行程式碼呼叫 IronTesseract,傳入一張圖片,即可獲得辨識出的文字——無需繁瑣步驟,直接呈現結果。
簡化工作流程(5 個步驟)
- 透過 NuGet 套件管理員安裝增強版的 Tesseract OCR 函式庫
- 設定影像預處理以獲得最佳文字辨識效果
- 支援多種文件格式,包括 PDF 及多幀 TIFF 檔案
- 以字元級精度的指標擷取結構化資料
- 無需原生依賴項即可進行跨平台部署
IronOCR 針對 C# 實作的 Tesseract 功能全面概覽,涵蓋平台相容性、支援格式及進階處理能力
如何以最少的程式碼在 C# 中從圖片中擷取文字?
以下範例展示如何僅透過幾行程式碼,在您的 .NET 應用程式中實作 OCR 功能。 與標準版 Tesseract 不同,此方法會自動處理影像預處理,即使面對掃描品質不佳的文件,也能提供精準的結果。
請使用 NuGet 套件管理員,將 IronOCR NuGet 套件安裝至您的 Visual Studio 解決方案中。
using IronOcr;
using System;
// Initialize IronTesseract for performing OCR (Optical Character Recognition)
var ocr = new IronTesseract
{
// Set the language for the OCR process to English
Language = OcrLanguage.English
};
// Create a new OCR input that can hold the images to be processed
using var input = new OcrInput();
// Specify the page indices to be processed from the TIFF image
var pageIndices = new int[] { 1, 2 };
// Load specific pages of the TIFF image into the OCR input object
// Perfect for processing large multi-page documents efficiently
input.LoadImageFrames(@"img\example.tiff", pageIndices);
// Optional pre-processing steps (uncomment as needed)
// input.DeNoise(); // Remove digital noise from scanned documents
// input.Deskew(); // Automatically straighten tilted scans
// Perform OCR on the provided input
OcrResult result = ocr.Read(input);
// Output the recognized text to the console
Console.WriteLine(result.Text);
// Note: The OcrResult object contains detailed information including:
// - Individual words with confidence scores
// - Character positions and bounding boxes
// - Paragraph and line structure
using IronOcr;
using System;
// Initialize IronTesseract for performing OCR (Optical Character Recognition)
var ocr = new IronTesseract
{
// Set the language for the OCR process to English
Language = OcrLanguage.English
};
// Create a new OCR input that can hold the images to be processed
using var input = new OcrInput();
// Specify the page indices to be processed from the TIFF image
var pageIndices = new int[] { 1, 2 };
// Load specific pages of the TIFF image into the OCR input object
// Perfect for processing large multi-page documents efficiently
input.LoadImageFrames(@"img\example.tiff", pageIndices);
// Optional pre-processing steps (uncomment as needed)
// input.DeNoise(); // Remove digital noise from scanned documents
// input.Deskew(); // Automatically straighten tilted scans
// Perform OCR on the provided input
OcrResult result = ocr.Read(input);
// Output the recognized text to the console
Console.WriteLine(result.Text);
// Note: The OcrResult object contains detailed information including:
// - Individual words with confidence scores
// - Character positions and bounding boxes
// - Paragraph and line structure
Imports IronOcr
Imports System
' Initialize IronTesseract for performing OCR (Optical Character Recognition)
Private ocr = New IronTesseract With {.Language = OcrLanguage.English}
' Create a new OCR input that can hold the images to be processed
Private input = New OcrInput()
' Specify the page indices to be processed from the TIFF image
Private pageIndices = New Integer() { 1, 2 }
' Load specific pages of the TIFF image into the OCR input object
' Perfect for processing large multi-page documents efficiently
input.LoadImageFrames("img\example.tiff", pageIndices)
' Optional pre-processing steps (uncomment as needed)
' input.DeNoise(); // Remove digital noise from scanned documents
' input.Deskew(); // Automatically straighten tilted scans
' Perform OCR on the provided input
Dim result As OcrResult = ocr.Read(input)
' Output the recognized text to the console
Console.WriteLine(result.Text)
' Note: The OcrResult object contains detailed information including:
' - Individual words with confidence scores
' - Character positions and bounding boxes
' - Paragraph and line structure
此程式碼展示了 IronOCR 簡化版 API 的強大功能。 IronTesseract 類別為 Tesseract 5 提供了一層受管封裝,無需進行複雜的 C++ 互通操作。 OcrInput 類別支援載入多種圖像格式與頁面,而可選的預處理方法(DeNoise() 和 Deskew())能顯著提升實際文件中的辨識準確度。
除了基本的文字擷取功能外,OcrResult 物件還提供豐富的結構化資料,包括單字層級的信心分數、字元位置及文件結構,從而實現可搜尋 PDF 建立與精確文字位置追蹤等進階功能。
Tesseract 與 IronOCR 在安裝方面有哪些主要差異?
在 .NET 中使用 Tesseract 引擎進行 OCR
在 C# 中進行傳統的 Tesseract 整合,需要管理 C++ 函式庫,這會帶來若干挑戰。
開發人員必須處理特定平台的二進位檔、確保 Visual C++ 執行階段環境已安裝,並處理 32/64 位元相容性問題。 安裝過程通常需要手動編譯 Tesseract 和 Leptonica 函式庫,特別是針對最新版本的 Tesseract 5,因其設計時並未考慮 Windows 環境的編譯需求。
在 Azure、Docker 或 Linux 環境中,由於權限與依賴項差異極大,跨平台部署會變得特別棘手。
IronOCR Tesseract for .NET
IronOCR 透過 NuGet 分發的單一受管 .NET 程式庫,消除了安裝的複雜性:
Install-Package IronOcr
無需原生 DLL、無需 C# 執行環境、無需平台專屬設定。 所有功能均以純受管程式碼形式運行,並具備自動依賴項解析功能。
此函式庫完全相容於:
- .NET Framework 4.6.2 及以上版本
- .NET Standard 2.0 及以上版本(包含 .NET 5、6、7、8、9 及 10)
- .NET Core 2.0 及以上版本
此方法可確保在 Windows、macOS、Linux、Azure、AWS Lambda、Docker 容器,甚至 Xamarin 行動應用程式中,都能保持一致的運作行為。
最新 OCR 引擎版本在 .NET 開發中的表現如何比較?
Google Tesseract with C
Tesseract 5 雖然功能強大,但對 Windows 開發者而言仍面臨重大挑戰。
最新版本需要使用 MinGW 進行交叉編譯,但此方式極少能產生可正常運作的 Windows 二進位檔。 GitHub 上免費的 C# 封裝程式往往比最新的 Tesseract 版本落後數年,因此缺少關鍵的改進與錯誤修正。 由於這些編譯障礙,開發人員經常不得不使用過時的 Tesseract 3.x 或 4.x 版本。
IronOCR Tesseract for .NET
IronOCR 內建專為 .NET 環境特別優化的自訂版 Tesseract 5 引擎。
此版本包含多項效能提升,例如原生多執行緒支援、自動影像預處理,以及針對大型文件的高記憶體效率處理。 定期更新可確保與最新 .NET 版本的相容性,同時維持向下相容性。
該函式庫還透過專用的 NuGet 套件提供廣泛的語言支援,讓您無需管理外部字典檔案,即可輕鬆為超過 127 種語言新增 OCR 功能。
Google Cloud OCR 比較
雖然 Google Cloud Vision OCR 具備高準確度,但它需要網路連線、會產生每次請求的費用,且對於敏感文件而言,會引發資料隱私的疑慮。 IronOCR 提供與本地端處理相媲美的準確度,使其成為需要資料安全性或離線功能的應用程式的理想選擇。
採用不同方法時,能達到何種程度的 OCR 準確度?
在 .NET 專案中使用 Google Tesseract
Raw Tesseract 擅長讀取高解析度且對齊完美的文字,但在處理真實世界的文件時卻顯得力不從心。
掃描頁面、照片或低解析度圖像若未經大量預處理,通常會產生亂碼輸出。 要達到可接受的準確度,通常需要使用 ImageMagick 或類似工具建立自訂的影像處理流程,這會為每種文件類型增加數週的開發時間。
常見的準確性問題包括:
- 傾斜文件上的誤讀字元
- 在低 DPI 掃描時完全失敗
- 混合使用不同字型或版面配置時,效能不佳
- 無法處理背景雜訊或浮水印
IronOCR Tesseract 在 .NET 專案中的應用
IronOCR 的增強型實作在無需手動預處理的情況下,針對典型商務文件可達到 99.8% 至 100% 的準確度:
using IronOcr;
using System;
// Create an instance of the IronTesseract class for OCR processing
var ocr = new IronTesseract();
// Create an OcrInput object to load and preprocess images
using var input = new OcrInput();
// Specify which pages to extract from multi-page documents
var pageIndices = new int[] { 1, 2 };
// Load specific frames from a TIFF file
// IronOCR automatically detects and handles various image formats
input.LoadImageFrames(@"img\example.tiff", pageIndices);
// Apply automatic image enhancement filters
// These filters dramatically improve accuracy on imperfect scans
input.DeNoise(); // Removes digital artifacts and speckles
input.Deskew(); // Corrects rotation up to 15 degrees
// Perform OCR with enhanced accuracy algorithms
OcrResult result = ocr.Read(input);
// Access the extracted text with confidence metrics
Console.WriteLine(result.Text);
// Additional accuracy features available:
// - result.Co/nfidence: Overall accuracy percentage
// - result.Pages[0].Words: Word-level confidence scores
// - result.Blocks: Structured document layout analysis
using IronOcr;
using System;
// Create an instance of the IronTesseract class for OCR processing
var ocr = new IronTesseract();
// Create an OcrInput object to load and preprocess images
using var input = new OcrInput();
// Specify which pages to extract from multi-page documents
var pageIndices = new int[] { 1, 2 };
// Load specific frames from a TIFF file
// IronOCR automatically detects and handles various image formats
input.LoadImageFrames(@"img\example.tiff", pageIndices);
// Apply automatic image enhancement filters
// These filters dramatically improve accuracy on imperfect scans
input.DeNoise(); // Removes digital artifacts and speckles
input.Deskew(); // Corrects rotation up to 15 degrees
// Perform OCR with enhanced accuracy algorithms
OcrResult result = ocr.Read(input);
// Access the extracted text with confidence metrics
Console.WriteLine(result.Text);
// Additional accuracy features available:
// - result.Co/nfidence: Overall accuracy percentage
// - result.Pages[0].Words: Word-level confidence scores
// - result.Blocks: Structured document layout analysis
Imports IronOcr
Imports System
' Create an instance of the IronTesseract class for OCR processing
Dim ocr As New IronTesseract()
' Create an OcrInput object to load and preprocess images
Using input As New OcrInput()
' Specify which pages to extract from multi-page documents
Dim pageIndices As Integer() = {1, 2}
' Load specific frames from a TIFF file
' IronOCR automatically detects and handles various image formats
input.LoadImageFrames("img\example.tiff", pageIndices)
' Apply automatic image enhancement filters
' These filters dramatically improve accuracy on imperfect scans
input.DeNoise() ' Removes digital artifacts and speckles
input.Deskew() ' Corrects rotation up to 15 degrees
' Perform OCR with enhanced accuracy algorithms
Dim result As OcrResult = ocr.Read(input)
' Access the extracted text with confidence metrics
Console.WriteLine(result.Text)
' Additional accuracy features available:
' - result.Confidence: Overall accuracy percentage
' - result.Pages(0).Words: Word-level confidence scores
' - result.Blocks: Structured document layout analysis
End Using
自動預處理篩選器可處理常見的文件品質問題,否則這些問題將需要人工介入處理。 DeNoise() 方法可消除掃描產生的數位雜訊,而 Deskew() 則能修正文件旋轉角度——這兩者對於維持高準確度皆至關重要。
OCR 處理支援哪些圖像格式與來源?
.NET 中的 Google Tesseract
原生 Tesseract 僅接受 Leptonica PIX 格式——這是一種非託管 C++ 指標,在 C# 中難以處理。
將 .NET 影像轉換為 PIX 格式時,需謹慎管理記憶體以防止記憶體洩漏。 若要支援 PDF 及多頁 TIFF 檔案,則需額外安裝其他函式庫,且這些函式庫本身可能存在相容性問題。 許多實作方案在基本格式轉換方面存在困難,導致實際應用受限。
IronOCR 影像相容性
IronOCR 提供全面的格式支援與自動轉換功能:
- PDF 文件(包括受密碼保護的文件)
- 多幀 TIFF 檔案
- 標準格式:JPEG、PNG、GIF、BMP
- 進階格式:JPEG2000、WBMP
- .NET 類型:
System.Drawing.Image,System.Drawing.Bitmap - 資料來源:串流、位元組陣列、檔案路徑
- 直接掃描器整合
全面格式支援範例
using IronOcr;
using System;
// Initialize IronTesseract for OCR operations
var ocr = new IronTesseract();
// Create an OcrInput container for multiple sources
using var input = new OcrInput();
// Load password-protected PDFs seamlessly
// IronOCR handles PDF rendering internally
input.LoadPdf("example.pdf", "password");
// Process specific pages from multi-page TIFFs
// Perfect for batch document processing
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames("multi-frame.tiff", pageIndices);
// Add individual images in any common format
// Automatic format detection and conversion
input.LoadImage("image1.png");
input.LoadImage("image2.jpeg");
// Process all loaded content in a single operation
// Results maintain document structure and ordering
var result = ocr.Read(input);
// Extract text while preserving document layout
Console.WriteLine(result.Text);
// Advanced features for complex documents:
// - Extract images from specific PDF pages
// - Process only certain regions of images
// - Maintain reading order across mixed formats
using IronOcr;
using System;
// Initialize IronTesseract for OCR operations
var ocr = new IronTesseract();
// Create an OcrInput container for multiple sources
using var input = new OcrInput();
// Load password-protected PDFs seamlessly
// IronOCR handles PDF rendering internally
input.LoadPdf("example.pdf", "password");
// Process specific pages from multi-page TIFFs
// Perfect for batch document processing
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames("multi-frame.tiff", pageIndices);
// Add individual images in any common format
// Automatic format detection and conversion
input.LoadImage("image1.png");
input.LoadImage("image2.jpeg");
// Process all loaded content in a single operation
// Results maintain document structure and ordering
var result = ocr.Read(input);
// Extract text while preserving document layout
Console.WriteLine(result.Text);
// Advanced features for complex documents:
// - Extract images from specific PDF pages
// - Process only certain regions of images
// - Maintain reading order across mixed formats
Imports IronOcr
Imports System
' Initialize IronTesseract for OCR operations
Private ocr = New IronTesseract()
' Create an OcrInput container for multiple sources
Private input = New OcrInput()
' Load password-protected PDFs seamlessly
' IronOCR handles PDF rendering internally
input.LoadPdf("example.pdf", "password")
' Process specific pages from multi-page TIFFs
' Perfect for batch document processing
Dim pageIndices = New Integer() { 1, 2 }
input.LoadImageFrames("multi-frame.tiff", pageIndices)
' Add individual images in any common format
' Automatic format detection and conversion
input.LoadImage("image1.png")
input.LoadImage("image2.jpeg")
' Process all loaded content in a single operation
' Results maintain document structure and ordering
Dim result = ocr.Read(input)
' Extract text while preserving document layout
Console.WriteLine(result.Text)
' Advanced features for complex documents:
' - Extract images from specific PDF pages
' - Process only certain regions of images
' - Maintain reading order across mixed formats
這種統一的文件載入方式,可消除特定於格式之的程式碼。 無論處理掃描的 TIFF 檔案、數位 PDF 檔案,還是智慧型手機照片,同一套 API 皆能處理所有情境。 OcrInput 類別能智慧地管理記憶體,並無論來源格式為何,皆能提供一致的結果。
針對特殊情境,IronOCR 亦支援從同一份文件中讀取 BARCODE 與 QR 碼,實現單次處理即可完成全面的文件資料擷取。
在實際應用中,OCR 的表現如何?
免費 Google Tesseract 效能
Vanilla Tesseract 在處理與其訓練資料相符的預處理高解析度影像時,可提供令人滿意的速度。
然而,實際表現往往令人失望。 當 Tesseract 難以處理影像品質不佳的情況時,處理單一頁掃描文件可能需要 10 至 30 秒。 單執行緒架構會成為批次處理的瓶頸,且處理大型圖片時,記憶體使用量可能會急遽增加。
IronOCR Tesseract 程式庫效能
IronOCR 針對生產環境工作負載實施了智慧型效能優化:
using IronOcr;
using System;
// Configure IronTesseract for optimal performance
var ocr = new IronTesseract();
// Performance optimization: disable unnecessary character recognition
// Speeds up processing by 20-30% when special characters aren't needed
ocr.Co/nfiguration.BlackListCharacters = "~`$#^*_}{][|\\@¢©«»°±·×-–—''""•…′″€™←↑→↓↔⇄⇒∅∼≅≈≠≤≥≪≫⌁⌘○◔◑◕●";
// Use automatic page segmentation for faster processing
// Adapts to document layout without manual configuration
ocr.Co/nfiguration.PageSegmentationMode = TesseractPageSegmentationMode.Auto;
// Disable barcode scanning when not needed
// Eliminates unnecessary processing overhead
ocr.Co/nfiguration.ReadBarCodes = false;
// Switch to fast language pack for speed-critical applications
// Trades minimal accuracy for 40% performance improvement
ocr.Language = OcrLanguage.EnglishFast;
// Load and process documents efficiently
using var input = new OcrInput();
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageIndices);
// Multi-threaded processing utilizes all CPU cores
// Automatically scales based on system capabilities
var result = ocr.Read(input);
Console.WriteLine(result.Text);
// Performance monitoring capabilities:
// - result.TimeToRead: Processing duration
// - result.InputDetails: Image analysis metrics
// - Memory-efficient streaming for large documents
using IronOcr;
using System;
// Configure IronTesseract for optimal performance
var ocr = new IronTesseract();
// Performance optimization: disable unnecessary character recognition
// Speeds up processing by 20-30% when special characters aren't needed
ocr.Co/nfiguration.BlackListCharacters = "~`$#^*_}{][|\\@¢©«»°±·×-–—''""•…′″€™←↑→↓↔⇄⇒∅∼≅≈≠≤≥≪≫⌁⌘○◔◑◕●";
// Use automatic page segmentation for faster processing
// Adapts to document layout without manual configuration
ocr.Co/nfiguration.PageSegmentationMode = TesseractPageSegmentationMode.Auto;
// Disable barcode scanning when not needed
// Eliminates unnecessary processing overhead
ocr.Co/nfiguration.ReadBarCodes = false;
// Switch to fast language pack for speed-critical applications
// Trades minimal accuracy for 40% performance improvement
ocr.Language = OcrLanguage.EnglishFast;
// Load and process documents efficiently
using var input = new OcrInput();
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageIndices);
// Multi-threaded processing utilizes all CPU cores
// Automatically scales based on system capabilities
var result = ocr.Read(input);
Console.WriteLine(result.Text);
// Performance monitoring capabilities:
// - result.TimeToRead: Processing duration
// - result.InputDetails: Image analysis metrics
// - Memory-efficient streaming for large documents
Imports IronOcr
Imports System
' Configure IronTesseract for optimal performance
Dim ocr As New IronTesseract()
' Performance optimization: disable unnecessary character recognition
' Speeds up processing by 20-30% when special characters aren't needed
ocr.Configuration.BlackListCharacters = "~`$#^*_}{][|\@¢©«»°±·×-–—''""•…′″€™←↑→↓↔⇄⇒∅∼≅≈≠≤≥≪≫⌁⌘○◔◑◕●"
' Use automatic page segmentation for faster processing
' Adapts to document layout without manual configuration
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto
' Disable barcode scanning when not needed
' Eliminates unnecessary processing overhead
ocr.Configuration.ReadBarCodes = False
' Switch to fast language pack for speed-critical applications
' Trades minimal accuracy for 40% performance improvement
ocr.Language = OcrLanguage.EnglishFast
' Load and process documents efficiently
Using input As New OcrInput()
Dim pageIndices As Integer() = {1, 2}
input.LoadImageFrames("img\Potter.tiff", pageIndices)
' Multi-threaded processing utilizes all CPU cores
' Automatically scales based on system capabilities
Dim result = ocr.Read(input)
Console.WriteLine(result.Text)
' Performance monitoring capabilities:
' - result.TimeToRead: Processing duration
' - result.InputDetails: Image analysis metrics
' - Memory-efficient streaming for large documents
End Using
這些優化功能彰顯了 IronOCR 具備投入生產環境的設計。 當不需要特殊字元時,僅使用 BlackListCharacters 配置即可將速度提升 20-30%。 快速語言套件在處理大量資料時,能提供絕佳的平衡,尤其當完美準確性並非關鍵考量時。
針對 Enterprise 級應用,IronOCR 的多執行緒支援功能可同時處理多份文件,相較於單執行緒的 Tesseract,在現代多核心系統上能實現 4 至 8 倍的處理效能提升。
Tesseract 與 IronOCR 的 API 設計有何不同?
.NET 中的 Google Tesseract OCR
將原始 Tesseract 整合至 C# 應用程式時,有兩種具挑戰性的選項:
- 互通性封裝函式庫:通常過時、文件不完善,且容易發生記憶體洩漏
- 命令列執行:難以部署、受安全政策阻擋、錯誤處理不佳
這兩種方法在雲端環境、網頁應用程式或跨平台部署中均無法可靠運作。 缺乏適當的 .NET 整合,意味著必須花費更多時間與工具搏鬥,而非解決業務問題。
IronOCR Tesseract OCR .NET 程式庫
IronOCR 提供專為 .NET 開發人員設計的、完全受管且直觀的 API:
最簡單的實作方式
using IronOcr;
// Initialize the OCR engine with full IntelliSense support
var ocr = new IronTesseract();
// Process an image with automatic format detection
// Handles JPEG, PNG, TIFF, PDF, and more
var result = ocr.Read("img.png");
// Extract text with confidence metrics
string extractedText = result.Text;
Console.WriteLine(extractedText);
// Rich API provides detailed results:
// - result.Co/nfidence: Overall accuracy percentage
// - result.Pages: Page-by-page breakdown
// - result.Paragraphs: Document structure
// - result.Words: Individual word details
// - result.Barcodes: Detected barcode values
using IronOcr;
// Initialize the OCR engine with full IntelliSense support
var ocr = new IronTesseract();
// Process an image with automatic format detection
// Handles JPEG, PNG, TIFF, PDF, and more
var result = ocr.Read("img.png");
// Extract text with confidence metrics
string extractedText = result.Text;
Console.WriteLine(extractedText);
// Rich API provides detailed results:
// - result.Co/nfidence: Overall accuracy percentage
// - result.Pages: Page-by-page breakdown
// - result.Paragraphs: Document structure
// - result.Words: Individual word details
// - result.Barcodes: Detected barcode values
Imports IronOcr
' Initialize the OCR engine with full IntelliSense support
Dim ocr As New IronTesseract()
' Process an image with automatic format detection
' Handles JPEG, PNG, TIFF, PDF, and more
Dim result = ocr.Read("img.png")
' Extract text with confidence metrics
Dim extractedText As String = result.Text
Console.WriteLine(extractedText)
' Rich API provides detailed results:
' - result.Confidence: Overall accuracy percentage
' - result.Pages: Page-by-page breakdown
' - result.Paragraphs: Document structure
' - result.Words: Individual word details
' - result.Barcodes: Detected barcode values
此精簡版 API 消除了傳統 Tesseract 整合的複雜性。 每個方法皆附有完整的 XML 文件,讓您能直接在 IDE 中輕鬆探索各項功能。詳盡的 API 文件針對每項功能皆提供詳細範例。
經驗豐富的工程師提供Professional支援,確保您在實作細節上絕不會受阻。 該函式庫會定期更新,在維持與最新 .NET 版本相容的同時,也會根據開發者的回饋新增功能。
支援哪些平台與部署情境?
Google Tesseract + Interop for .NET
跨平台的 Tesseract 部署需要針對特定平台進行編譯與配置。
每個目標環境都需要不同的二進位檔、執行時依賴項及權限。 Docker 容器需要謹慎選擇基礎映像。 Azure 部署常因缺少 Visual C++ 執行階段套件而失敗。 Linux 相容性取決於具體的發行版及套件的可用性。
IronOCR Tesseract .NET OCR 程式庫
IronOCR 提供真正的"寫一次,部署到任何地方"功能:
應用類型:
- 桌面應用程式(WPF、WinForms、Console)
- 網頁應用程式(ASP.NET Core、Blazor)
- 雲端服務(Azure Functions、AWS Lambda)
- 行動應用程式(透過 Xamarin)
- 微服務(Docker、Kubernetes)
平台支援:
- Windows(7、8、10、11、伺服器版本)
- macOS(Intel 及 Apple Silicon)
- Linux(Ubuntu、Debian、CentOS、Alpine)
- Docker 容器(官方基礎映像)
- 雲端平台(Azure、AWS、Google Cloud)
.NET 相容性:
.NET Framework 4.6.2及以上.NET Standard 2.0及以上(包含9及10).NET Core 2.0及以上- Mono 框架
- Xamarin.Mac
該函式庫在內部處理平台差異,確保在所有環境中皆能提供一致的結果。 部署指南涵蓋特定情境,包括容器化、無伺服器函式及高可用性配置。
多語言 OCR 功能如何比較?
Google Tesseract 語言支援
在原始 Tesseract 中管理語言需要下載並維護 tessdata 檔案——所有語言的檔案總量約為 4GB。
資料夾結構必須精確無誤,環境變數需正確設定,且路徑在執行時必須可存取。語言切換需要存取檔案系統,這使得在受限環境中的部署變得複雜。 Tesseract 二進位檔與語言檔之間的版本不符會導致難以理解的錯誤。
IronOCR 語言管理
IronOCR 透過 NuGet 套件管理徹底革新了語言支援:
阿拉伯文 OCR 範例
using IronOcr;
// Configure IronTesseract for Arabic text recognition
var ocr = new IronTesseract
{
// Set primary language to Arabic
// Automatically handles right-to-left text
Language = OcrLanguage.Arabic
};
// Load Arabic documents for processing
using var input = new OcrInput();
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames("img/arabic.gif", pageIndices);
// IronOCR includes specialized preprocessing for Arabic scripts
// Handles cursive text and diacritical marks automatically
// Perform OCR with language-specific optimizations
var result = ocr.Read(input);
// Save results with proper Unicode encoding
// Preserves Arabic text formatting and direction
result.SaveAsTextFile("arabic.txt");
// Advanced Arabic features:
// - Mixed Arabic/English document support
// - Automatic number conversion (Eastern/Western Arabic)
// - Font-specific optimization for common Arabic typefaces
using IronOcr;
// Configure IronTesseract for Arabic text recognition
var ocr = new IronTesseract
{
// Set primary language to Arabic
// Automatically handles right-to-left text
Language = OcrLanguage.Arabic
};
// Load Arabic documents for processing
using var input = new OcrInput();
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames("img/arabic.gif", pageIndices);
// IronOCR includes specialized preprocessing for Arabic scripts
// Handles cursive text and diacritical marks automatically
// Perform OCR with language-specific optimizations
var result = ocr.Read(input);
// Save results with proper Unicode encoding
// Preserves Arabic text formatting and direction
result.SaveAsTextFile("arabic.txt");
// Advanced Arabic features:
// - Mixed Arabic/English document support
// - Automatic number conversion (Eastern/Western Arabic)
// - Font-specific optimization for common Arabic typefaces
Imports IronOcr
' Configure IronTesseract for Arabic text recognition
Private ocr = New IronTesseract With {.Language = OcrLanguage.Arabic}
' Load Arabic documents for processing
Private input = New OcrInput()
Private pageIndices = New Integer() { 1, 2 }
input.LoadImageFrames("img/arabic.gif", pageIndices)
' IronOCR includes specialized preprocessing for Arabic scripts
' Handles cursive text and diacritical marks automatically
' Perform OCR with language-specific optimizations
Dim result = ocr.Read(input)
' Save results with proper Unicode encoding
' Preserves Arabic text formatting and direction
result.SaveAsTextFile("arabic.txt")
' Advanced Arabic features:
' - Mixed Arabic/English document support
' - Automatic number conversion (Eastern/Western Arabic)
' - Font-specific optimization for common Arabic typefaces
多語言文件處理
using IronOcr;
// Install language packs via NuGet:
// PM> Install-Package IronOcr.Languages.ChineseSimplified
// Configure multi-language OCR
var ocr = new IronTesseract();
// Set primary language for majority content
ocr.Language = OcrLanguage.ChineseSimplified;
// Add secondary language for mixed content
// Perfect for documents with Chinese text and English metadata
ocr.AddSecondaryLanguage(OcrLanguage.English);
// Process multi-language PDFs efficiently
using var input = new OcrInput();
input.LoadPdf("multi-language.pdf");
// IronOCR automatically detects and switches between languages
// Maintains high accuracy across language boundaries
var result = ocr.Read(input);
// Export preserves all languages correctly
result.SaveAsTextFile("results.txt");
// Supported scenarios:
// - Technical documents with English terms in foreign text
// - Multilingual forms and applications
// - International business documents
// - Mixed-script content (Latin, CJK, Arabic, etc.)
using IronOcr;
// Install language packs via NuGet:
// PM> Install-Package IronOcr.Languages.ChineseSimplified
// Configure multi-language OCR
var ocr = new IronTesseract();
// Set primary language for majority content
ocr.Language = OcrLanguage.ChineseSimplified;
// Add secondary language for mixed content
// Perfect for documents with Chinese text and English metadata
ocr.AddSecondaryLanguage(OcrLanguage.English);
// Process multi-language PDFs efficiently
using var input = new OcrInput();
input.LoadPdf("multi-language.pdf");
// IronOCR automatically detects and switches between languages
// Maintains high accuracy across language boundaries
var result = ocr.Read(input);
// Export preserves all languages correctly
result.SaveAsTextFile("results.txt");
// Supported scenarios:
// - Technical documents with English terms in foreign text
// - Multilingual forms and applications
// - International business documents
// - Mixed-script content (Latin, CJK, Arabic, etc.)
Imports IronOcr
' Install language packs via NuGet:
' PM> Install-Package IronOcr.Languages.ChineseSimplified
' Configure multi-language OCR
Private ocr = New IronTesseract()
' Set primary language for majority content
ocr.Language = OcrLanguage.ChineseSimplified
' Add secondary language for mixed content
' Perfect for documents with Chinese text and English metadata
ocr.AddSecondaryLanguage(OcrLanguage.English)
' Process multi-language PDFs efficiently
Dim input = New OcrInput()
input.LoadPdf("multi-language.pdf")
' IronOCR automatically detects and switches between languages
' Maintains high accuracy across language boundaries
Dim result = ocr.Read(input)
' Export preserves all languages correctly
result.SaveAsTextFile("results.txt")
' Supported scenarios:
' - Technical documents with English terms in foreign text
' - Multilingual forms and applications
' - International business documents
' - Mixed-script content (Latin, CJK, Arabic, etc.)
語言套件系統支援超過 127 種語言,每種語言皆針對特定文字編碼與書寫系統進行了最佳化。 透過 NuGet 進行安裝,可確保版本相容性,並簡化跨不同環境的部署流程。
IronOCR 除了基本 OCR 功能外,還提供了哪些額外功能?
IronOCR 具備 Enterprise 級功能,其應用範圍遠超出基本的文字擷取:
- 自動影像分析:根據影像特性智能地配置處理流程
- 可搜尋 PDF 建立:將掃描文件轉換為可完全搜尋的 PDF 檔案。 將
true作為第二個參數傳遞給SaveAsSearchablePdf(),以對輸出套用主動 OCR 濾鏡(新增於 v2025.5.11) - 進階 PDF OCR:在保留文件結構的同時擷取文字
- BarCode 與 QR 碼讀取:在單次處理中偵測並解碼 BarCode
- HTML 匯出:根據 OCR 結果產生結構化 HTML
- TIFF 轉 PDF:將多頁 TIFF 檔案轉換為可搜尋的 PDF 檔案
- 英文手寫 OCR:內建的英文手寫辨識功能,於 v2025.11.31 版本新增 — 相較於原始的 Tesseract,在處理手寫表單與筆記時具備顯著的差異化優勢
- 方向偵測:
DetectPageOrientation()支援四種OrientationDetectionMode值 —ExtremeDetailed—— 用於控制精準度與速度之間的權衡(新增於 v2025.8.6) - 多執行緒支援:可同時處理多個文件
- 詳細結果分析:可存取附帶信心分數的字元級資料
Scale() 與 EnhanceResolution() 因 v2025.12.3 版本中的已知問題,無法與 SaveAsSearchablePdf() 相容。所有其他篩選器在可搜尋 PDF/A 輸出時皆能正常運作。
OcrResult 類別提供對識別內容的細粒度存取,可實現複雜的後處理與驗證工作流程。
進行 C# 開發時,您該選擇哪種 OCR 解決方案?
Google Tesseract for C# OCR
在以下情況下請選擇標準版 Tesseract:
- 從事學術或研究專案
- 處理完美掃描的文件,且開發時間不受限制
- 建置概念驗證應用程式
- 成本是唯一的考量因素
請做好應對重大整合挑戰及持續維護需求的準備。
IronOCR Tesseract OCR 程式庫(適用於 .NET Framework 及 .NET Core)
IronOCR 是以下情況的最佳選擇:
- 需要可靠性的生產環境應用程式
- 具備真實世界文件品質的專案
- 跨平台部署
- 時間緊迫的開發時程
- 需要專業支援的應用程式
該函式庫能透過縮短開發時間,以及在處理複雜文件時展現的卓越準確性,為使用者帶來實質效益。
如何在您的 C# 專案中開始使用 Professional OCR?
開始在您的 Visual Studio 專案中實作高精準度的 OCR:
Install-Package IronOcr
或直接下載 IronOCR .NET DLL 進行手動安裝。
請從我們的完整入門指南開始,探索程式碼範例,並在需要時利用Professional支援。
親身體驗 Professional OCR 帶來的差異——立即開始免費試用,加入超過 10,000 家企業的行列,在文件處理工作流程中實現 99.8% 以上的準確度。
Iron Software 的 OCR 技術深受全球《財星》500 大企業及政府機構信賴,廣泛應用於關鍵任務的文件處理
常見問題
如何在 C# 應用程式中實作 Tesseract OCR?
若要在 C# 應用程式中實作 Tesseract OCR,可使用 IronOCR 中的 IronTesseract 類別。透過 NuGet 執行 Install-Package IronOcr 指令進行安裝,接著使用 using IronOcr; 加入命名空間。透過 var ocr = new IronTesseract(); 建立 OCR 引擎實例,並使用 var result = ocr.Read("image.png"); 從圖片中擷取文字。
相較於傳統的 Tesseract,使用 IronOCR 有什麼好處?
相較於傳統的 Tesseract,IronOCR 具備多項優勢,包括無需原生依賴項的簡化部署、可提升精準度的自動影像預處理,以及受管 .NET 整合。它提供 PDF 及多語言支援等功能,並可透過 NuGet 輕鬆安裝,避免了原生 Tesseract 所需的複雜 C++ 互通操作。
如何在 C# 專案中提升 OCR 準確度?
若要在 C# 專案中提升 OCR 準確度,請使用 IronOCR 的自動影像增強功能。透過 input.DeNoise() 和 input.Deskew() 等方法對影像進行預處理,可有效降低雜訊並修正傾斜。此外,請選擇正確的語言設定,並利用 OcrResult.Confidence 中的信心指標來驗證準確度。
我可以使用 C# 對 PDF 文件執行 OCR 嗎?
是的,透過 IronOCR 的 OcrInput 類別,您可以對 PDF 文件執行 OCR 處理。使用 input.LoadPdf("file.pdf", "password") 載入 PDF 文件,並透過 var result = ocr.Read(input); 進行處理。這讓您能夠直接在 C# 應用程式中擷取文字並建立可搜尋的 PDF 文件。
如何處理單一 OCR 文件中的多種語言?
IronOCR 支援在單一文件中處理多種語言。請使用 ocr.Language = OcrLanguage.English; 設定主要語言,並透過 ocr.AddSecondaryLanguage(OcrLanguage.Spanish); 新增次要語言。此靈活性對於包含混合語言或技術術語的文件特別有益。
哪些平台支援 IronOCR?
IronOCR 支援多種平台,包括 .NET Framework 4.6.2 以上、.NET Core 2.0 以上、.NET 5-10 以及 .NET Standard 2.0 以上。它可在 Windows、macOS 和 Linux 系統上運行,亦支援 Docker 容器、Azure Functions、AWS Lambda 以及 Xamarin 行動應用程式,並在不同環境中提供一致的效能表現。
如何在 C# 中優化 OCR 處理的效能?
若要在 C# 中優化 OCR 處理效能,請善用 IronOCR 的功能,例如透過 ocr.Configuration.ReadBarCodes = false; 停用不必要的 BarCode 掃描,並選用 ocr.Language = OcrLanguage.Fast; 等更快速的語言模型。此外,亦可運用多執行緒功能以加速批次處理。
IronOCR 支援哪些圖像格式?
IronOCR 支援多種影像格式,包括 PDF、TIFF、JPEG 和 PNG。請使用 OcrInput 類別透過 input.LoadImage("photo.jpg") 或 input.LoadPdf("file.pdf") 等方法載入影像。這種廣泛的相容性,讓您能輕鬆整合各種影像來源與格式。

