如何使用IronOCR讀取手寫影像
IronOCR提供一種專門的ReadHandwriting方法,能夠可靠地將圖片中的手寫文字數位化,儘管面臨不規則間距和筆劃變化的挑戰,仍能對清晰的英文手寫字提供強而有力的結果。
- 安裝IronOCR和
IronOcr.Extensions.AdvancedScan套件 - 建立一個
IronTesseract實例 - 使用
LoadImage()加載您的手寫圖片 - 呼叫
ReadHandwriting()方法 - 從
OcrResult中獲取提取的文字
-
1使用 IronOCR 安裝 NuGet Package Manager
-
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);Imports IronOcr Dim ocrTesseract = New IronTesseract() Using ocrInput = New OcrInput() ocrInput.LoadImage("handwriting.png") Dim ocrResult = ocrTesseract.ReadHandwriting(ocrInput) Console.WriteLine(ocrResult.Text) End UsingImports IronOcr Dim ocrTesseract = New IronTesseract() Using ocrInput = New OcrInput() ocrInput.LoadImage("handwriting.png") Dim ocrResult = ocrTesseract.ReadHandwriting(ocrInput) Console.WriteLine(ocrResult.Text) End Using -
3部署到您的生產環境進行測試
立即在您的項目中開始使用 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方法。 列印擷取的文字以驗證正確性與內容。
在處理之前,考慮應用影像質量校正過濾器以提高可讀性。 這些濾鏡可以顯著提高辨識準確度,特別是對於對比度或解析度較差的掃描文件。
我應該使用什麼輸入格式?

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);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)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教程開始,以在嘗試手寫識別之前了解基礎知識。
如何使用異步版本?
IronOCR支持異步版本:ReadHandwritingAsync。 這在處理需要在處理前取得輸入影像的異步程式碼時非常有用。 異步支援文檔提供實施異步OCR操作的全面指南。
使用相同的輸入,以下是如何使用 async 方法:
using IronOcr;
using System;
using System.Threading.Tasks;
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'.
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);
}
}using IronOcr;
using System;
using System.Threading.Tasks;
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'.
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
Public Class read_handwritten_image_async
Public Async Function codeAsync() As Task
' Instantiate OCR engine
Dim ocr = New IronTesseract()
' Load handwriting image
Dim inputHandWriting = New OcrInput()
inputHandWriting.LoadImage("handwritten.png")
' Perform OCR using the async method with 'await'.
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 ClassImports IronOcr
Imports System
Public Class read_handwritten_image_async
Public Async Function codeAsync() As Task
' Instantiate OCR engine
Dim ocr = New IronTesseract()
' Load handwriting image
Dim inputHandWriting = New OcrInput()
inputHandWriting.LoadImage("handwritten.png")
' Perform OCR using the async method with 'await'.
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;
using System;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
// Define a specific region for signature area
var signatureRegion = new Rectangle(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;
using System;
var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();
// Define a specific region for signature area
var signatureRegion = new Rectangle(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
Imports System
Dim ocrTesseract = New IronTesseract()
Using ocrInput = New OcrInput()
' Define a specific region for signature area
Dim signatureRegion = New Rectangle(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 UsingImports IronOcr
Imports IronSoftware.Drawing
Imports System
Dim ocrTesseract = New IronTesseract()
Using ocrInput = New OcrInput()
' Define a specific region for signature area
Dim signatureRegion = New Rectangle(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 SubocrTesseract.OcrProgress += Sub(sender, e)
Console.WriteLine($"Processing: {e.ProgressPercent}% complete")
End Sub我應該注意哪些挑戰?
雖然 IronOCR 在保留整體結構和文字方面達到了很高的置信度,但 OCR 在處理手寫文字時仍有困難,導致局部錯誤。 常見的挑戰需要對提取的輸出進行驗證:
不規則間距:印刷文本的字母之間具有均勻的間距。 手寫筆劃間的間距和字母連接有很大的差異。 這會導致錯誤的字符分割,如當ununiformed分成單個字符(u n u n i f o c m e d)而非單字時所示。
筆劃變化:每個人的筆跡獨具特色,且個人每次書寫相同字母也略有不同。字母連接和模式差異顯著。 這可以避免「一刀切」的模式,因為引擎必須處理筆劃斜度、壓力和形狀的高變化性,使得模式匹配的可靠性比標準字型低。
模稜兩可的字形:手寫常常使用簡化或匆忙的筆劃,形成模糊的字形。快速寫出的e可能像c,或連接的l和i可能被誤辨。
質量和解析度問題:掃描質量差、解析度低或墨水褪色會嚴重影響識別準確性。 遇到此類問題時,請參考我們的常規疑難排解指南以尋求解決方案。
使用此方法時,請確認輸出與預期的輸入相符,並特別注意間距較近或格式不佳的字詞。 考慮實施後處理邏輯,以處理特定於您的使用個案的常見錯誤辨識。
ReadHandwriting方法只能達到低準確度的OCR提取。常見問題
什麼是IronOCR的ReadHandwriting方法?
IronOCR的ReadHandwriting方法是一個專門的功能,能夠可靠地將影像中的手寫文字數位化,即使面對如不規則間距和筆畫變化等挑戰,對於清晰的英文手寫具有很強的效果。
如何在.NET應用程式中實現手寫OCR?
要實現手寫OCR,您需要安裝IronOCR,創建一個IronTesseract實例,使用LoadImage()載入您的手寫圖像,然後呼叫ReadHandwriting()方法來存取提取的文字。
IronOCR的手寫識別的典型應用是什麼?
IronOCR的手寫識別可以用於數位化歷史文件、處理醫療表單或轉換手寫筆記,以提高資料完整性並減少手動處理錯誤。
IronOCR可以處理品質不佳或解析度低的手寫圖像嗎?
是的,IronOCR可以更好地處理品質不佳或解析度低的圖像,通過使用圖像品質校正濾鏡來提高可讀性並改善識別精度。
IronOCR支援手寫多語言的識別嗎?
目前,ReadHandwriting方法僅支援英文手寫。若要進行多語言的OCR,您應使用標準的Read()方法並搭配適當的語言包。
IronOCR的手寫識別有多準確?
IronOCR的ReadHandwriting方法已經過測試,在識別具有挑戰性的英文手寫稿時報告約90.6%的信心,包括克服如間距和連寫等複雜性。
如何異步使用IronOCR進行手寫識別?
使用IronOCR,您可以利用ReadHandwritingAsync方法來異步進行OCR。在需要異步處理的場景中,這非常有用,您可以使用C#的async/await模式來處理操作。
使用IronOCR進行手寫OCR的某些高級技術是什麼?
高級技術包括針對表格或特定文件的區域特定OCR,以專注於手寫文字的部分進行處理,並實現批次處理的進度跟蹤。
OCR在手寫識別中常見的挑戰有哪些?
IronOCR面臨的挑戰包括不規則間距、筆劃變化、模糊的字元形狀和劣質的掃描品質,這些都可能影響OCR結果,需要對提取的文本進行驗證。
IronOCR如何應對手寫OCR的挑戰?
IronOCR通過結合高級圖像處理和機器學習技術來應對OCR的挑戰,以提高從圖像中識別和數位化手寫文本的可靠性。
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。