如何使用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 通过引入一种专门的方法来可靠地理解和数字化手写图像,从而解决了这一问题。 基于强大的Tesseract 5引擎,IronOCR结合了先进的图像处理和机器学习技术,以提供可靠的手写识别能力。
本指南将逐步指导您在 .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。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。