Introduction
LEADTOOLS, the world’s leading imaging SDK for Windows, WinRT and HTML5, has released Version 18. The most exciting new feature in Version 18 is LEADTOOLS Anywhere™, which is its award-winning imaging technology ported to multiple platforms including WinRT, iOS, OS X, Android and Linux.
The advanced iOS and OS X imaging SDK technology in LEADTOOLS includes everything developers need to build image-enabled applications for Apple iPhone, iPad and Macintosh. Viewers, annotations and markup, OCR, barcode, PDF, image formats, compression, image processing and more are just a sampling of what LEADTOOLS has to offer developers creating software for the increasingly popular Apple platforms.
Key iOS & OS X Features in LEADTOOLS SDKs
-
Universal frameworks targeting iPhone, iPad and Mac
-
Xcode 3.2 and later
-
iOS 4 and later
-
OS X Lion (10.7) and later
-
Comprehensive and easy to use Objective-C class library that
closely resembles other LEADTOOLS libraries such as .NET and Android
-
Load, convert and save more than 150 image formats
-
Advanced bit depth, color space and compression support for
common formats including PDF, PDF/A, JPEG, JPEG 2000, TIFF, JBIG2 and more
-
Interactive image viewers
-
Touch screen enabled interactive modes
-
Retina display optimizations for incredible image quality
-
Quickly process images using built-in image manipulation
-
Display images based on physical and logical units
-
Over 200 Image processing functions for enhancing, correcting and
manipulating images
-
Comprehensive Annotation and Markup including geometric shapes,
sticky note, redact, highlight and rubber stamp
-
OCR to convert images to searchable text
-
Barcode reading and writing for QR, PDF417, Data Matrix, UPC/EAN
and more
An iOS
Example: OCR and Barcode
In this article, we’ll show how to use LEADTOOLS’ new iOS
libraries to recognize text with OCR and read barcodes from an image.
Obtaining a LEADTOOLS Image
The object that defines an image in iOS is the
standard UIImage
(or the low level CGImage
).
You can obtain an image in your app through a variety of ways:
-
Load the image directly from the app bundle
-
Browse the device’s photo library
-
Live capture through the device’s camera
LEADTOOLS libraries use the LTRasterImage
object for all of its image display and processing. Fortunately, LEADTOOLS
makes it easy to interoperate with iOS by providing its conversion utilities which
only require a couple lines of code:
UIImage* uiImage = ...
LTRasterImage* rasterImage = [LTRasterImageConverter convertFromImage:uiImage
options:LTConvertFromImageOptions_None
error:nil];
Now that we have an image, we can utilize the advanced imaging
technology offered by LEADTOOLS, such as OCR and Barcode.
OCR Example
First, we need an instance of the LEADTOOLS OCR engine:
LTOcrEngine* ocrEngine = [LTOcrEngineManager createEngine:LTOcrEngineType_Advantage];
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
[ocrEngine startup:nil workDirectory:nil startupParameters:bundlePath];
Next, we create a new OCR document and add our image as a
page:
LTOcrDocument* ocrDocument = [ocrEngine.documentManager createDocument];
LTOcrPage* ocrPage = [ocrDocument.pages addPageWithImage:rasterImage
target:nil
selector:nil
error:nil];
And finally, recognize the page and get the text:
NSString* result = [ocrPage recognizeText:nil
selector:nil
error:nil];
printf("%s\n", result.UTF8String);
LEADTOOLS also provides additional low level control for
advanced custom processing. For example, you can obtain the resulting
characters and words along with their location, font properties and confidence
level information:
[ocrPage recognize:nil selector:nil error:nil];
LTOcrPageCharacters* pageCharacters = [ocrPage getRecognizedCharacters:nil];
for (LTOcrZoneCharacters* zoneCharacters in pageCharacters)
{
NSArray* words = [zoneCharacters getWords];
for (LTOcrWord* word in words)
{
printf("Word: %s at %d,%d,%d,%d\n",
word.value.UTF8String,
word.bounds.x,
word.bounds.y,
word.bounds.x + word.bounds.width,
word.bounds.y + word.bounds.height);
}
}
Barcode Example
Just as we started for OCR, we must first create an instance
of the LEADTOOLS Barcode engine:
LTBarcodeEngine* barcodeEngine = [LTBarcodeEngine new];
LTBarcodeReader* barcodeReader = barcodeEngine.reader;
Next we set some searching options and then read the
barcode(s) from the image. It is possible to narrow down the search to
specific barcode types or areas of the image, but for this example we simply search
the entire image for any type of barcode:
LeadRect searchBounds = LeadRect_Empty();
LTBarcodeSymbology* symbologies = nil;
LTBarcodeData* barcodeData = [barcodeReader readBarcode:rasterImage
searchBounds:searchBounds
symbologies:symbologies
symbologiesCount:0
error:nil];
The LTBarcodeData
object contains
information about the barcode found, such its type, value, location and more. Armed
with this information, your creativity can take off to produce spectacular apps
for customers to use on their devices. For example, you can perform a price-checking
web search on the product, or go to the web page embedded in the barcode. In
this example, we will just print the barcode data to the console:
if (barcodeData != nil)
{
NSString* symbology = [LTBarcodeEngine getSymbologyFriendlyName:barcodeData.symbology];
LeadRect bounds = barcodeData.bounds;
NSString* value = barcodeData.value;
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");
}
Download the Full iOS and OS X Examples
You can download a fully functional demo which includes the
features discussed above. To run these examples you will need the following:
Support
Need help getting this sample up and going? Contact
our support team for free technical support! For pricing or licensing
questions, you can contact our sales team (sales@leadtools.com)
or call us at 704-332-5532.