如何使用 IronOCR 讀取手寫影像
IronOCR 提供專用的 ReadHandwriting 方法,能可靠地將圖像中的手寫文字數位化,儘管面臨間距不規則與筆畫變異等固有挑戰,其英文手寫辨識準確度仍可達約 90%。
快速入門:使用 IronOCR 讀取手寫影像
- 安裝 IronOCR 及
IronOcr.Extensions.AdvancedScan套件 - 建立一個
IronTesseract實例 - 使用
LoadImage()載入您的手寫圖像 - 呼叫
ReadHandwriting()方法 - 從
OcrResult存取擷取的文字
-
using NuGet 套件管理員安裝 https://www.nuget.org/packages/IronOcr
PM > Install-Package IronOcr -
請複製並執行此程式碼片段。
using IronOcr; var ocrTesseract = new IronTesseract(); using var ocrInput = new OcrInput(); ocrInput.LoadImage("handwriting.png"); var ocrResult = ocrTesseract.ReadHandwriting(ocrInput); Console.WriteLine(ocrResult.Text); -
部署至您的生產環境進行測試
立即透過免費試用,在您的專案中開始使用 IronOCR
由於人們的書寫方式各不相同,因此從圖像中自動辨識手寫文字極具挑戰性。 這種大規模的不一致性使得 OCR 處理極具挑戰性。 諸如舊紀錄、病患登記表及客戶問卷等關鍵文件,仍需人工處理,導致工作流程容易出錯,進而危及資料完整性。
IronOCR 透過引入一種專門的方法,能可靠地識別並數位化手寫影像,從而解決此問題。 IronOCR 基於強大的 Tesseract 5 引擎打造,結合先進的影像處理與機器學習技術,提供業界領先的手寫辨識能力。
本指南將逐步引導您在 .NET 應用程式中實作手寫 OCR。無論您是將歷史文件數位化、處理醫療表格,還是轉換手寫筆記,您都將學會如何透過 IronOCR 獲得可靠的結果。
開始使用 IronOCR
如何使用 IronOcr 讀取手寫影像
- 下載用於讀取手寫圖像的 C# 函式庫
- 實例化 OCR 引擎
- 使用
LoadImage載入手寫圖像 - 使用
ReadHandwriting方法從範例手寫圖像中提取資料 - 透過存取 OcrResult 屬性來檢視及處理已擷取的資料
若要使用此功能,您必須先安裝 IronOcr.Extensions.AdvancedScan 套件。 請注意,ReadHandwriting 方法目前僅支援英文。 若需進行多語言 OCR 處理,請使用標準的 Read() 方法並搭配適當的語言套件。
如何使用 IronOCR 讀取手寫影像?
使用 IronOCR 讀取手寫圖像非常簡單。 首先建立 OCR 引擎的實例,接著使用 LoadImage 載入影像,最後使用專為手寫辨識設計的 ReadHandwriting 方法。 請將提取的文字列印出來以驗證其準確性與內容。
處理前,請考慮套用影像品質修正濾鏡以提升可讀性。 這些濾鏡能顯著提升辨識準確度,特別是針對對比度或解析度不佳的掃描文件。
我應該使用哪種輸入格式?
:path=/static-assets/ocr/content-code-examples/how-to/read-handwritten-image.cs
using IronOcr;
using System;
// 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
Imports System
' 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)
我可以期待什麼樣的成果?
ReadHandwriting 方法獲得 90.6% 的信心分數,正確識別了大部分文字,包括開頭的句子"My name is Erin Fish."
這項優異的成果充分展現了 IronOCR 處理高難度手寫字體的能力。 雖然翻譯引擎在處理空格和連字時遇到困難,但成功提取了核心訊息。 這顯示 IronOCR 能有效處理複雜且非標準的文字。
對於 OCR 新手,建議先從我們的簡易 OCR 教學開始,在處理手寫辨識之前先掌握基礎知識。
如何使用 Async 版本?
IronOCR 支援非同步版本:ReadHandwritingAsync。 這在處理需要先擷取輸入圖片再進行處理的異步程式碼時非常有用。 《非同步支援文件》提供了關於實作非同步 OCR 操作的全面指引。
使用相同的輸入,以下是使用 async 方法的方式:
:path=/static-assets/ocr/content-code-examples/how-to/read-handwritten-image-async.cs
using IronOcr;
using System;
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
#endregion
public class read_handwritten_image_async
{
public async Task codeAsync()
{
// 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
Imports System.Threading.Tasks
Public Class ReadHandwrittenImageAsync
Public Async Function CodeAsync() As Task
' 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 Task Main()' 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)
End Function
End Class
您可以選填 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
進度追蹤:針對多份手寫文件的批次處理,請實作進度追蹤功能以監控 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
我應注意哪些挑戰?
儘管 IronOCR 在保留整體結構與文字方面表現出色,但 OCR 技術在處理手寫文字時仍存在困難,導致局部出現錯誤。 常見的挑戰在於需驗證提取的輸出結果:
不規則間距:PRINT文字的字母間距應保持均勻。 手寫字體在筆畫間距與字母連接方面差異極大。 這會導致字元分割錯誤,例如 ununiformed 被分割成個別字元(u n u n i f o c m e d),而非一個WORD。
筆畫變化:每個人的筆跡都是獨一無二的,即使寫同一個字母,每次的寫法也會有所不同。字母的連接方式與筆畫模式存在顯著差異。 這避免了"一刀切"的模式,因為引擎必須處理筆畫傾斜度、筆壓和字形的高變異性,使得模式比對的可靠性不如標準化字體。
字形模糊:手寫字常因簡化或倉促的筆畫而產生模糊的字形。快速書寫的 e 可能與 c 相似,或連筆書寫的 l 和 i 可能被誤判。
品質與解析度問題:掃描品質不佳、解析度過低或墨跡褪色,都會顯著影響辨識準確度。 若遇到此類問題,請參閱我們的通用疑難排解指南以獲取解決方案。
使用此方法時,請確認輸出結果與預期輸入相符,並特別注意字距過近或格式不當的WORD。 請考慮實作後處理邏輯,以處理您特定使用情境中常見的辨識錯誤。
ReadHandwriting 方法在處理連筆字時,僅能實現低精度的 OCR 擷取。 常見問題
從圖片中擷取手寫文字時,可以期待達到怎樣的準確度?
儘管手寫 OCR 因字距不規則及筆畫變化等固有挑戰而格外困難,IronOCR 的 ReadHandwriting 方法在英文手寫辨識方面仍能達到約 90% 的準確度。
手寫辨識支援哪些語言?
IronOCR 中的 ReadHandwriting 方法目前僅支援英文。若需進行多語言 OCR,請使用標準的 Read() 方法並搭配適當的語言套件,而非專用的手寫辨識方法。
進行手寫 OCR 時,我還需要安裝哪些額外套件?
若要使用 IronOCR 中的手寫辨識功能,除主要 IronOCR程式庫外,還必須安裝 IronOcr.Extensions.AdvancedScan 套件。
如何在 C# 中實作基礎手寫辨識功能?
建立 IronTesseract 實例,使用 LoadImage() 載入手寫影像,呼叫 ReadHandwriting() 方法,並從 OcrResult 取得擷取的文字。IronOCR 會自動處理複雜的影像處理與機器學習工作。
哪些類型的手寫文件可以進行處理?
IronOCR 可處理各種手寫文件,包括歷史紀錄、病患登記表、客戶問卷及手寫筆記。IronOCR程式庫專為處理人類手寫字跡的不一致性而設計,此類不一致性往往導致人工處理容易出錯。
手寫辨識功能採用何種技術驅動?
IronOCR 的手寫辨識功能建構於強大的 Tesseract 5 引擎之上,結合先進的影像處理技術與機器學習演算法,提供業界領先的手寫辨識能力。
IronOCR 能否整合至現有應用程式中?
IronOCR 設計上可輕鬆透過 C# 整合至現有應用程式中,讓開發人員能以最少的努力,為其軟體增添 OCR 功能。
使用 IronOCR 進行文件管理有哪些好處?
使用 IronOCR 進行文件管理,可將掃描文件轉換為可搜尋且可編輯的文字,從而簡化工作流程,減少人工資料輸入的需求,並提升文件的可存取性。
IronOCR 如何提升資料準確性?
IronOCR 透過其先進的辨識演算法與影像校正功能來提升資料準確性,確保文字擷取過程既可靠又精確。
IronOCR 是否有提供免費試用版?
是的,Iron Software 提供 IronOCR 的免費試用版,讓使用者能在決定購買前測試其功能與效能。

