多语言展示
当前在线:805今日阅读:176今日分享:34

图像处理包LEADTOOLS 教程:OCR 和 Barcode识别

移动图像开发包LEADTOOLS iOS and OS X imaging SDK提供了创建跨平台移动图像应用的所有功能,如查看器、注释、标记、OCR、条形码、PDF、图像格式、压缩和图像处理等。 本文主要展示如何利用LEADTOOLS iOS库的OCR功能识别文本并从图像中读取条码。
工具/原料

LEADTOOLS iOS

方法/步骤
1

移动图像开发包LEADTOOLS iOS and OS X imaging SDK提供了创建跨平台移动图像应用的所有功能,如查看器、注释、标记、OCR、条形码、PDF、图像格式、压缩和图像处理等。 本文主要展示如何利用LEADTOOLS iOS库的OCR功能识别文本并从图像中读取条码。

2

获得LEADTOOLS图像LEADTOOLS iOS库通过 LTRasterImage对象显示和处理图像。幸运的是,LEADTOOLS只需要几行代码便可轻松地实现与iOS的互操作。// Obtain the image from bundle, photo library or live captureUIImage* uiImage = ...// Convert UIImage to LTRasterImage using default optionsLTRasterImage* rasterImage = [LTRasterImageConverter convertFromImage:uiImageoptions:LTConvertFromImageOptions_Noneerror:nil];获取图像后,接下使用LEADTOOLS 所提供的先进的OCR和Barcode成像技术。

3

OCR示例首先,创建一个LEADTOOLS OCR引擎实例。// Create an instance of LEADTOOLS OCR engineLTOcrEngine* 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 bundleNSString* 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 documentLTOcrDocument* ocrDocument = [ocrEngine.documentManager createDocument]; // Add the image as a page into the document pages collectionLTOcrPage* ocrPage = [ocrDocument.pages addPageWithImage:rasterImagetarget:nilselector:nilerror: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 consoleNSString* result = [ocrPage recognizeText:nilselector:nilerror:nil];printf('%s\n', result.UTF8String);

4

Barcode示例首先,创建一个LEADTOOLS Barcode引擎实例。// Create an instance of LEADTOOLS barcode engineLTBarcodeEngine* barcodeEngine = [LTBarcodeEngine new]; // Get the barcode reader objectLTBarcodeReader* 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 itLeadRect searchBounds = LeadRect_Empty(); // Symbologies (barcode types such as UPC-A, UPC-E,// QR, etc.) we are interested in, all of themLTBarcodeSymbology* symbologies = nil; // Call readBarcodeLTBarcodeData* barcodeData = [barcodeReader readBarcode:rasterImagesearchBounds:searchBoundssymbologies:symbologiessymbologiesCount:0error: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 imageLeadRect bounds = barcodeData.bounds;// Get a text representation of the dataNSString* value = barcodeData.value; // Print the result to the consoleNSString* 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');}

推荐信息