如何使用 IronOCR 閱讀手寫影像。

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

IronOCR 提供專門的 ReadHandwriting 方法,能夠可靠地將影像中的手寫文字數位化,儘管面對不規則間距和筆劃變化的固有挑戰,英文手寫文字的準確率仍可達到 90% 左右。

快速入門:使用 IronOCR 閱讀手寫影像

<! -- 介紹的視覺演示 --> <!--說明:螢幕截圖或圖表 -->

1.安裝 IronOCR 和 IronOcr.Extensions.AdvancedScan 套件 2.建立 IronTesseract 範例 3.使用 LoadImage() 載入您的手寫圖像 4.呼叫 ReadHandwriting() 方法 5.從 OcrResult 存取擷取的文字

Nuget Icon立即開始使用 NuGet 建立 PDF 檔案:

  1. 使用 NuGet 套件管理器安裝 IronOCR

    PM > Install-Package IronOcr

  2. 複製並運行這段程式碼。

    using IronOcr;
    
    var ocrTesseract = new IronTesseract();
    using var ocrInput = new OcrInput();
    ocrInput.LoadImage("handwriting.png");
    var ocrResult = ocrTesseract.ReadHandwriting(ocrInput);
    Console.WriteLine(ocrResult.Text);
  3. 部署到您的生產環境進行測試

    立即開始在您的專案中使用 IronOCR,免費試用!
    arrow pointer

從影像中自動讀取手寫文字極為困難,因為人們的書寫方式各不相同。 這種大量的不一致使得 OCR 具有挑戰性。 舊記錄、病人入院表格和客戶調查等重要文件仍然需要手動處理,導致容易出錯的工作流程,損害資料的完整性。

IronOCR 藉由引進可靠理解手寫影像並將其數位化的專門方法,解決了這個問題。 IronOCR 基於強大的Tesseract 5 引擎,將先進的影像處理與機器學習相結合,提供業界領先的手寫辨識功能。

本指南將逐步說明如何在您的 .NET 應用程式中實作手寫 OCR。無論您是將歷史文件數位化、處理醫療表單或轉換手寫筆記,您都將學到如何使用 IronOCR 達到可靠的結果。

IronOCR 入門指南


若要使用此功能,您必須先安裝 IronOcr.Extensions.AdvancedScan 套件。 請注意 ReadHandwriting 方法目前僅支援英文。 對於 多語言 OCR,請使用標準 Read() 方法與適當的語言套件。

如何使用 IronOCR 閱讀手寫影像?

<! -- 在 IronPDF 中顯示讀取手寫影像結果的輸出 --> --> <!--說明:顯示程式碼執行輸出或結果的截圖 -->

使用 IronOCR 閱讀手寫影像非常簡單直接。 首先實體化 OCR 引擎,然後以 LoadImage 載入影像,最後再使用專門為手寫辨識設計的 ReadHandwriting 方法。 列印擷取的文字以驗證正確性與內容。

在處理之前,請考慮套用 影像品質修正篩選器,以提高可讀性。 這些濾鏡可以顯著提高辨識準確度,特別是對於對比度或解析度較差的掃描文件。

我應該使用何種輸入格式?

手寫輸入影像範例,顯示 OCR 處理的草書文字
:path=/static-assets/ocr/content-code-examples/how-to/read-handwritten-image.cs
using IronOcr;

// Instantiate OCR engine
var ocr = new IronTesseract();

// Load handwriting image
var inputHandWriting = new OcrInput();
inputHandWriting.LoadImage("handwritten.png");

// Perform OCR on the handwriting image
OcrHandwritingResult result = ocr.ReadHandwriting(inputHandWriting);

// Output the recognized handwritten text
Console.WriteLine(result.Text);
// Output the confidence score of the OCR result
Console.WriteLine(result.Confidence);
Imports IronOcr

' Instantiate OCR engine
Dim ocr As New IronTesseract()

' Load handwriting image
Dim inputHandWriting As New OcrInput()
inputHandWriting.LoadImage("handwritten.png")

' Perform OCR on the handwriting image
Dim result As OcrHandwritingResult = ocr.ReadHandwriting(inputHandWriting)

' Output the recognized handwritten text
Console.WriteLine(result.Text)
' Output the confidence score of the OCR result
Console.WriteLine(result.Confidence)
$vbLabelText   $csharpLabel

我可以期待什麼結果?

OCR 輸出結果,顯示擷取的手寫文字與信心分數

ReadHandwriting 方法的置信度達到了 90.6%,正確辨識了大部分的文字,包括開頭的短語 "My name is Erin Fish"。

這個強大的結果證明了 IronOCR 處理具有挑戰性的手寫腳本的能力。 雖然引擎在間距和連接字母方面有困難,但它成功地提取了核心訊息。 這顯示 IronOCR 能有效處理複雜、非標準的文字。

對於 OCR 的新手,請先從我們的 simple OCR tutorial 開始瞭解基本知識,然後再處理手寫辨識。

如何使用 Async 版本?

IronOCR 支援異步版本:ReadHandwritingAsync。 這在處理需要在處理前取得輸入影像的異步程式碼時非常有用。 async 支援文件提供實施異步 OCR 作業的全面指導。

使用相同的輸入,以下是如何使用 async 方法:

:path=/static-assets/ocr/content-code-examples/how-to/read-handwritten-image-async.cs
using IronOcr;
using System.Threading.Tasks;

// Instantiate OCR engine
var ocr = new IronTesseract();

// Load handwriting image
var inputHandWriting = new OcrInput();
inputHandWriting.LoadImage("handwritten.png");

// Perform OCR using the async method with 'await'.
// The compiler automatically infers this top-level code block as an 'async Task Main()' method.
OcrHandwritingResult result = await ocr.ReadHandwritingAsync(inputHandWriting);

// Output the recognized handwriting text
Console.WriteLine(result.Text);
// Output the confidence score of the OCR result
Console.WriteLine(result.Confidence);
Imports IronOcr
Imports System.Threading.Tasks

' Instantiate OCR engine
Dim ocr As New IronTesseract()

' Load handwriting image
Dim inputHandWriting As New OcrInput()
inputHandWriting.LoadImage("handwritten.png")

' Perform OCR using the async method with 'Await'.
' The compiler automatically infers this top-level code block as an 'Async Function Main() As Task' method.
Dim result As OcrHandwritingResult = Await ocr.ReadHandwritingAsync(inputHandWriting)

' Output the recognized handwriting text
Console.WriteLine(result.Text)
' Output the confidence score of the OCR result
Console.WriteLine(result.Confidence)
$vbLabelText   $csharpLabel

您可以提供可選的 timeoutMs 參數,指定自動取消前的毫秒數。 預設值為 -1,表示沒有時間限制 - 作業會一直執行到完成為止。

進階處理技術

<! -- 進階手寫處理技術示範 --> <!--說明:顯示進階處理選項的視覺指南 -->

對於複雜的手寫辨識情境,請考慮這些先進的技術:

特定區域的 OCR:在處理表格或結構化文件時,請使用 區域特定 OCR 來集中處理包含手寫文字的特定區域。 此方法可透過限制處理範圍來提高精確度:

using IronOcr;
using IronSoftware.Drawing;

var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();

// Define a specific region for signature area
var signatureRegion = new CropRectangle(x: 100, y: 500, width: 300, height: 100);
ocrInput.LoadImage("form-with-signature.png", signatureRegion);

var signatureResult = ocrTesseract.ReadHandwriting(ocrInput);
Console.WriteLine($"Signature text: {signatureResult.Text}");
using IronOcr;
using IronSoftware.Drawing;

var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();

// Define a specific region for signature area
var signatureRegion = new CropRectangle(x: 100, y: 500, width: 300, height: 100);
ocrInput.LoadImage("form-with-signature.png", signatureRegion);

var signatureResult = ocrTesseract.ReadHandwriting(ocrInput);
Console.WriteLine($"Signature text: {signatureResult.Text}");
Imports IronOcr
Imports IronSoftware.Drawing

Dim ocrTesseract As New IronTesseract()
Using ocrInput As New OcrInput()

    ' Define a specific region for signature area
    Dim signatureRegion As New CropRectangle(x:=100, y:=500, width:=300, height:=100)
    ocrInput.LoadImage("form-with-signature.png", signatureRegion)

    Dim signatureResult = ocrTesseract.ReadHandwriting(ocrInput)
    Console.WriteLine($"Signature text: {signatureResult.Text}")

End Using
$vbLabelText   $csharpLabel

進度追蹤:針對多份手寫文件的批次處理,實施 進度追蹤 以監控 OCR 作業:

ocrTesseract.OcrProgress += (sender, e) => 
{
    Console.WriteLine($"Processing: {e.ProgressPercent}% complete");
};
ocrTesseract.OcrProgress += (sender, e) => 
{
    Console.WriteLine($"Processing: {e.ProgressPercent}% complete");
};
ocrTesseract.OcrProgress += Sub(sender, e)
    Console.WriteLine($"Processing: {e.ProgressPercent}% complete")
End Sub
$vbLabelText   $csharpLabel

我應該注意哪些挑戰?

雖然 IronOCR 在保留整體結構和文字方面達到了很高的置信度,但 OCR 在處理手寫文字時仍有困難,導致局部錯誤。 常見的挑戰需要對提取的輸出進行驗證:

不規則的間距:印刷文字的字母間距一致。 手寫筆劃間的間距和字母連接有很大的差異。 這會造成不正確的字元分割,如 ununiformed 分割成個別字元 (u n u n i f o c m e d) 而非單一字元所示。

筆劃變化: 每個人都有獨特的筆跡,每個人每次書寫同一個字母的方式都不同。字母的連接和模式也有顯著的差異。 這可以避免"一刀切"的模式,因為引擎必須處理筆劃斜度、壓力和形狀的高變化性,使得模式匹配的可靠性比標準字型低。

模糊的字形:手寫字體經常使用簡化或匆忙的筆觸,造成模糊的字形。快速書寫的 e 可能與 c 相似,或者連接的 li 可能會被誤認。

品質與解析度問題:掃描品質差、解析度低或油墨褪色會嚴重影響辨識的準確性。 遇到此類問題時,請參閱我們的 一般疑難排解指南,以獲得解決方案。

使用此方法時,請確認輸出與預期的輸入相符,並特別注意間距較近或格式不佳的字詞。 考慮實施後處理邏輯,以處理特定於您的使用個案的常見錯誤辨識。

警告 ReadHandwriting 方法在處理草書時只能達到低準確度的 OCR 擷取。

常見問題解答

從影像中萃取手寫文字的精確度為何?

IronOCR 的 ReadHandwriting 方法在英文手寫辨識上達到約 90% 的準確度,儘管不規則的間距和筆劃變化是手寫 OCR 特別困難的固有挑戰。

手寫辨識支援哪些語言?

IronOCR 中的 ReadHandwriting 方法目前僅支援英文。對於多國語言的 OCR,您需要使用標準的 Read() 方法與適當的語言套件,而非專門的手寫方法。

手寫 OCR 需要安裝哪些額外套件?

若要使用 IronOCR 中的手寫辨識功能,除了 IronOCR 主程式庫之外,您必須安裝 IronOcr.Extensions.AdvancedScan 套件。

如何在 C# 中實現基本的手寫辨識功能?

建立 IronTesseract 範例,使用 LoadImage() 載入您的手寫圖像,呼叫 ReadHandwriting() 方法,並從 OcrResult 存取擷取的文字。IronOCR 會自動處理複雜的影像處理和機器學習。

可以處理哪些類型的手寫文件?

IronOCR 可處理各種手寫文件,包括歷史記錄、病人入院表、客戶調查問卷和手寫筆記。這個函式庫的設計是為了處理人類手寫筆跡不一致的問題,這些問題使得手寫處理容易出錯。

手寫辨識功能採用什麼技術?

IronOCR 的手寫辨識功能建構在強大的 Tesseract 5 引擎上,結合先進的影像處理與機器學習演算法,提供領先業界的手寫辨識能力。

Curtis Chau
技術撰稿人

Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。

準備好開始了嗎?
Nuget 下載 5,384,824 | 版本: 2026.2 剛剛發布