Skip to content
g8production edited this page Aug 24, 2017 · 26 revisions

Use the provided template project

If you're starting from scratch, the "Template Framework Project" in this repository provides an example of how to use Tesseract in your iOS projects. It's iOS7 and arm64 ready!

Integrate the framework into an existing project using CocoaPods

CocoaPods

First install CocoaPods; instructions are here: http://cocoapods.org/

Using the latest stable version

Add the following line to your Podfile then run pod install

pod 'TesseractOCRiOS', '4.0.0'

(Optional) Using the development version

You can optionally use the development version of this library instead of the 4.0.0 release. Of course, you should only have one TesseractOCRiOS line in your Podfile (the 4.0.0 release or this one). To use the development version, add the following line to your Podfile then run pod install

pod 'TesseractOCRiOS', :git => 'https://github.com/gali8/Tesseract-OCR-iOS.git'

** WARNING **: This uses the GitHub repository's master branch as the source for the library. This is not based off of any stable Tesseract OCR iOS release.

Import libz.dylib (or libz.tbd) to target, if it's not been automatically

  • Go to target section
  • 'Build Phases' tab
  • Open 'Link Binaries With Libraries'
  • Click on + button
  • Search and select libz.dylib or libz.tbd
  • Click on the Add Button

Importing the tessdata folder

Import your tessdata folder (you can download one for your language from https://code.google.com/p/tesseract-ocr/downloads/list) into the root of your project AS A REFERENCED FOLDER (see below). It contains the Tesseract trained data files. You can add your own trained data files here too.

NOTE: This library currently requires the tessdata folder to be linked as a referenced folder instead of a symbolic group. If Tesseract can't find a language file in your own project, it's probably because you created the tessdata folder as a symbolic group instead of a referenced folder. It should look like this if you did it correctly:

Note how the tessdata folder has a blue icon, indicating it was imported as a referenced folder instead of a symbolic group.

XCode 9:

  • Create a tessdata folder into the project folder (open the project folder on Finder and create the tessdata folder at the same level of the AppDelegate.swift file).
  • Add your Tesseract trained data files into the tessdata folder.
  • Open Xcode.
  • From the File menu, choose Add files to...
  • Select the tessdata folder.
  • Click Options and make sure Create folder references is selected.
  • Click Finish.

Side note: I (mdenty) used to put TesseractOCR.framework as an embedded framework in my project. Since iOS7 does not support embedded frameworks, I've decided to put TesseractOCR as "normal" framework. My project built and linked without problem, but at runtime I use - (UIImage *)g8_blackAndWhite; method of UIImage (G8Filters) category and I got something like:

reason: '-[UIImage g8 blackAndWhite]: unrecognized selector sent to instance

I solved the problem by setting GENERATE_MASTER_OBJECT_FILE = YES in the Tesseract OCR IOS.xcodeproj build settings. This should lead to a bit bigger executable file. End of side note.

Also, add -lstdc++ to your other linker flags or you may get a slew of errors.

Work with Swift (ios 9):

set ENABLE_BITCODE = NO

Work with Swift (iOS 10):

set ENABLE_BITCODE = NO then, see answer here. The POD's bitcode must be Bitcode disabled as well. https://github.com/gali8/Tesseract-OCR-iOS/issues/279#issuecomment-287415081

Don't forget to import the "import TesseractOCR" at the class you are working