原創|行業資訊|編輯:郝浩|2013-10-24 09:27:53.000|閱讀 1105 次
概述:移動圖像開發包LEADTOOLS iOS and OS X imaging SDK提供了創建跨平臺移動圖像應用的所有功能,如查看器、注釋、標記、OCR、條形碼、PDF、圖像格式、壓縮和圖像處理等。 本文主要展示如何利用LEADTOOLS iOS庫的OCR功能識別文本并從圖像中讀取條碼。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
移動圖像開發包LEADTOOLS iOS and OS X imaging SDK提供了創建跨平臺移動圖像應用的所有功能,如查看器、注釋、標記、OCR、條形碼、PDF、圖像格式、壓縮和圖像處理等。 本文主要展示如何利用LEADTOOLS iOS庫的OCR功能識別文本并從圖像中讀取條碼。
獲得LEADTOOLS圖像
LEADTOOLS iOS庫通過 LTRasterImage對象顯示和處理圖像。幸運的是,LEADTOOLS只需要幾行代碼便可輕松地實現與iOS的互操作。
// Obtain the image from bundle, photo library or live capture UIImage* uiImage = ... // Convert UIImage to LTRasterImage using default options LTRasterImage* rasterImage = [LTRasterImageConverter convertFromImage:uiImage options:LTConvertFromImageOptions_None error:nil];
獲取圖像后,接下使用LEADTOOLS 所提供的先進的OCR和Barcode成像技術。
OCR示例
首先,創建一個LEADTOOLS OCR引擎實例。
// Create an instance of LEADTOOLS OCR engine LTOcrEngine* ocrEngine = [LTOcrEngineManager createEngine:LTOcrEngineType_Advantage]; // Start up the engine with default parameters... // We already added the OCR engine required language data files to the main bundle NSString* bundlePath = [[NSBundle mainBundle] bundlePath]; [ocrEngine startup:nil workDirectory:nil startupParameters:bundlePath]; // Optionally, modify the settings for the OCR engine // here (through ocrEngine.settingsManager)
接下來,我們創建一個新的OCR文檔并添加圖像:
// First create a document LTOcrDocument* ocrDocument = [ocrEngine.documentManager createDocument]; // Add the image as a page into the document pages collection LTOcrPage* ocrPage = [ocrDocument.pages addPageWithImage:rasterImage target:nil selector:nil error:nil]; // You can add manual zones (text or graphics area) // to the page at this point through the ocrPage.zones collection. // In this example we will let the engine auto-zone the page for us.
最后,識別頁面獲取文本。
// Recognize it and print the results to the console NSString* result = [ocrPage recognizeText:nil selector:nil error:nil]; printf("%s\n", result.UTF8String);
Barcode示例
首先,創建一個LEADTOOLS Barcode引擎實例。
// Create an instance of LEADTOOLS barcode engine LTBarcodeEngine* barcodeEngine = [LTBarcodeEngine new]; // Get the barcode reader object LTBarcodeReader* barcodeReader = barcodeEngine.reader; // At this point, you can modify the barcode reading // options (such as search direction, error checking, etc.) // through the barcodeReader members. In this example we // will leave everything as default.
接下來,我們將設置一些搜索選項,然后從圖像中讀取條形碼。
// Read the barcode in the image, first lets setup the options: // The search location and size in the image, all of it LeadRect searchBounds = LeadRect_Empty(); // Symbologies (barcode types such as UPC-A, UPC-E, // QR, etc.) we are interested in, all of them LTBarcodeSymbology* symbologies = nil; // Call readBarcode LTBarcodeData* barcodeData = [barcodeReader readBarcode:rasterImage searchBounds:searchBounds symbologies:symbologies symbologiesCount:0 error:nil];
LTBarcodeData對象包含條碼信息,如類型,價值和位置等。有了這些信息,你可以實現在線搜索價格或者訪問條碼中所嵌入的Web頁面。
if (barcodeData != nil) { // We have a barcode // Get the name of the symbology (type) such as UPC-A, // UPC-E, QR, EAN, etc. NSString* symbology = [LTBarcodeEngine getSymbologyFriendlyName:barcodeData.symbology]; // Get the location in the image LeadRect bounds = barcodeData.bounds; // Get a text representation of the data NSString* value = barcodeData.value; // Print the result to the console NSString* result = [NSString stringWithFormat: @"Found %@ barcode at %d,%d,%d,%d\nData: %@", symbology, bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, value]; printf("%s\n", result.UTF8String); } else { printf("No barcode found\n"); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網