LEADTOOLS入门教程:Leadtools .NET OCR用法

LEADTOOLS OCR功能提供了将光学字符识别(OCR)技术融合到应用程序中的方法。OCR可将位图图像转换为文本。

一旦在系统中安装LEADTOOLS .NET OCR工具包,用户便可以在程序中使用LEADTOOLS OCR。需要注意的是,在用户使用OCR属性,方法和事件之前,必须对OCR功能解锁。

用户可以添加引用到Leadtools.Forms.Ocr.dll和 Leadtools.Forms.DocumentWriter.dll组件从而启动LEADTOOLS for .NET OCR。这些组件包含了各种接口、类、结构和委托。

由于LEADTOOLS OCR工具包支持多个引擎,一旦创建了IOcrEngine接口实例,与引擎接口的实际代码便被存储在一个被动态加载的单独程序集中。因此,你必须确保即将使用的引擎程序集位于旁边的Leadtools.Forms.Ocr.dll组件。如果你需要自动检测依赖关系,你可以将引擎程序集作为引用添加到程序中。

LEADTOOLS提供了实现下列功能的方法:

  • 从各种文字、文字处理、数据库或者电子表格文档中识别和导出文本;
  • 在单线程或者多线程环境下执行OCR处理;
  • 选择需要识别的文档语言,如英语,丹麦语,荷兰语,芬兰语,法语,德语,意大利语,挪威语,葡萄牙语,俄语,西班牙语或瑞典语;
  • 自动或手动将复杂页面划分为文本区,图像区,表格区,线,页眉和页脚;
  • 识别前,设置精度阈值以控制识别精度;
  • 自动检测传真,点阵和其他degraded文档;
  • 支持多种文档保存格式,如Adobe PDF、 PDF/A, MS Word, MS Excel和UNICODE文本等等。
  • 处理文本和图形。

LEADTOOLS通过OCR手柄与OCR引擎和包含的页面列表的OCR文档进行交互。OCR手柄是安装在系统上的LEADTOOLS OCR和OCR引擎之间的通信会话。OCR手柄是一种内部结构,包含了识别、获取信息、设置信息和文本验证的所有必要信息。

识别单页或多页的步骤如下:

1、选择所需引擎类型并创建IOcrEngine接口实例;

2、利用 IOcrEngine.Startup方法启动OCR引擎;

3、简单单页或多页OCR文档;

4、手动或自动创建页面区域;

5、设置OCR引擎所需的活动语言;

6、设置拼写检查语言;

7、识别;

8、保存识别结果;

9、关闭OCR引擎。

步骤4,5,6和7可以不必依照顺序进行,只要在OCR引擎启动后和页面识别之间执行这几个步骤即可。

下面的示例展示了如何执行上述步骤:

Visual Basic

' Assuming you added "Imports Leadtools.Forms.Ocr" and "Imports Leadtools.Forms.DocumentWriter" at the beginning of this class
' *** Step 1: Select the engine type and create an instance of the IOcrEngine interface.
' We will use the LEADTOOLS OCR Plus engine and use it in the same process
Dim ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)

' *** Step 2: Startup the engine.

' Use the default parameters
ocrEngine.Startup(Nothing, Nothing, Nothing, "C:\LEADTOOLS 18\Bin\Common\OcrAdvantageRuntime")

' *** Step 3: Create an OCR document with one or more pages.

Dim ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()

' Add all the pages of a multi-page TIF image to the document
ocrDocument.Pages.AddPages("C:\Users\Public\Documents\LEADTOOLS Images\Ocr.tif", 1, -1, Nothing)

' *** Step 4: Establish zones on the page(s), either manually or automatically

' Automatic zoning
ocrDocument.Pages.AutoZone(Nothing)

' *** Step 5: (Optional) Set the active languages to be used by the OCR engine

' Enable English and German languages
ocrEngine.LanguageManager.EnableLanguages(New String() {"en", "de"})

' *** Step 6: (Optional) Set the spell checking language
' Enable the spell checking system and set English as the spell language
ocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.Native
ocrEngine.SpellCheckManager.SpellLanguage = "en"

' *** Step 7: (Optional) Set any special recognition module options

' Change the fill method for the first zone in the first page to be Omr
Dim ocrZone As OcrZone = ocrDocument.Pages(0).Zones(0)
ocrZone.FillMethod = OcrZoneFillMethod.Omr
ocrDocument.Pages(0).Zones(0) = ocrZone

' *** Step 8: Recognize

ocrDocument.Pages.Recognize(Nothing)

' *** Step 9: Save recognition results

' Save the results to a PDF file
ocrDocument.Save("C:\Users\Public\Documents\LEADTOOLS Images\Document.pdf", DocumentFormat.Pdf, Nothing)
ocrDocument.Dispose()

' *** Step 10: Shut down the OCR engine when finished
ocrEngine.Shutdown()
ocrEngine.Dispose()

C#

// Assuming you added "using Leadtools.Codecs;", "using Leadtools.Forms.Ocr;" and "using Leadtools.Forms.DocumentWriters;" at the beginning of this class
// *** Step 1: Select the engine type and create an instance of the IOcrEngine interface.

// We will use the LEADTOOLS OCR Plus engine and use it in the same process
IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);

// *** Step 2: Startup the engine.

// Use the default parameters
ocrEngine.Startup(null, null, null, @"C:\LEADTOOLS 18\Bin\Common\OcrAdvantageRuntime");

// *** Step 3: Create an OCR document with one or more pages.

IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument();

// Add all the pages of a multi-page TIF image to the document
ocrDocument.Pages.AddPages(@"C:\Users\Public\Documents\LEADTOOLS Images\Ocr.tif", 1, -1, null);

// *** Step 4: Establish zones on the page(s), either manually or automatically

// Automatic zoning
ocrDocument.Pages.AutoZone(null);

// *** Step 5: (Optional) Set the active languages to be used by the OCR engine

// Enable English and German languages
ocrEngine.LanguageManager.EnableLanguages(new string[] { "en", "de" });

// *** Step 6: (Optional) Set the spell checking language

// Enable the spell checking system and set English as the spell language
ocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.Native;
ocrEngine.SpellCheckManager.SpellLanguage = "en";

// *** Step 7: (Optional) Set any special recognition module options

// Change the fill method for the first zone in the first page to be default
OcrZone ocrZone = ocrDocument.Pages[0].Zones[0];
ocrZone.FillMethod = OcrZoneFillMethod.Default;
ocrDocument.Pages[0].Zones[0] = ocrZone;

// *** Step 8: Recognize

ocrDocument.Pages.Recognize(null);

// *** Step 9: Save recognition results

// Save the results to a PDF file
ocrDocument.Save(@"C:\Users\Public\Documents\LEADTOOLS Images\Document.pdf", DocumentFormat.Pdf, null);
ocrDocument.Dispose();

// *** Step 10: Shut down the OCR engine when finished
ocrEngine.Shutdown();
ocrEngine.Dispose();

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值