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

IronOCR 與 Iris OCR:工程團隊應該選擇哪種 OCR 解決方案?

Azure Computer Vision的Read API每1000筆交易收費1.00美元,需訂閱Azure以配置Cognitive Services資源,且每次OCR呼叫都需經過三步非同步過程:將您的文件序列化至AnalyzeAsync,然後遍歷巢狀的區塊和行以重建文字。 那是最低可行的路徑 — 且多頁PDF的每頁都算作單獨的交易。 IronOCR將這一切簡化為一個同步方法呼叫,完全在您的基礎設施內運行,且不對每筆交易進行計量。

了解Azure Computer Vision

Azure Computer Vision是由微軟提供的基於雲的認知服務,通過兩個主要的API提供OCR:即用於影像的Image Analysis API (使用VisualFeatures.Read) 和用於PDF的Azure Form Recognizer的DocumentAnalysisClient。 這兩者都是在Azure資料中心託管的基於REST的服務,分別通過Azure.AI.FormRecognizer.DocumentAnalysis NuGet包進入。

關鍵架構特徵:

  • 雲先行,永遠如此:每次OCR操作都將文件資料通過HTTPS傳輸到微軟管理的伺服器。 沒有本地處理模式。
  • 訂閱前提:團隊必須建立一個Azure帳戶,配置一個Cognitive Services資源,獲得一個端點URL,並生成一個API密鑰才可撰寫單行OCR程式碼。
  • 按頁交易計費:Read API按圖像或PDF頁收費。 50頁的PDF等於50次交易。 價格從每1000次交易1.00美元起,首百萬次,隨著更高的交易量下降到0.60和0.40美元。
  • 免費層上限:每月5000筆交易的免費層 — 足夠用於原型設計,不適用於生產工作負載。
  • 拆分PDF服務:基本圖像OCR使用ImageAnalysisClient。 完整的PDF處理需要一個單獨的服務 — Form Recognizer的DocumentAnalysisClient — 有其自己的端點和配置。
  • 僅非同步設計:所有Read API呼叫都為非同步。 本地OCR可以同步返回結果; 雲端來回則不能。 鏈中的每個呼叫方法都必須是async
  • 速度限制:S1層上限為每秒10次交易。 大批量作業需要排隊邏輯或層級升級以處理。
  • 錯誤面積:生產程式碼必須處理 HTTP 429 速率限制響應,5xx Azure 服務錯誤,網路超時,身份驗證失敗,和端點可用性 — 每個需要單獨的重試邏輯。

非同步輪詢模式

Read API的非同步要求導致結構性程式碼後果。 使用await; 通過Form Recognizer進行的PDF處理需要UpdateStatusAsync進行自定義輪詢以實現真正的非同步行為。 結果層次結構然後要求通過巢狀迴圈遍歷塊、行和詞語:

// Azure Computer Vision: image OCR
// Requires: Azure subscription + Cognitive Services resource + endpoint + API key
using Azure;
using Azure.AI.Vision.ImageAnalysis;

public class AzureOcrService
{
    private readonly ImageAnalysisClient _client;

    public AzureOcrService(string endpoint, string apiKey)
    {
        // Endpoint and key provisioned in Azure portal
        _client = new ImageAnalysisClient(
            new Uri(endpoint),
            new AzureKeyCredential(apiKey));
    }

    public async Task<string> ExtractTextAsync(string imagePath)
    {
        // Document is uploaded to Microsoft Azure
        using var stream = File.OpenRead(imagePath);
        var imageData = BinaryData.FromStream(stream);

        var result = await _client.AnalyzeAsync(
            imageData,
            VisualFeatures.Read);

        var text = new StringBuilder();
        foreach (var block in result.Value.Read.Blocks)
        {
            foreach (var line in block.Lines)
            {
                text.AppendLine(line.Text);
            }
        }

        return text.ToString();
    }
}
// Azure Computer Vision: image OCR
// Requires: Azure subscription + Cognitive Services resource + endpoint + API key
using Azure;
using Azure.AI.Vision.ImageAnalysis;

public class AzureOcrService
{
    private readonly ImageAnalysisClient _client;

    public AzureOcrService(string endpoint, string apiKey)
    {
        // Endpoint and key provisioned in Azure portal
        _client = new ImageAnalysisClient(
            new Uri(endpoint),
            new AzureKeyCredential(apiKey));
    }

    public async Task<string> ExtractTextAsync(string imagePath)
    {
        // Document is uploaded to Microsoft Azure
        using var stream = File.OpenRead(imagePath);
        var imageData = BinaryData.FromStream(stream);

        var result = await _client.AnalyzeAsync(
            imageData,
            VisualFeatures.Read);

        var text = new StringBuilder();
        foreach (var block in result.Value.Read.Blocks)
        {
            foreach (var line in block.Lines)
            {
                text.AppendLine(line.Text);
            }
        }

        return text.ToString();
    }
}
Imports Azure
Imports Azure.AI.Vision.ImageAnalysis
Imports System.IO
Imports System.Text
Imports System.Threading.Tasks

Public Class AzureOcrService
    Private ReadOnly _client As ImageAnalysisClient

    Public Sub New(endpoint As String, apiKey As String)
        ' Endpoint and key provisioned in Azure portal
        _client = New ImageAnalysisClient(
            New Uri(endpoint),
            New AzureKeyCredential(apiKey))
    End Sub

    Public Async Function ExtractTextAsync(imagePath As String) As Task(Of String)
        ' Document is uploaded to Microsoft Azure
        Using stream = File.OpenRead(imagePath)
            Dim imageData = BinaryData.FromStream(stream)

            Dim result = Await _client.AnalyzeAsync(
                imageData,
                VisualFeatures.Read)

            Dim text = New StringBuilder()
            For Each block In result.Value.Read.Blocks
                For Each line In block.Lines
                    text.AppendLine(line.Text)
                Next
            Next

            Return text.ToString()
        End Using
    End Function
End Class
$vbLabelText   $csharpLabel

PDF處理進一步增加了複雜性 — 一個單獨的.Text

理解 IronOCR

IronOCR是.NET的商業本地OCR程式庫,以單個NuGet包形式交付。 它封裝了一個優化的Tesseract 5引擎,具有自動預處理、本地PDF支持和需要無雲憑證、無端點配置、無非同步管道的同步API。

關鍵特徵:

  • 單NuGet部署dotnet add package IronOcr 安裝所有,包含OCR引擎、本機二進制和英語語言資料。 無需tessdata文件夾,無需單獨的本機庫下載。
  • 永久授權:$999 Lite / $1,499 Plus / $2,999 Professional / $5,999 Unlimited — 一次購買,不是訂閱。 無論任何數量的每份文件費用。
  • 本地處理:所有OCR運行於您的流程中。 文件從未離開您的基礎設施。
  • 自動預處理:Deskew、DeNoise、Contrast、Binarize和解析度提升被自動或通過顯式篩選器調用應用在OcrInput
  • 本機PDF支持IronTesseract.Read("document.pdf") 直接處理PDF,包括受密碼保護的文件,而不需要單獨服務或額外的NuGet包。
  • 超過125種語言:通過單獨的語言NuGet包安裝 — IronOcr.Languages.French, IronOcr.Languages.ChineseSimplified, 等等 —,不需要手動tessdata管理。
  • 執行緒安全IronTesseract 安全地併發使用。 批處理工作負載可以使用Parallel.ForEach而沒有额外的同步。
  • 結構化輸出.Pages, .Paragraphs, .Lines, .Words, 和.Barcodes集合,具有每個元素的座標、信心分數和邊界矩形。

功能比較

功能 Azure Computer Vision IronOCR
處理位置 微軟Azure雲 本地,企業內
價格模型 按交易 (聯繫微軟以獲取當前定價) 永久授權($999+)
需要網際網路 是的, 始終如此 不是
PDF支持 通過Form Recognizer(單獨) 內建、本機
設置複雜性 Azure帳戶+資源+密鑰 NuGet安裝
API模式 非同步 (雲I/O) 同步 (本地)
速率限制 10 TPS (S1) 僅限硬體

詳細功能比較

功能 Azure Computer Vision IronOCR
設置與部署
NuGet安裝 多個包 dotnet add package IronOcr
憑證配置 端點URL+API密鑰 授權密鑰字串
需要Azure訂閱 不是
需要互聯網連接 是的,每次請求 不是
氣隙部署 不可能 全面支持
Docker部署 需要外向網路 自包含
OCR能力
圖像OCR 是 (AnalyzeAsync) 是 (Read())
PDF OCR 由Form Recognizer提供(額外的服務) 本地、內建
受密碼保護的 PDF 由Form Recognizer提供 Password:參數
多頁PDF(按頁收費) 是 — 每頁 = 1個交易 無按頁成本
可搜尋的 PDF 輸出 手動構造 SaveAsSearchablePdf()
自動預處理 有限的伺服器端 Deskew, DeNoise, Contrast, Binarize
OCR期間的條碼讀取 有限 ReadBarCodes = true
基於區域的OCR 不能直接(需手動裁剪) CropRectangleOcrInput
語言支持
語言數量 164+ 125+
語言安裝 服務級別(由雲處理) NuGet語言包
支持多種同時語言 是 (AddSecondaryLanguage)
輸出與結構
純文字
按詞劃分的邊界框 基於多邊形 基於矩形
每個單詞的信心分數 是的 (0-100比例)
結構化層次 塊 / 行 / 字詞 頁面 / 段落 / 行 / 字詞
hOCR匯出 不是 是 (SaveAsHocrFile)
成本及合規性
按文件費用 $0.001每頁 (Form Recognizer) None
HIPAA合規部署 複雜 (BAA + 雲) 簡單 (僅限本地)
ITAR適合性 不適用受控資料 完全在內部部署
FedRAMP 空隙 不是
可靠性
網路故障模式 None
速率限制錯誤 是 (429 在 10 TPS) None
服務可用性 SLA 99.9% (Azure) 您自己的基礎設施

成本模型

Azure Computer Vision與IronOCR在生產量下的交易定價差距變得具有決定性。 來自Azure原始文件的成本計算器準確地顯示了計算。

Azure Computer Vision辦法

Azure根據交易數量使用逐級定價來計費。 查閱Azure Computer Vision定價頁面獲取當前價格。 每個PDF頁面即一個交易。 10頁PDF即10筆可計費呼叫。 每月5000次交易的免費層可用。

// Azure bills per transaction — costs grow with every document processed
// Free tier: 5,000 transactions/month
// Volume tiers apply at higher usage levels
// (Every PDF page multiplies the bill)
// Azure bills per transaction — costs grow with every document processed
// Free tier: 5,000 transactions/month
// Volume tiers apply at higher usage levels
// (Every PDF page multiplies the bill)
' Azure bills per transaction — costs grow with every document processed
' Free tier: 5,000 transactions/month
' Volume tiers apply at higher usage levels
' (Every PDF page multiplies the bill)
$vbLabelText   $csharpLabel

在適中或高文件量的情況下,IronOCR永久授權比持續的Azure交易費用快還清成本,之後每增加一個文件都可節省成本。

IronOCR方法

IronOCR的定價模型是單一數字。 安裝NuGet包,設置授權密鑰,處理任何數量無需運行計量:

// Install: dotnet add package IronOcr
// License: one-time, perpetual

IronOcr.License.LicenseKey = Environment.GetEnvironmentVariable("IRONOCR_LICENSE");

var ocr = new IronTesseract();

// Process 1 document or 1 million — same cost
foreach (var path in documentPaths)
{
    var result = ocr.Read(path);
    Console.WriteLine($"Processed: {path}");
}

// Multi-page PDFs — no per-page billing
foreach (var path in pdfPaths)
{
    // 1 page or 100 pages, still no extra cost
    var result = ocr.Read(path);
    Console.WriteLine($"{path}: {result.Pages.Length} pages processed");
}
// Install: dotnet add package IronOcr
// License: one-time, perpetual

IronOcr.License.LicenseKey = Environment.GetEnvironmentVariable("IRONOCR_LICENSE");

var ocr = new IronTesseract();

// Process 1 document or 1 million — same cost
foreach (var path in documentPaths)
{
    var result = ocr.Read(path);
    Console.WriteLine($"Processed: {path}");
}

// Multi-page PDFs — no per-page billing
foreach (var path in pdfPaths)
{
    // 1 page or 100 pages, still no extra cost
    var result = ocr.Read(path);
    Console.WriteLine($"{path}: {result.Pages.Length} pages processed");
}
' Install: dotnet add package IronOcr
' License: one-time, perpetual

IronOcr.License.LicenseKey = Environment.GetEnvironmentVariable("IRONOCR_LICENSE")

Dim ocr As New IronTesseract()

' Process 1 document or 1 million — same cost
For Each path In documentPaths
    Dim result = ocr.Read(path)
    Console.WriteLine($"Processed: {path}")
Next

' Multi-page PDFs — no per-page billing
For Each path In pdfPaths
    ' 1 page or 100 pages, still no extra cost
    Dim result = ocr.Read(path)
    Console.WriteLine($"{path}: {result.Pages.Length} pages processed")
Next
$vbLabelText   $csharpLabel

無計量、無使用跟踪、無預算警報需求。 從第一天開始的可預測成本。 查看從影像讀取文字教程了解完整入門指南。

資料主權與離線功能

雲OCR 的合規影響不是理論性的。 每個通過Azure Computer Vision處理的文件都跨越了一個組織邊界。 Azure READ.me文件記錄了受影響的特定法規框架:受HIPAA 覆蓋的實體、ITAR國防承包商、CMMC認證的組織、受GDPR 管制的歐洲公司及任何在氣隙網路運營的機構。

Azure Computer Vision辦法

即使選擇了地區端點並簽訂了商業夥伴協議,資料流動也是固定的:

// Azure: data flow for every OCR call
// 1. Your application reads the file
// 2. File is serialized to BinaryData
// 3. HTTPS transmission to Azure data center
// 4. Microsoft infrastructure processes the document
// 5. Result returned over HTTPS
// 6. You parse the result

using var stream = File.OpenRead(imagePath);
var imageData = BinaryData.FromStream(stream);  // Document in memory

// This call transmits your document to Azure
var result = await _client.AnalyzeAsync(
    imageData,           // Document leaves your network here
    VisualFeatures.Read);
// Azure: data flow for every OCR call
// 1. Your application reads the file
// 2. File is serialized to BinaryData
// 3. HTTPS transmission to Azure data center
// 4. Microsoft infrastructure processes the document
// 5. Result returned over HTTPS
// 6. You parse the result

using var stream = File.OpenRead(imagePath);
var imageData = BinaryData.FromStream(stream);  // Document in memory

// This call transmits your document to Azure
var result = await _client.AnalyzeAsync(
    imageData,           // Document leaves your network here
    VisualFeatures.Read);
Imports System.IO
Imports Azure.AI.FormRecognizer.DocumentAnalysis

' Azure: data flow for every OCR call
' 1. Your application reads the file
' 2. File is serialized to BinaryData
' 3. HTTPS transmission to Azure data center
' 4. Microsoft infrastructure processes the document
' 5. Result returned over HTTPS
' 6. You parse the result

Using stream As FileStream = File.OpenRead(imagePath)
    Dim imageData As BinaryData = BinaryData.FromStream(stream) ' Document in memory

    ' This call transmits your document to Azure
    Dim result = Await _client.AnalyzeAsync(
        imageData,           ' Document leaves your network here
        VisualFeatures.Read)
End Using
$vbLabelText   $csharpLabel

氣隙網路無法存取端點URL — Azure Computer Vision不提供離線模式。 對於運行SCIF、軍事設施或孤立處理環境的組織,該服務在架構上是不相容的,不管價格如何。

IronOCR方法

IronOCR在調用過程內處理文件。 無外向連通:

// IronOCR: data never leaves your infrastructure
using IronOcr;

public class OnPremiseOcrService
{
    private readonly IronTesseract _ocr = new IronTesseract();

    public string ExtractText(string imagePath)
    {
        // Runs entirely in-process
        //不是network call, no serialization to external endpoint
        var result = _ocr.Read(imagePath);
        return result.Text;
    }

    public string ExtractFromPdf(string pdfPath)
    {
        // PDF processed entirely on-premise, native support
        using var input = new OcrInput();
        input.LoadPdf(pdfPath);
        return _ocr.Read(input).Text;
    }

    public string ExtractFromEncryptedPdf(string pdfPath, string password)
    {
        // Encrypted PDFs also stay local
        using var input = new OcrInput();
        input.LoadPdf(pdfPath, Password: password);
        return _ocr.Read(input).Text;
    }
}
// IronOCR: data never leaves your infrastructure
using IronOcr;

public class OnPremiseOcrService
{
    private readonly IronTesseract _ocr = new IronTesseract();

    public string ExtractText(string imagePath)
    {
        // Runs entirely in-process
        //不是network call, no serialization to external endpoint
        var result = _ocr.Read(imagePath);
        return result.Text;
    }

    public string ExtractFromPdf(string pdfPath)
    {
        // PDF processed entirely on-premise, native support
        using var input = new OcrInput();
        input.LoadPdf(pdfPath);
        return _ocr.Read(input).Text;
    }

    public string ExtractFromEncryptedPdf(string pdfPath, string password)
    {
        // Encrypted PDFs also stay local
        using var input = new OcrInput();
        input.LoadPdf(pdfPath, Password: password);
        return _ocr.Read(input).Text;
    }
}
Imports IronOcr

Public Class OnPremiseOcrService
    Private ReadOnly _ocr As New IronTesseract()

    Public Function ExtractText(imagePath As String) As String
        ' Runs entirely in-process
        '不是network call, no serialization to external endpoint
        Dim result = _ocr.Read(imagePath)
        Return result.Text
    End Function

    Public Function ExtractFromPdf(pdfPath As String) As String
        ' PDF processed entirely on-premise, native support
        Using input As New OcrInput()
            input.LoadPdf(pdfPath)
            Return _ocr.Read(input).Text
        End Using
    End Function

    Public Function ExtractFromEncryptedPdf(pdfPath As String, password As String) As String
        ' Encrypted PDFs also stay local
        Using input As New OcrInput()
            input.LoadPdf(pdfPath, Password:=password)
            Return _ocr.Read(input).Text
        End Using
    End Function
End Class
$vbLabelText   $csharpLabel

Docker 部署完全消除了出站網路需求:

FROM mcr.microsoft.com/dotnet/aspnet:8.0
RUN apt-get update && apt-get install -y libgdiplus
WORKDIR /app
COPY --from=build /app/publish .
ENV IRONOCR_LICENSE=your-key
#不是Azure endpoint, no API key, no outbound network rules needed
ENTRYPOINT ["dotnet", "YourApp.dll"]

對於HIPAA 覆蓋的實體、ITAR 遵從或FedRAMP氣隙場景,IronOCR 消除了整個第三方資料處理器風險類別。 請參閱Azure 部署指南以便在保持文件在計算實例本地的情況下在Azure 基礎設施內運行IronOCR,查看Docker 部署指南以進行容器配置。

同步與非同步API設計

因為無法同步,Azure Read API 是非同步的 — 雲I/O 有網路延遲。 IronOCR本地處理,並且可以同步返回,這簡化了調用程式碼,消除了async在調用堆棧中的傳播,並消除了內在於網路I/O的故障模式。

Azure Computer Vision辦法

每次Azure OCR呼叫都需要await。 生產程式碼為429速率限制錯誤和5xx服務錯誤增加重試邏輯。 一個最小的生產實現看起來如下:

public async Task<string> RobustExtractAsync(string imagePath)
{
    const int maxRetries = 3;
    int attempt = 0;

    while (attempt < maxRetries)
    {
        try
        {
            using var stream = File.OpenRead(imagePath);
            var imageData = BinaryData.FromStream(stream);

            var result = await _client.AnalyzeAsync(
                imageData,
                VisualFeatures.Read);

            return string.Join("\n",
                result.Value.Read.Blocks
                    .SelectMany(b => b.Lines)
                    .Select(l => l.Text));
        }
        catch (RequestFailedException ex) when (ex.Status == 429)
        {
            // Rate limited — Azure caps S1 at 10 TPS
            attempt++;
            await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt)));
        }
        catch (RequestFailedException ex) when (ex.Status >= 500)
        {
            // Azure service error
            attempt++;
            await Task.Delay(TimeSpan.FromSeconds(1));
        }
        catch (RequestFailedException ex)
        {
            // Client error — bad credential, invalid endpoint
            throw new Exception($"Azure OCR failed: {ex.Message}", ex);
        }
    }

    throw new Exception("Max retries exceeded for Azure OCR");
}
public async Task<string> RobustExtractAsync(string imagePath)
{
    const int maxRetries = 3;
    int attempt = 0;

    while (attempt < maxRetries)
    {
        try
        {
            using var stream = File.OpenRead(imagePath);
            var imageData = BinaryData.FromStream(stream);

            var result = await _client.AnalyzeAsync(
                imageData,
                VisualFeatures.Read);

            return string.Join("\n",
                result.Value.Read.Blocks
                    .SelectMany(b => b.Lines)
                    .Select(l => l.Text));
        }
        catch (RequestFailedException ex) when (ex.Status == 429)
        {
            // Rate limited — Azure caps S1 at 10 TPS
            attempt++;
            await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt)));
        }
        catch (RequestFailedException ex) when (ex.Status >= 500)
        {
            // Azure service error
            attempt++;
            await Task.Delay(TimeSpan.FromSeconds(1));
        }
        catch (RequestFailedException ex)
        {
            // Client error — bad credential, invalid endpoint
            throw new Exception($"Azure OCR failed: {ex.Message}", ex);
        }
    }

    throw new Exception("Max retries exceeded for Azure OCR");
}
Imports System.IO
Imports System.Threading.Tasks

Public Async Function RobustExtractAsync(imagePath As String) As Task(Of String)
    Const maxRetries As Integer = 3
    Dim attempt As Integer = 0

    While attempt < maxRetries
        Try
            Using stream = File.OpenRead(imagePath)
                Dim imageData = BinaryData.FromStream(stream)

                Dim result = Await _client.AnalyzeAsync(
                    imageData,
                    VisualFeatures.Read)

                Return String.Join(vbCrLf,
                    result.Value.Read.Blocks _
                        .SelectMany(Function(b) b.Lines) _
                        .Select(Function(l) l.Text))
            End Using
        Catch ex As RequestFailedException When ex.Status = 429
            ' Rate limited — Azure caps S1 at 10 TPS
            attempt += 1
            Await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt)))
        Catch ex As RequestFailedException When ex.Status >= 500
            ' Azure service error
            attempt += 1
            Await Task.Delay(TimeSpan.FromSeconds(1))
        Catch ex As RequestFailedException
            ' Client error — bad credential, invalid endpoint
            Throw New Exception($"Azure OCR failed: {ex.Message}", ex)
        End Try
    End While

    Throw New Exception("Max retries exceeded for Azure OCR")
End Function
$vbLabelText   $csharpLabel

這不是防禦式的過度設計——這是任何生產中的Azure API呼叫所必需的最低要求。 速率限制、服務中斷和瞬態錯誤是任何Azure消費者都會遇到的真實情況。

IronOCR方法

本地處理消除了網路故障面。 錯誤處理的範圍縮小為文件系統和輸入驗證:

//不是async required — local processing returns synchronously
public string ExtractText(string imagePath)
{
    var result = new IronTesseract().Read(imagePath);
    return result.Text;
}

// One line for simple cases
public string OneLineOcr(string imagePath)
{
    return new IronTesseract().Read(imagePath).Text;
}

// Confidence-aware extraction
public (string Text, double Confidence) ExtractWithConfidence(string imagePath)
{
    var result = new IronTesseract().Read(imagePath);
    return (result.Text, result.Confidence);
}
//不是async required — local processing returns synchronously
public string ExtractText(string imagePath)
{
    var result = new IronTesseract().Read(imagePath);
    return result.Text;
}

// One line for simple cases
public string OneLineOcr(string imagePath)
{
    return new IronTesseract().Read(imagePath).Text;
}

// Confidence-aware extraction
public (string Text, double Confidence) ExtractWithConfidence(string imagePath)
{
    var result = new IronTesseract().Read(imagePath);
    return (result.Text, result.Confidence);
}
'不是async required — local processing returns synchronously
Public Function ExtractText(imagePath As String) As String
    Dim result = New IronTesseract().Read(imagePath)
    Return result.Text
End Function

' One line for simple cases
Public Function OneLineOcr(imagePath As String) As String
    Return New IronTesseract().Read(imagePath).Text
End Function

' Confidence-aware extraction
Public Function ExtractWithConfidence(imagePath As String) As (Text As String, Confidence As Double)
    Dim result = New IronTesseract().Read(imagePath)
    Return (result.Text, result.Confidence)
End Function
$vbLabelText   $csharpLabel

沒有Task.WhenAll協調批量作業。 如果您需要非同步以進行與非同步控制器管道的整合,Task.Run(() => ocr.Read(path))將同步呼叫進行包裝而無需對OCR邏輯本身進行結構性更改。 IronTesseract API 參考涵蓋全同步介面。 對於真正需要非同步模式的工作負載,IronOCR還提供專用的非同步OCR指南

憑證和端點的配置

在第一次測試之前,Azure Computer Vision需要準備基礎架構。IronOCR只需安裝NuGet,並可選填寫授權密鑰字串。

Azure Computer Vision辦法

編寫任何OCR程式碼之前的Azure設置順序:

  1. 如無Azure帳戶,建立一個。
  2. 導航到Azure門戶建立Cognitive Services資源(或Azure AI Services 資源)。
  3. 選擇一個價格層和區域。
  4. 複製端點URL(格式:https://your-resource.cognitiveservices.azure.com/)。
  5. 複製兩個API密鑰中的一個。
  6. 安全儲存兩個值——在環境變數中、Azure Key Vault或appsettings.json(僅限非生產)。
  7. 通過NuGet安裝Azure.AI.Vision.ImageAnalysis
  8. 使用端點和憑證初始化ImageAnalysisClient

對於PDF處理,重複步驟2-8為單獨NuGet包(DocumentAnalysisClient)的Form Recognizer資源。

appsettings.json儲存端點和密鑰:

{
  "Azure": {
    "ComputerVision": {
      "Endpoint": "https://your-resource.cognitiveservices.azure.com/",
      "ApiKey": "your-api-key"
    }
  }
}

API密鑰旋轉,處理憑證過期,和管理環境各異的端點URL(開發、測試、生產)是本地處理中沒有對應的持續操作任務。

IronOCR方法

IronTesseract 設置指南將設置簡化至兩步:

dotnet add package IronOcr
// Set once at application startup — environment variable recommended
IronOcr.License.LicenseKey = Environment.GetEnvironmentVariable("IRONOCR_LICENSE");

// Then use immediately — no endpoint, no credential rotation, no portal setup
var text = new IronTesseract().Read("document.jpg").Text;
// Set once at application startup — environment variable recommended
IronOcr.License.LicenseKey = Environment.GetEnvironmentVariable("IRONOCR_LICENSE");

// Then use immediately — no endpoint, no credential rotation, no portal setup
var text = new IronTesseract().Read("document.jpg").Text;
Imports System

' Set once at application startup — environment variable recommended
IronOcr.License.LicenseKey = Environment.GetEnvironmentVariable("IRONOCR_LICENSE")

' Then use immediately — no endpoint, no credential rotation, no portal setup
Dim text As String = (New IronTesseract()).Read("document.jpg").Text
$vbLabelText   $csharpLabel

授權密鑰是一個靜態字串。 不會在每次請求後過期、不需要旋轉、激活後不會致電驗證。 部署環境不需要出站防火牆規則以便OCR正常工作。

API 地圖參考

Azure Computer Vision IronOCR 等效
ImageAnalysisClient IronTesseract
new AzureKeyCredential(apiKey) IronOcr.License.LicenseKey = key
client.AnalyzeAsync(data, VisualFeatures.Read) ocr.Read(imagePath)
BinaryData.FromStream(stream) input.LoadImage(stream)
result.Value.Read.Blocks result.Paragraphs
block.Lines result.Lines
line.Text line.Text
line.Words result.Words
word.Confidence word.Confidence (0-100比例對比Azure的0-1)
word.BoundingPolygon word.X, word.Y, word.Width, word.Height
DocumentAnalysisClient IronTesseract + OcrInput
AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-read", stream) ocr.Read(input)input.LoadPdf(path)
operation.Value.Pages result.Pages
page.Lines / line.Content result.Lines / line.Text
RequestFailedException (429重試) 不適用 — 無速率限制
RequestFailedException (500重試) 不適用 — 無服務錯誤

當團隊考慮從Azure Computer Vision轉移至IronOCR

合規要求阻止雲處理

一家開發文件管理系統的醫療ISV開始使用Azure Computer Vision因為整合速度快。 然後第一個企業客戶到來——一個醫院系統,其中有一個HIPAA安全官,他問了兩個問題:"我們的PHI去哪裡了?"及"您能向我們展示涵蓋該第三方的商業夥伴協議嗎?"Azure有BAA,但對於第一個問題的回答——"Microsoft資料中心"——引發了一場長時間的安全審查、對Microsoft審核報告的請求,以及推遲合同的合規時間表。 轉而使用IronOCR完全消除了這個問題。 PHI從未離開過客戶的環境。 合規範圍保持在客戶自己的組織內。

音量增長讓每交易定價無法承擔

一家運營團隊推出了一個每月5000個文件的發票處理管線——舒適地在Azure的免費層範圍內。 隨著量上升,每筆交易費用都伴隨著每個處理的文件增加。 IronOCR專業版($2,999) 是一次性購買,無每文件費用。 即使預測到適中體量增長的團隊也能快速達到收支平衡,之後每增加一份文件都是節省。

網路延遲影響處理SLA(服務水平協議)

某文件處理服務設定的目標是2秒的端到端SLA。 Azure Computer Vision為同區域呼叫增加了200-800ms的網路延遲,對於跨區域部署增加了500-2000ms的網路延遲——這還未計算OCR計算時間本身。 在高負載下,S1的10 TPS限速強制排隊,進一步增加延遲。 IronOCR在商品伺服器硬體上以100-400ms的速度處理單個300 DPI圖像,無需排隊、無速率上限且無網路跳躍。SLA變得可預測,因為它僅依賴於硬體而非Azure服務健康或網路狀況。

氣隙基礎設施需求

國防承包商、情報機構以及關鍵基礎設施運營商在設計上運行無互聯網連接的網路上的工作負載。 Azure Computer Vision在技術上與這些環境不相容——無法到達端點。 這些領域的團隊需要一個能作為自包含二進制部署、無需任何外向連接並通過明確禁止雲資料傳輸的安全審查程式庫。 IronOCR的Linux部署及Docker支持使其能夠在受限環境中部署而無需修改。

簡化多環境部署

一個管理SaaS應用程式的開發、測試和生產環境的團隊保持三個Azure認知服務資源、三組API密鑰及三個端點URL——每個都需要安全儲存、輪換策略及特定於環境的配置。 每個部署環境都需要對Azure的外向網路存取。 IronOCR將每環境的配置簡化至一個環境變數(IRONOCR_LICENSE),消除了網路存取需求並消除了在多個環境間憑證管理的操作性開銷。

常見的遷移考量

非同步到同步模式

Azure 消費者程式碼因必要而async。 IronOCR不需要非同步,但轉換是機械性的。 用async 關鍵字,並刪除重試迴圈。如果調用方法是一個ASP.NET控制器或服務並且必須保持非同步,將IronOCR調用包裝於Task.Run

// Before: Azure async chain
public async Task<string> ReadTextAsync(string imagePath)
{
    using var stream = File.OpenRead(imagePath);
    var data = BinaryData.FromStream(stream);
    var result = await _client.AnalyzeAsync(data, VisualFeatures.Read);
    return string.Join("\n", result.Value.Read.Blocks
        .SelectMany(b => b.Lines)
        .Select(l => l.Text));
}

// After:IronOCRsynchronous
public string ReadText(string imagePath)
{
    return new IronTesseract().Read(imagePath).Text;
}

// If async signature must be preserved for interface compatibility
public Task<string> ReadTextAsync(string imagePath)
{
    return Task.Run(() => new IronTesseract().Read(imagePath).Text);
}
// Before: Azure async chain
public async Task<string> ReadTextAsync(string imagePath)
{
    using var stream = File.OpenRead(imagePath);
    var data = BinaryData.FromStream(stream);
    var result = await _client.AnalyzeAsync(data, VisualFeatures.Read);
    return string.Join("\n", result.Value.Read.Blocks
        .SelectMany(b => b.Lines)
        .Select(l => l.Text));
}

// After:IronOCRsynchronous
public string ReadText(string imagePath)
{
    return new IronTesseract().Read(imagePath).Text;
}

// If async signature must be preserved for interface compatibility
public Task<string> ReadTextAsync(string imagePath)
{
    return Task.Run(() => new IronTesseract().Read(imagePath).Text);
}
Imports System.IO
Imports System.Threading.Tasks
Imports IronOcr

' Before: Azure async chain
Public Async Function ReadTextAsync(imagePath As String) As Task(Of String)
    Using stream = File.OpenRead(imagePath)
        Dim data = BinaryData.FromStream(stream)
        Dim result = Await _client.AnalyzeAsync(data, VisualFeatures.Read)
        Return String.Join(vbLf, result.Value.Read.Blocks _
            .SelectMany(Function(b) b.Lines) _
            .Select(Function(l) l.Text))
    End Using
End Function

' After: IronOCR synchronous
Public Function ReadText(imagePath As String) As String
    Return New IronTesseract().Read(imagePath).Text
End Function

' If async signature must be preserved for interface compatibility
Public Function ReadTextAsync(imagePath As String) As Task(Of String)
    Return Task.Run(Function() New IronTesseract().Read(imagePath).Text)
End Function
$vbLabelText   $csharpLabel

信心比例標準化

Azure Computer Vision將字詞信心返回為0到1之間的float。 IronOCR將信心作為0到100的double返回。 任何在Azure信心值上設置閾值的程式碼需要進行調整:

// Azure: confidence is 0.0 - 1.0
foreach (var word in line.Words)
{
    if (word.Confidence > 0.85f) { /* high confidence */ }
}

// IronOCR: confidence is 0 - 100
var result = new IronTesseract().Read(imagePath);
foreach (var word in result.Words)
{
    if (word.Confidence > 85.0) { /* equivalent threshold */ }
}
Console.WriteLine($"Overall: {result.Confidence}%");
// Azure: confidence is 0.0 - 1.0
foreach (var word in line.Words)
{
    if (word.Confidence > 0.85f) { /* high confidence */ }
}

// IronOCR: confidence is 0 - 100
var result = new IronTesseract().Read(imagePath);
foreach (var word in result.Words)
{
    if (word.Confidence > 85.0) { /* equivalent threshold */ }
}
Console.WriteLine($"Overall: {result.Confidence}%");
Imports IronOcr

' Azure: confidence is 0.0 - 1.0
For Each word In line.Words
    If word.Confidence > 0.85F Then
        ' high confidence
    End If
Next

' IronOCR: confidence is 0 - 100
Dim result = New IronTesseract().Read(imagePath)
For Each word In result.Words
    If word.Confidence > 85.0 Then
        ' equivalent threshold
    End If
Next
Console.WriteLine($"Overall: {result.Confidence}%")
$vbLabelText   $csharpLabel

OcrResult API參考記錄了所有結果屬性包括信心比例。 信心分數具體指南涵蓋了閾值選擇及每個元素的解釋。

PDF處理服務整合

Azure將圖像OCR和PDF OCR拆分到兩個單獨的服務,具有單獨的客戶端、NuGet包和端點配置。 遷徙意味著將這兩個路徑整合到一個IronTesseract實例中。 Password參數—無需第二個客戶端:

// Before: Two separate Azure clients for images vs PDFs
// Image: ImageAnalysisClient + AnalyzeAsync
// PDF:   DocumentAnalysisClient + AnalyzeDocumentAsync(WaitUntil.Completed, ...)

// After: One IronTesseract instance handles both
var ocr = new IronTesseract();

// Image
var imageResult = ocr.Read("document.jpg");

// PDF (same client, same Read method)
using var pdfInput = new OcrInput();
pdfInput.LoadPdf("document.pdf");
var pdfResult = ocr.Read(pdfInput);

// Password-protected PDF
using var encInput = new OcrInput();
encInput.LoadPdf("secured.pdf", Password: "secret");
var encResult = ocr.Read(encInput);

//可搜尋的 PDF 輸出— no manual construction
pdfResult.SaveAsSearchablePdf("searchable-output.pdf");
// Before: Two separate Azure clients for images vs PDFs
// Image: ImageAnalysisClient + AnalyzeAsync
// PDF:   DocumentAnalysisClient + AnalyzeDocumentAsync(WaitUntil.Completed, ...)

// After: One IronTesseract instance handles both
var ocr = new IronTesseract();

// Image
var imageResult = ocr.Read("document.jpg");

// PDF (same client, same Read method)
using var pdfInput = new OcrInput();
pdfInput.LoadPdf("document.pdf");
var pdfResult = ocr.Read(pdfInput);

// Password-protected PDF
using var encInput = new OcrInput();
encInput.LoadPdf("secured.pdf", Password: "secret");
var encResult = ocr.Read(encInput);

//可搜尋的 PDF 輸出— no manual construction
pdfResult.SaveAsSearchablePdf("searchable-output.pdf");
Imports IronOcr

' Before: Two separate Azure clients for images vs PDFs
' Image: ImageAnalysisClient + AnalyzeAsync
' PDF:   DocumentAnalysisClient + AnalyzeDocumentAsync(WaitUntil.Completed, ...)

' After: One IronTesseract instance handles both
Dim ocr As New IronTesseract()

' Image
Dim imageResult = ocr.Read("document.jpg")

' PDF (same client, same Read method)
Using pdfInput As New OcrInput()
    pdfInput.LoadPdf("document.pdf")
    Dim pdfResult = ocr.Read(pdfInput)

    ' Password-protected PDF
    Using encInput As New OcrInput()
        encInput.LoadPdf("secured.pdf", Password:="secret")
        Dim encResult = ocr.Read(encInput)
    End Using

    ' 可搜尋的 PDF 輸出— no manual construction
    pdfResult.SaveAsSearchablePdf("searchable-output.pdf")
End Using
$vbLabelText   $csharpLabel

PDF輸入指南涵蓋頁面範圍選擇、流輸入和本地PDF渲染管道。對於圖像輸入,請查看圖像輸入指南

無需Form Recognizer的結構化資料提取

使用Form Recognize預建模型(發票、收據、身份文件)進行字段提取的團隊需要使用基於區域的OCR與CropRectangle來在IronOCR中複製該提取邏輯。 位置提取是顯式的而不是模型化的:

// Form Recognizer extracted named fields automatically
// IronOCR: define extraction zones for known document layouts
var ocr = new IronTesseract();

// Define regions matching the document template
var vendorZone   = new CropRectangle(0,   0,   300, 100);
var invoiceDate  = new CropRectangle(400, 0,   200, 50);
var totalAmount  = new CropRectangle(400, 500, 200, 100);

string vendor, date, total;

using (var input = new OcrInput())
{
    input.LoadImage("invoice.jpg", vendorZone);
    vendor = ocr.Read(input).Text.Trim();
}

using (var input = new OcrInput())
{
    input.LoadImage("invoice.jpg", invoiceDate);
    date = ocr.Read(input).Text.Trim();
}

using (var input = new OcrInput())
{
    input.LoadImage("invoice.jpg", totalAmount);
    total = ocr.Read(input).Text.Trim();
}
// Form Recognizer extracted named fields automatically
// IronOCR: define extraction zones for known document layouts
var ocr = new IronTesseract();

// Define regions matching the document template
var vendorZone   = new CropRectangle(0,   0,   300, 100);
var invoiceDate  = new CropRectangle(400, 0,   200, 50);
var totalAmount  = new CropRectangle(400, 500, 200, 100);

string vendor, date, total;

using (var input = new OcrInput())
{
    input.LoadImage("invoice.jpg", vendorZone);
    vendor = ocr.Read(input).Text.Trim();
}

using (var input = new OcrInput())
{
    input.LoadImage("invoice.jpg", invoiceDate);
    date = ocr.Read(input).Text.Trim();
}

using (var input = new OcrInput())
{
    input.LoadImage("invoice.jpg", totalAmount);
    total = ocr.Read(input).Text.Trim();
}
Imports IronOcr

' Form Recognizer extracted named fields automatically
' IronOCR: define extraction zones for known document layouts
Dim ocr As New IronTesseract()

' Define regions matching the document template
Dim vendorZone As New CropRectangle(0, 0, 300, 100)
Dim invoiceDate As New CropRectangle(400, 0, 200, 50)
Dim totalAmount As New CropRectangle(400, 500, 200, 100)

Dim vendor As String
Dim [date] As String
Dim total As String

Using input As New OcrInput()
    input.LoadImage("invoice.jpg", vendorZone)
    vendor = ocr.Read(input).Text.Trim()
End Using

Using input As New OcrInput()
    input.LoadImage("invoice.jpg", invoiceDate)
    [date] = ocr.Read(input).Text.Trim()
End Using

Using input As New OcrInput()
    input.LoadImage("invoice.jpg", totalAmount)
    total = ocr.Read(input).Text.Trim()
End Using
$vbLabelText   $csharpLabel

基於區域的OCR指南詳細介紹了CropRectangle的用法。 對於特定的發票工作流程,發票OCR教程演示了完整的提取模式。

其他IronOCR功能

除了上述比較點,IronOCR提供了Azure Computer Vision通過其標准OCR API未暴露的功能:

  • 掃描文件處理:完整的預處理管道 — 反璇轉、去噪、對比度、二值化、銳化 — 在OCR引擎看到圖像之前應用,提高雲API返回空或低置信結果時的準確性。
  • 長文件的進度追踪:在多頁PDF處理過程中訂閱進程事件—這對於UI反饋需求的長時間運行批處理作業非常有用。
  • 計算機視覺預處理:基於深度學習的預處理適用於如在角度拍攝或光線不一致的照片等具有挑戰性的文件。

.NET 相容性和未來準備

IronOCR從單個NuGet包提供對.NET 8、.NET 9、.NET Standard 2.0、.NET Framework 4.6.2到4.8的支持。 它支持Windows x64、Windows x86、Linux x64、macOS(Intel 和 Apple Silicon),和ARM64 ——覆蓋從Azure App Service、AWS Lambda、Docker 容器到本地主機的全部現代.NET部署目標。 Azure Computer Vision的.NET SDK (Azure.AI.Vision.ImageAnalysis)也保持現代.NET相容性,但其雲架構意味著與語言運行時的相容性次於與Azure端點的相容性,而後者獨立於SDK進行版本化和更新。 IronOCR通過NuGet發送語言和引擎更新,保持更新模型與.NET生態系統其餘部分一致。

結論

Azure Computer Vision是對於已在Azure生態系統中運營且文件無雲傳輸合規限制的團隊來說是有能力的OCR服務,且其容量適合於免費層或低量付費層。 非同步API功能齊全,標准文件的準確性可靠,Form Recognize預先構建的模型降低了像發票和收據這樣的結構化文件型別的開發工作量。

但是,其成本模型不可擴展。 針對每月50,000個文件,IronOCR Lite在不到兩個月內即由節省下來的Azure交易費付清自己。 對於多頁PDF的按頁計費又加劇了成本。每增加一個操作年度超過收支平衡的額外成本不是去Microsoft的錢了。 對於任何預計增長超過每月10,000個文件的團隊來說,長期經濟性利好於永久本地授權。

資料主權論點更為絕對。 如果PHI、ITAR控制資料、律師-客戶特權通信或任何類不能法定或合同地跨過組織邊界的文件類別流過您的OCR管道,Azure Computer Vision 就被設計排除 — 而不是被剝奪,而是排除。IronOCR的本地處理模式無需做出架構妥協即可處理這些工作負載。

非同步輪詢的複雜性是真實的開銷。 重試邏輯、速率限制處理、網路故障模式和DocumentAnalysisClient在影像和PDF之間的分裂都增加了沒有OCR價值的程式碼 — 它是雲整合程式碼。 IronOCR的同步Read()方法用相同程式碼處理影像及PDF,不需要非同步傳播,也不需重試邏輯。 對於那些希望將工程精力用於其應用而非雲API管道的團隊來說,這種簡單性隨著項目的生命而具有附加價值。

請注意Azure Computer Vision 和 Tesseract是其各自所有者的註冊商標。 此站點與Google或Microsoft無任何聯繫、認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供資訊用途,並反映撰寫時獲得的公開資訊。

常見問題

什麼是 Azure Computer Vision OCR?

Azure Computer Vision OCR 是一種被開發者和企業使用的 OCR 解決方案,用於從影像和文件中提取文字。這是.NET應用程式開發中與 IronOCR 一起評估的多個 OCR 選項之一。

IronOCR 與 Azure Computer Vision OCR 對.NET開發者來說有何不同?

IronOCR 是一款 NuGet 原生的 .NET OCR 程式庫,使用 IronTesseract 作為核心引擎。與 Azure Computer Vision OCR 相比,它提供更簡單的部署(無需 SDK 安裝程式)、固定費率定價,以及無需 COM interop 或雲端依賴的簡潔 C# API。

IronOCR 比 Azure Computer Vision OCR 更容易設定嗎?

IronOCR 通過一個單一的 NuGet 套件安裝。無需 SDK 安裝程式、複製授權文件、註冊 COM 元件或管理單獨的運行時二進位檔案。整個 OCR 引擎都打包在套件中。

Azure Computer Vision OCR 和 IronOCR 之間有什麼準確性差異?

IronOCR 在標準商業文件、發票、收據和掃描表單上達到了高識別準確度。對於極度退化的文件或罕見文字,準確度會根據來源品質變化。IronOCR 包含影像預處理篩選器,以改善低品質輸入的識別。

IronOCR 支援 PDF 文字提取嗎?

是的。IronOCR 能從原生 PDF 和掃描的 PDF 圖像中一次性提取文字。它還支持多頁 TIFF 檔案、影像和流。對於掃描的 PDF,OCR 會逐頁應用並生成每頁的結果物件。

Azure Computer Vision OCR 和 IronOCR 的授權有何比較?

IronOCR 採用固定費率的永久授權,無須為每頁或每次掃描支付費用。處理大量文件的組織無論數量多少都支付相同的授權費用。詳細資訊和批量定價在 IronOCR 授權頁面上。

IronOCR 支援哪些語言?

IronOCR 透過單獨的 NuGet 語言包支持 127 種語言。新增一種語言只需一個 'dotnet add package IronOcr.Languages.{Language}' 命令。無需手動放置文件或配置路徑。

如何在.NET專案中安裝IronOCR?

通過 NuGet 安裝:在套件管理員控制台或 CLI 中分別使用 'Install-Package IronOcr' 或 'dotnet add package IronOcr'。其他語言包也是這樣安裝的。無需本地 SDK 安裝程式。

IronOCR 是否適合 Docker 和容器化部屬,而 Azure Computer Vision 則不適合?

是的。IronOCR 通過其 NuGet 載於 Docker 容器中運行。授權金鑰通過環境變數設置。無需授權文件、SDK 路徑或量掛載來執行 OCR 引擎。

我可以在購買之前試用 IronOCR,與 Azure Computer Vision 比較如何?

是的。IronOCR 試用模式中處理文件並在輸出上附上浮水印結果。您可以在購買授權前驗證自己文件的準確性。

IronOCR 支援條碼閱讀與文字提取嗎?

IronOCR 專注於文字提取和 OCR。對於條碼閱讀,Iron Software 提供了額外的 IronBarcode 程式庫。兩者均可個別使用或作為 Iron Suite 套件的一部分。

從 Azure Computer Vision OCR 遷移到 IronOCR 容易嗎?

從 Azure Computer Vision OCR 遷移到 IronOCR 通常包括用 IronTesseract 初始化取代初始化序列,移除 COM 生命週期管理,以及更新 API 調用。大多數遷移明顯減少程式碼複雜性。

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

Iron 支援團隊

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