原創(chuàng)|行業(yè)資訊|編輯:郝浩|2013-10-24 09:27:53.000|閱讀 1105 次
概述:移動(dòng)圖像開(kāi)發(fā)包LEADTOOLS iOS and OS X imaging SDK提供了創(chuàng)建跨平臺(tái)移動(dòng)圖像應(yīng)用的所有功能,如查看器、注釋、標(biāo)記、OCR、條形碼、PDF、圖像格式、壓縮和圖像處理等。 本文主要展示如何利用LEADTOOLS iOS庫(kù)的OCR功能識(shí)別文本并從圖像中讀取條碼。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
移動(dòng)圖像開(kāi)發(fā)包LEADTOOLS iOS and OS X imaging SDK提供了創(chuàng)建跨平臺(tái)移動(dòng)圖像應(yīng)用的所有功能,如查看器、注釋、標(biāo)記、OCR、條形碼、PDF、圖像格式、壓縮和圖像處理等。 本文主要展示如何利用LEADTOOLS iOS庫(kù)的OCR功能識(shí)別文本并從圖像中讀取條碼。
獲得LEADTOOLS圖像
LEADTOOLS iOS庫(kù)通過(guò) LTRasterImage對(duì)象顯示和處理圖像。幸運(yùn)的是,LEADTOOLS只需要幾行代碼便可輕松地實(shí)現(xiàn)與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 所提供的先進(jìn)的OCR和Barcode成像技術(shù)。
OCR示例
首先,創(chuàng)建一個(gè)LEADTOOLS OCR引擎實(shí)例。
// 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)
接下來(lái),我們創(chuàng)建一個(gè)新的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.
最后,識(shí)別頁(yè)面獲取文本。
// Recognize it and print the results to the console NSString* result = [ocrPage recognizeText:nil selector:nil error:nil]; printf("%s\n", result.UTF8String);
Barcode示例
首先,創(chuàng)建一個(gè)LEADTOOLS Barcode引擎實(shí)例。
// 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.
接下來(lái),我們將設(shè)置一些搜索選項(xiàng),然后從圖像中讀取條形碼。
// 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對(duì)象包含條碼信息,如類(lèi)型,價(jià)值和位置等。有了這些信息,你可以實(shí)現(xiàn)在線(xiàn)搜索價(jià)格或者訪(fǎng)問(wèn)條碼中所嵌入的Web頁(yè)面。
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"); }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)