原創|使用教程|編輯:郝浩|2013-09-29 09:55:28.000|閱讀 888 次
概述:LEADTOOLS v18的全新設計極大地簡化了開發而無需犧牲控制力。LEADTOOLS v18增強了其用于光學字符識別的.Net類。LEADTOOLS的架構靈活、直觀而且易于使用。開發人員僅通過三行代碼就可以實現圖像的OCR功能。本文接下來將著重介紹全新的LEADTOOLS .NET OCR 類,以及展示如何創建一個OCR程序。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
LEADTOOLS v18的全新設計極大地簡化了開發而無需犧牲控制力。LEADTOOLS v18增強了其用于光學字符識別的.Net類。LEADTOOLS的架構靈活、直觀而且易于使用。開發人員僅通過三行代碼就可以實現圖像的OCR功能。本文接下來將著重介紹全新的LEADTOOLS .NET OCR 類,以及展示如何創建一個OCR程序。
LEADTOOLS OCR .NET類庫提供了Win32 和 x64 版本,適用于下列開發環境:
LEADTOOLS使用OCR手柄連接OCR引擎和包含在頁面列表中的OCR文檔。OCR手柄是LEADTOOLS OCR和OCR引擎之間的通信會話。OCR手柄是一個包含了識別、獲取/設置信息以及文本驗證的所有必要信息的內部結構。
以下是識別單頁或者多文檔所涉及到的基本步驟:
1、選擇你想使用的引擎類型并創建一個IOcrEngine接口實例。
2、根據IOcrEngine.Startup方法啟動OCR引擎。
3、創建一個OCR文檔。
4、手動或者自動創建頁面區域。(該步驟為可選步驟)
5、設置OCR引擎所使用的活動語言。(默認為英語)
6、設置拼寫語言。(默認為英語)
7、設置任意特殊識別模塊選項。如果頁面包含區域,該步驟是必須的。
8、識別。
9、如果需要,可以保存識別結果。可將識別結果保存到一個文件或者內存中。
10、關閉OCR引擎。
只要步驟4、5、6和7在啟動OCR引擎后和完成識別前進行都可以,而且可以不按照順序進行。
添加引用到.Net程序的Leadtools.Forms.Ocr.dll 程序集中,以啟動LEADTOOLS for .NET OCR。該程序集包含了各種接口、類和結構。由于LEADTOOLS圖像開發包提供了多引擎支持,因此 鏈接引擎的實際代碼被儲存在一個單獨的程序集中。因此,必須確保你打算用的引擎程序集位于Leadtools.Forms.Ocr.dll 程序集中。如果需要自動檢測依賴性,你可以將引擎程序集作為引用添加到項目中。
下列代碼演示了如何執行上次步驟:
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();
接下來的示例展示了如何利用IOcrAutoRecognizeManager執行相同任務,
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); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網