Home

Awesome

Tesseract for iOS

tesseract-ios is not actively maintained anymore. I encourage you to use gali8's Tesseract-OCR-iOS instead.

About

Tesseract-ios is an Objective-C wrapper for Tesseract OCR.

This project couldn't exist without the Ângelo Suzuki's blog post. A lot of code came from his article.

Requirements

Installation

Usage

Here is the default workflow to extract text from an image:

Code Sample

#import "Tesseract.h"

Tesseract* tesseract = [[Tesseract alloc] initWithDataPath:@"tessdata" language:@"eng"];
[tesseract setVariableValue:@"0123456789" forKey:@"tessedit_char_whitelist"];
[tesseract setImage:[UIImage imageNamed:@"image_sample.jpg"]];
[tesseract recognize];

NSLog(@"%@", [tesseract recognizedText]);
[tesseract clear];

Method reference

-initWithDataPath:language:

- (id)initWithDataPath:(NSString *)dataPath language:(NSString *)language

Initialize a new Tesseract instance.

Returns nil if instanciation failed.

-setVariableValue:forKey:

- (void)setVariableValue:(NSString *)value forKey:(NSString *)key

Set Tesseract variable key to value. See http://www.sk-spell.sk.cx/tesseract-ocr-en-variables for a complete (but not up-to-date) list.

For instance, use tessedit_char_whitelist to restrict characters to a specific set.

-setImage:

- (void)setImage:(UIImage *)image

Set the image to recognize.

-setLanguage:

- (BOOL)setLanguage:(NSString *)language

Override the language defined with -initWithDataPath:language:.

-recognize

- (BOOL)recognize

Start text recognition. You might want to launch this process in background with NSObject's -performSelectorInBackground:withObject:.

-recognizedText

- (NSString *)recognizedText

Get the text extracted from the image.

-clear

- (void) clear

Clears Tesseract object after text has been recognized from image. Preventing memory leaks.