Install and use tesseract on iOS with tesseract-ios
Update 10/10/12
I updated tesseract-ios-lib
with a (fake) armv7s slice. There is no need to remove armv7s from build architectures anymore. More informations about this change on my previous post.
Introduction
In my last article about how to compile tesseract for iOS SDK 6, I quickly posted two links to my github repos:
- tesseract-ios: an Objective-C wrapper for tesseract
- tesseract-ios-lib: the tesseract library compiled for iOS (universal armv7/i386 library)
Some comments complained about the lack of guide to install and use this wrapper. I’m going to show you how to build a new iOS project with tesseract, from scratch.
Create the project
Create a simple Single View Application from XCode:
Name it whatever you want:
Project structure
Download tesseract-ios, tesseract-ios-lib, and your language trained data.
Then, open your project folder in Finder, and organise it like this:
Add “tesseract-ios” and “tesseract-ios-lib” in your project by creating groups:
Then, add “tessdata” by reference:
This step is extremely important, double check that you’re adding it by reference or your application will crash.
Project settings
Go to your project configuration, select your target, and click on “Build Settings”. Then, set the C++ compiler to default:
And set the build architecture to “armv7″ (instead of “armv7 armv7s”, as tesseract-ios-lib doesn’t contain an armv7s slice for now):
We’re ready to use tesseract.
Usage
Add an image called “image_sample.jpg” to your project.
Then, in ViewController.m
, add #import tesseract.h
and put the following lines in -viewDidLoad
:
1 2 3 4 5 | Tesseract* tesseract = [[Tesseract alloc] initWithDataPath:@"tessdata" language:@"eng"]; [tesseract setImage:[UIImage imageNamed:@"image_sample.jpg"]]; [tesseract recognize]; NSLog(@"%@", [tesseract recognizedText]); |
Methods reference is available on the project repo.
You should get the image-extracted text in your console.
Project code
You can download the tutorial source code right here: TesseractSample.