原創(chuàng)|使用教程|編輯:郝浩|2013-09-29 09:55:28.000|閱讀 888 次
概述:LEADTOOLS v18的全新設(shè)計(jì)極大地簡(jiǎn)化了開(kāi)發(fā)而無(wú)需犧牲控制力。LEADTOOLS v18增強(qiáng)了其用于光學(xué)字符識(shí)別的.Net類。LEADTOOLS的架構(gòu)靈活、直觀而且易于使用。開(kāi)發(fā)人員僅通過(guò)三行代碼就可以實(shí)現(xiàn)圖像的OCR功能。本文接下來(lái)將著重介紹全新的LEADTOOLS .NET OCR 類,以及展示如何創(chuàng)建一個(gè)OCR程序。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
LEADTOOLS v18的全新設(shè)計(jì)極大地簡(jiǎn)化了開(kāi)發(fā)而無(wú)需犧牲控制力。LEADTOOLS v18增強(qiáng)了其用于光學(xué)字符識(shí)別的.Net類。LEADTOOLS的架構(gòu)靈活、直觀而且易于使用。開(kāi)發(fā)人員僅通過(guò)三行代碼就可以實(shí)現(xiàn)圖像的OCR功能。本文接下來(lái)將著重介紹全新的LEADTOOLS .NET OCR 類,以及展示如何創(chuàng)建一個(gè)OCR程序。
LEADTOOLS OCR .NET類庫(kù)提供了Win32 和 x64 版本,適用于下列開(kāi)發(fā)環(huán)境:
LEADTOOLS使用OCR手柄連接OCR引擎和包含在頁(yè)面列表中的OCR文檔。OCR手柄是LEADTOOLS OCR和OCR引擎之間的通信會(huì)話。OCR手柄是一個(gè)包含了識(shí)別、獲取/設(shè)置信息以及文本驗(yàn)證的所有必要信息的內(nèi)部結(jié)構(gòu)。
以下是識(shí)別單頁(yè)或者多文檔所涉及到的基本步驟:
1、選擇你想使用的引擎類型并創(chuàng)建一個(gè)IOcrEngine接口實(shí)例。
2、根據(jù)IOcrEngine.Startup方法啟動(dòng)OCR引擎。
3、創(chuàng)建一個(gè)OCR文檔。
4、手動(dòng)或者自動(dòng)創(chuàng)建頁(yè)面區(qū)域。(該步驟為可選步驟)
5、設(shè)置OCR引擎所使用的活動(dòng)語(yǔ)言。(默認(rèn)為英語(yǔ))
6、設(shè)置拼寫(xiě)語(yǔ)言。(默認(rèn)為英語(yǔ))
7、設(shè)置任意特殊識(shí)別模塊選項(xiàng)。如果頁(yè)面包含區(qū)域,該步驟是必須的。
8、識(shí)別。
9、如果需要,可以保存識(shí)別結(jié)果。可將識(shí)別結(jié)果保存到一個(gè)文件或者內(nèi)存中。
10、關(guān)閉OCR引擎。
只要步驟4、5、6和7在啟動(dòng)OCR引擎后和完成識(shí)別前進(jìn)行都可以,而且可以不按照順序進(jìn)行。
添加引用到.Net程序的Leadtools.Forms.Ocr.dll 程序集中,以啟動(dòng)LEADTOOLS for .NET OCR。該程序集包含了各種接口、類和結(jié)構(gòu)。由于LEADTOOLS圖像開(kāi)發(fā)包提供了多引擎支持,因此 鏈接引擎的實(shí)際代碼被儲(chǔ)存在一個(gè)單獨(dú)的程序集中。因此,必須確保你打算用的引擎程序集位于Leadtools.Forms.Ocr.dll 程序集中。如果需要自動(dòng)檢測(cè)依賴性,你可以將引擎程序集作為引用添加到項(xiàng)目中。
下列代碼演示了如何執(zhí)行上次步驟:
Visual Basic
' *** 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) ' *** 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:\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.Enabled = True 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:\\Images\Document.pdf", OcrDocumentFormat.PdfA, Nothing) ocrDocument.Dispose() ' *** Step 10: Shut down the OCR engine when finished ocrEngine.Shutdown() ocrEngine.Dispose()
C#
// *** 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.Plus, false); // *** Step 2: Startup the engine. // Use the default parameters ocrEngine.Startup(null, null, null); // *** 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:\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.Enabled = true; 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:\Images\Document.pdf", OcrDocumentFormat.PdfA, null); ocrDocument.Dispose(); // *** Step 10: Shut down the OCR engine when finished ocrEngine.Shutdown(); ocrEngine.Dispose();
接下來(lái)的示例展示了如何利用IOcrAutoRecognizeManager執(zhí)行相同任務(wù),
Visual Basic
' Create the engine instance Using ocrEngine As IOcrEngine = _ OcrEngineManager.CreateEngine(OcrEngineType.Plus, False) ' Startup the engine ocrEngine.Startup(Nothing, Nothing, Nothing) ' Convert the multi-page TIF image to a PDF document ocrEngine.AutoRecognizeManager.Run( _ "C:\Images\Ocr.tif", _ "C:\Images\Document.pdf", _ Nothing, _ OcrDocumentFormat.PdfA, _ Nothing) End Using
C#
// Create the engine instance using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false)) { // Startup the engine ocrEngine.Startup(null, null, null); // Convert the multi-page TIF image to a PDF document ocrEngine.AutoRecognizeManager.Run( @"C:\Images\Ocr.tif", @"C:\Images\Document.pdf", null, OcrDocumentFormat.PdfA, null); }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)