How to Read MICR Cheque using IronOCR

This article was translated from English: Does it need improvement?
Translated
View the article in English

手動處理支票既慢又容易出錯。 IronOCR 使用專門的引擎來簡化此工作流程,準確讀取 MICR(磁性墨水字符識別)行,讓您自動提取路由號碼、賬號和其他關鍵數據。

作為標題:2(快速入門:從支票圖像中讀取MICR)

使用 IronOCR 快速抓取 MICR 行——只需將語言設置為 MICR,指定 MICR 文本顯示的矩形區域,運行 Read(),立即獲得結果文本字符串。 非常適合希望在最小設置下獲取可靠財務數據的開發人員。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. Copy and run this code snippet.

    string micrText = new IronOcr.IronTesseract { Language = IronOcr.OcrLanguage.MICR }.Read(new IronOcr.OcrInput().LoadImage("micr.png", new System.Drawing.Rectangle(125, 240, 310, 15))).Text;
  3. Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

簡化工作流程(5 步)

  1. 下載用於讀取 MICR 支票的 C# 庫
  2. 實例化 OCR 引擎
  3. 將 Language 設置為 MICR
  4. 使用 Read 方法從樣本支票圖像中提取數據
  5. 訪問 OcrResult 屬性查看和操作提取數據

讀取 MICR 支票示例

使用 IronOCR 讀取 MICR 行既簡單又直觀。我們首先將 IronTesseract 實例的 Language 屬性設置為 OcrLanguage.Micr。 為確保引擎讀取正確區域,必須通過在 OcrInput 上設置矩形邊界來指定 MICR 行的位置。

這是通過選擇界限矩形的 x 和 y 坐標以及高度和寬度來實現的,然後在調用 Load 方法時將矩形作為第二個參數傳遞。 調用 Read 方法然後僅處理此已定義區域。 這種 MICR 語言設置和特定區域的組合保證了 IronOCR 準確地提取相關的財務信息。

支票輸入

MICR 支票

MICR 行

支票號碼:此號碼唯一識別賬戶持有人的支票簿中的特定支票。 它作為跟蹤單個付款和維護交易記錄的明確參考。

路由號碼:此九位數代碼由 ⑆ 運送符號包圍,標識擁有賬戶的金融機構。 結算所使用的第一條信息是將支票正確地引導到銀行以進行支付。

賬號:這標識將從中提取資金的特定客戶賬戶。 其長度因不同銀行而異。

代碼

:path=/static-assets/ocr/content-code-examples/how-to/read-micr-cheque.cs
using IronOcr;
using IronSoftware.Drawing;
using System;

// Create a new instance of IronTesseract for performing OCR operations
IronTesseract ocr = new IronTesseract();

// Set the OCR language to MICR to recognize magnetic ink characters
// Must have MICR (IronOcr.Languages.MICR) installed beforehand
ocr.Language = OcrLanguage.MICR;

// Specify the file path of the input image containing MICR text
using (var input = new OcrInput())
{
    // Specify the MICR of the image to focus on for OCR (coordinates in pixels)
    var contentArea = new Rectangle(x: 215, y: 482, width: 520, height: 20);
    input.LoadImage("micr.png", contentArea);

    // Optional: Save the cropped area for verification
    input.StampCropRectangleAndSaveAs(contentArea, Color.Aqua, "cropped.png");

    // Run the OCR engine to read the MICR text from the input image
    var result = ocr.Read(input);
    // Output the recognized text to the console
    Console.WriteLine(result.Text);

    // Transit number is the first 7 characters of the MICR string
    string transitNum = result.Text.Substring(0, 7);
    // Routing number starts from the 8th character and is 11 characters long
    string routingNum = result.Text.Substring(7, 11);
    // Account number starts from the 22nd character to the end of the string
    string accountNum = result.Text.Substring(22);
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

輸出

class="content-img-align-center">
style="width=50%"> MICR Output

上面的輸出顯示了從 MICR 支票中獲得的三個部分:轉運號碼、路由號碼和賬號。

MICR OCR 結果

OcrResult 對象為掃描提供詳細信息:

文本: 從 OCR 輸入中提取的文本。

信心:表示每個字符平均統計精度的置信度,最高為 1,最低為 0。

驗證 MICR 支票的 OCR 區域

為確保您選擇了正確的 MICR 行坐標,您可以可視化您定義的 ContentArea。 一個簡單的方法是將矩形畫在輸入圖像上,並使用 StampCropRectangleAndSaveAs 將其保存為新文件。 這可以幫助您調試和微調坐標以獲得最佳效果。

提示要查找您的矩形的坐標,您可以使用像微軟畫圖這樣的簡單圖像編輯器。 打開支票圖像,將鼠標懸停在 MICR 行的左上角和右下角,並記錄 (x,y) 像素坐標。 然後您可以計算矩形的屬性:(x1, y1, 寬度, 高度),其中寬度 = x2-x1, 高度 = y2-y1。

這是根據我們的示例支票畫出指定邊界框後的輸出圖像。

輸出

class="content-img-align-center">
style="width=50%"> MICR cropped

淺藍色的矩形確認了我們已正確隔離了 MICR 行進行處理。

常見問題解答

使用 IronOCR 讀取 MICR 支票的目的是什麼?

IronOCR 透過精確提取路由號碼和帳號等關鍵數據,簡化了讀取 MICR 支票的過程,減少了人工錯誤,提高了財務處理的效率。

我該如何使用 IronOCR 讀出 MICR 支票?

要開始使用 IronOCR 讀取 MICR 支票,請下載 C# 庫,實例化 OCR 引擎,將語言設定為 MICR,然後使用 Read 方法從支票影像中提取資料。

IronOCR 讀取 MICR 影像需要哪些特定的庫包?

若要使用 IronOCR 執行 MICR 讀取,您需要安裝 IronOcr.Languages.MICR 軟體包。

如何確保使用 IronOCR 時 MICR 線讀取的準確性?

透過在 OcrInput 上設定矩形邊界來指定 MICR 行的位置。這種聚焦式方法結合 MICR 語言設置,可確保準確提取財務資訊。

IronOCR擷取的MICR線的關鍵組成部分是什麼?

IronOCR 從 MICR 行中提取支票號碼、路由號碼和帳號,這些資訊對於財務交易至關重要。

如何使用 IronOCR 驗證 MICR 支票的 OCR 區域?

您可以透過在輸入影像上繪製矩形並使用 StampCropRectangleAndSaveAs 儲存來視覺化內容區域,以確保正確的座標選擇。

IronOCR MICR 讀取過程可以得到什麼樣的結果?

輸出結果包括轉帳號碼、路由號碼和帳號,並以統計準確度置信度表示每個字元。

如何在 IronOCR 中定義 MICR 線的邊界框?

使用影像編輯器找到支票影像上 MICR 線的左上角和右下角座標,然後計算邊界框的矩形屬性。

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'name'

Filename: sections/author_component.php

Line Number: 18

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 18
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'title'

Filename: sections/author_component.php

Line Number: 38

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 38
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'comment'

Filename: sections/author_component.php

Line Number: 48

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 48
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

準備好開始了嗎?
Nuget 下載 5,044,537 | 版本: 2025.11 剛剛發布