如何在 C# 中使用 Tesseract OCR? IronOCR 的替代方案
想在 C# 應用程式中實現光學字元辨識嗎? 雖然 Google Tesseract 提供免費的 OCR 解決方案,但許多開發者都難以應對其複雜的設定、在真實文件上的有限準確性以及具有挑戰性的 C++ 互通性要求。 本綜合指南向您展示如何使用 IronOCR 增強的 Tesseract 實作(原生 C# 函式庫,可消除安裝難題,同時提供卓越的結果)達到 99.8-100% 的 OCR 準確率。
無論您是從掃描文件中提取文字、處理發票還是建立文件自動化系統,您都將學會如何在幾分鐘內而不是幾週內實現可用於生產的 OCR。
快速入門:使用 IronTesseract 進行單行 OCR
使用 IronOCR 最簡單的 API,幾秒鐘即可抓取文字。 這個範例展示如何透過一行程式碼呼叫 IronTesseract,向其提供圖像,並獲取識別出的文字——簡單直接,結果立竿見影。
立即開始使用 NuGet 建立 PDF 檔案:
使用 NuGet 套件管理器安裝 IronOCR
複製並運行這段程式碼。
string text = new IronTesseract().Read(new OcrInput("image.png")).Text;部署到您的生產環境進行測試
最小工作流程(5 個步驟)
- 透過 NuGet 套件管理器安裝增強型 Tesseract OCR 庫
- 配置影像預處理以獲得最佳文字辨識效果
- 處理多種文件格式,包括PDF和多幀TIFF
- 擷取具有字元級準確度指標的結構化數據
- 無需原生依賴即可跨平台部署
本文全面概述了 IronOCR 的 Tesseract C# 實現,重點介紹了其平台相容性、支援的格式以及高級處理能力。
如何使用最少的程式碼在 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 structureusing 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這段程式碼展示了 IronOCR 簡化 API 的強大功能。 IronTesseract類別為 Tesseract 5 提供了一個託管封裝,無需複雜的 C++ 互通。 OcrInput OcrInput支援載入多種影像格式和頁面,而可選的預處理方法( DeNoise()和Deskew() )可以顯著提高實際文件的辨識準確率。
除了基本的文字擷取之外, OcrResult物件還提供豐富的結構化數據,包括單字級置信度分數、字元位置和文件結構,從而實現可搜尋 PDF 建立和精確文字位置追蹤等高級功能。
Tesseract 和 IronOCR 在安裝上有哪些主要差異?
使用 Tesseract 引擎和 .NET 進行 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開發的比較情況如何?
使用 C# 連接 Google Tesseract
Tesseract 5 雖然功能強大,但對 Windows 開發人員來說卻帶來了巨大的挑戰。
最新版本需要使用 MinGW 進行交叉編譯,而 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掃描完全失敗
- 混合使用不同字體或版面時效能不佳
- 無法處理背景噪音或浮水印
.NET 專案中的 IronOCR Tesseract
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.Confidence: Overall accuracy percentage
// - result.Pages[0].Words: Word-level confidence scores
// - result.Blocks: Structured document layout analysisusing 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.Confidence: Overall accuracy percentage
// - result.Pages[0].Words: Word-level confidence scores
// - result.Blocks: Structured document layout analysis自動預處理過濾器可以處理常見的文件品質問題,否則這些問題需要人工幹預。 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 formatsusing 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這種統一的文檔載入方法消除了特定於格式的程式碼。 無論是處理掃描的 TIFF 檔案、數位 PDF 檔案或智慧型手機照片,同一個 API 都能處理所有場景。 OcrInput類別能夠智慧地管理內存,並且無論來源格式如何,都能提供一致的結果。
對於特殊場景,IronOCR 還支援從同一文件中讀取條碼和二維碼,從而能夠一次提取全面的文檔資料。
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.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 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 documentsusing 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.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 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這些優化措施證明了 IronOCR 已具備量產能力。 僅BlackListCharacters配置一項,在不需要特殊字元的情況下,即可將速度提高 20-30%。 快速語言包為大批量處理提供了極佳的平衡,在這種處理中,完美的準確性並非至關重要。
對於企業應用而言,IronOCR 的多線程支援能夠同時處理多個文檔,與單線程 Tesseract 相比,在現代多核心系統上可實現 4-8 倍的吞吐量提升。
Tesseract 和 IronOCR 的 API 設計有何不同?
在 .NET 中使用 Google Tesseract OCR
將原始 Tesseract 整合到 C# 應用程式中面臨兩種具有挑戰性的選擇:
-互通封裝器:通常過時、文件不完善且容易出現記憶體洩漏 -命令列執行:部署困難,受安全性原則限制,錯誤處理能力差。
這兩種方法在雲端環境、Web應用程式或跨平台部署中都無法可靠地運作。 缺乏合適的 .NET 整合意味著要花費更多時間與工具作鬥爭,而不是解決業務問題。
IronOCR Tesseract OCR 函式庫,適用於 .NET
IronOCR 提供了一個完全託管、直覺的 API,專為 .NET 開發人員設計:
最簡實現
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.Confidence: Overall accuracy percentage
// - result.Pages: Page-by-page breakdown
// - result.Paragraphs: Document structure
// - result.Words: Individual word details
// - result.Barcodes: Detected barcode valuesusing 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.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 文件為每個功能提供了詳細的範例。
經驗豐富的工程師提供的專業支援確保您不會在實施細節上遇到困難。 該程式庫會定期更新,在保持與最新 .NET 版本相容的同時,根據開發者的回饋添加新功能。
支援哪些平台和部署場景?
Google Tesseract + Interop for .NET
跨平台 Tesseract 部署需要針對特定平台進行建置和配置。
每個目標環境都需要不同的二進位檔案、執行時間依賴項和權限。 Docker容器需要仔細選擇基礎映像。 由於缺少 Visual C++ 運行時,Azure 部署經常失敗。 Linux相容性取決於具體的發行版和軟體包可用性。
IronOCR Tesseract .NET OCR庫
IronOCR 提供真正的"一次寫入,隨處部署"功能:
應用類型:
- 桌面應用程式(WPF、WinForms、控制台)
- Web 應用程式(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及以上 (包括.NET 5、6、7、8、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 typefacesusing 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;
// 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.)語言包系統支援超過 127 種語言,每種語言都針對特定的腳本和書寫系統進行了最佳化。 透過 NuGet 安裝可確保版本相容性,並簡化跨不同環境的部署。
除了基本的OCR功能外,IronOCR還提供哪些其他功能?
IronOCR 的功能遠不止基本的文字擷取,它還具備企業級功能:
-自動影像分析:根據影像特徵智慧配置處理方案 -建立可搜尋的PDF :將掃描文件轉換為完全可搜尋的PDF文件 -進階PDF OCR :在保留文件結構的同時提取文本 條碼和二維碼讀取:一次掃描即可偵測和解碼條碼。
- HTML匯出:根據OCR結果產生結構化HTML
- TIFF 轉 PDF 轉換:將多頁 TIFF 檔案轉換為可搜尋的 PDF 文件
- 支援多執行緒:同時處理多個文件
- 詳細結果分析:存取具有置信度分數的字元層級資料
OcrResult類別提供對已識別內容的精細訪問,從而實現複雜的後處理和驗證工作流程。
C# 開發應該選擇哪一種 OCR 解決方案?
Google Tesseract for C# OCR
選擇香草色 Tesseract 的情況:
參與學術或研究項目
- 處理完美掃描的文檔,開發時間不受限制
- 建立概念驗證應用程式 成本是唯一考慮因素。
要做好應對重大整合挑戰和持續維護需求的準備。
IronOCR Tesseract OCR 函式庫,適用於 .NET Framework 和 Core
IronOCR是以下情況的最佳選擇:
- 需要可靠性的生產應用
- 具有真實世界文檔品質的項目
- 跨平台部署
- 時間緊迫的開發計劃
- 需要專業支援的應用
該庫透過縮短開發時間和提高複雜文件的準確性來收回成本。
如何在 C# 專案中開始使用專業 OCR?
開始在 Visual Studio 專案中實現高精度 OCR:
Install-Package IronOcr
或直接下載 IronOCR .NET DLL進行手動安裝。
首先請參閱我們全面的入門指南,瀏覽程式碼範例,並在需要時獲得專業支援。
體驗專業 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 有哪些優點?
IronOCR 相較於傳統的 Tesseract 具有多項優勢,包括無需原生依賴項即可簡化部署、自動映像預處理以提高準確率以及託管式 .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;停用不必要的條碼掃描,以及選擇速度更快的語言模型,例如ocr.Language = OcrLanguage.EnglishFast; `。此外,還可以利用多執行緒功能來加快批次處理速度。
IronOCR支援哪些影像格式?
IronOCR 支援多種影像格式,包括 PDF、TIFF、JPEG 和 PNG。您可以使用OcrInput類,透過諸如input.LoadImage("photo.jpg")或input.LoadPdf("file.pdf")之類的方法載入圖片。這種廣泛的兼容性使得 IronOCR 能夠輕鬆地與不同的影像來源和格式整合。








