如何使用 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访问提取的文本
  1. 使用 NuGet 包管理器安装 https://www.nuget.org/packages/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 阅读手写图像?

using IronOCR 阅读手写图像非常简单。 首先实例化OCR引擎,然后用ReadHandwriting方法。 打印提取的文本以验证准确性和内容。

在处理之前,请考虑应用图像质量校正过滤器以提高可读性。 这些过滤器可以大大提高识别准确性,尤其是对于对比度或分辨率较差的扫描文档。

我应该使用什么输入格式?

手写输入图像样本,显示用于 OCR 处理的草书文本
: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)
$vbLabelText   $csharpLabel

我可以期待什么结果?

OCR 输出结果显示提取的手写文本和置信度分数

ReadHandwriting方法实现了90.6%的可信度分数,正确识别了大部分文字,包括开头短语"我叫Erin Fish。"

这个出色的结果展示了 IronOCR 处理具有挑战性的手写脚本的能力。 虽然引擎在间距和字母连接方面遇到了困难,但还是成功提取了核心信息。 这表明 IronOCR 能有效处理复杂、非标准的文本。

对于 OCR 的新手,请从我们的简单 OCR 教程开始,先了解基础知识,然后再处理手写识别。

如何使用异步版本?

IronOCR支持异步版本:ReadHandwritingAsync。 这在处理需要在处理前获取输入图像的异步代码时非常有用。 async 支持文档为实现异步 OCR 操作提供了全面的指导。

使用相同的输入,下面介绍如何使用 async 方法:

:path=/static-assets/ocr/content-code-examples/how-to/read-handwritten-image-async.cs
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
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'.
        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
$vbLabelText   $csharpLabel

您可以提供一个可选的timeoutMs参数,以指定在自动取消前的毫秒数。 默认值为-1,意味着没有时间限制——操作会一直运行直到完成。

高级处理技术

对于复杂的手写识别场景,可以考虑使用这些高级技术:

特定区域 OCR:在处理表单或结构化文档时,使用 基于区域的 OCR 专注于包含手写文本的特定区域。 这种方法通过限制处理区域来提高准确性:

:path=/static-assets/ocr/content-code-examples/how-to/read-handwritten-image-4.cs
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),而非单个单词。

笔画变化:每个人的笔迹都是独一无二的,每个人每次书写同一个字母的方式也不尽相同。字母的连接和模式也大不相同。 这就避免了 "一刀切 "的模式,因为引擎必须处理笔划斜度、压力和形式的高变化性,从而使模式匹配的可靠性低于标准化字体。

模糊字符形状:手写体通常使用简化或急促的笔画,导致模糊的形状。快速书写的i可能被误识别。

质量和分辨率问题:扫描质量差、分辨率低或墨迹褪色会严重影响识别准确性。 遇到此类问题时,请参阅我们的一般故障排除指南了解解决方案。

使用这种方法时,要验证输出是否与预期输入相匹配,特别要注意间距较近或词形不清的词语。 考虑实施后处理逻辑,以处理针对您的使用案例的常见错误识别。

[[w: (当涉及到草书时,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 引擎,结合了先进的图像处理和机器学习算法,提供业界领先的手写识别能力。

IronOCR可以集成到现有应用程序中吗?

IronOCR设计为易于使用C#集成到现有应用程序中,允许开发人员以最小的努力为他们的软件添加OCR功能。

使用IronOCR进行文档管理有什么好处?

使用IronOCR进行文档管理可以通过将扫描的文档转换为可搜索和可编辑文本来简化工作流程,减少手动数据输入的需要,提高文档可访问性。

IronOCR如何提高数据准确性?

IronOCR通过其高级识别算法和图像校正功能提高数据准确性,确保文本提取过程既可靠又精确。

IronOCR 有免费试用版吗?

是的,Iron Software 提供IronOCR 的免费试用,使用户在做出购买决定之前可以测试其功能和能力。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 6,151,372 | 版本: 2026.7 刚刚发布
Still Scrolling Icon

还在滚动吗?

想快速获得证据? PM > Install-Package IronOcr
运行示例 观看您的图像变成可搜索文本。