Tesseract OCR + Open CV 2 on iOS

Disclaimer: This is a quick and messy post that I wrote just so that I will not forget what I did. I am not sure that this is the best way to do things and there may be redundant or missing steps. I will clean this up if I need to do it again. If you happen to go through this procedure and find mistakes, drop me a note and I will fix the post.

The problem

  • I needed to add this build of Tesseract OCR to my iOS project, which uses Open CV 2.
  • Following the installation procedure in the link, caused the following error:

    ‘opencv2/opencv.hpp’ file not found

  • I tried solving it using this stack overflow solution, but it caused a circular dependency issue – every time I removed and added some framework, I got the following error for another framework:

    ld: framework not found <Framework Name>
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

What worked

  • Added the Tesseract OCR iOS project from the link into my workspace
  • Added another build target for the Tesseract project, of type: Cocoa Touch Static Library
  • For my new target:
    • Under build phases, compile sources – added Tesseract.mm (add any file that needs compiling, really)
    • Under build phases, copy files – added Tesseract.h
    • Under link with libraries, added:
      • libstdc++.6.0.9.dylib (Not sure it’s needed here)
      • All the files under the lib folder in the Tesseract OCR project
    • In Build Settings, click “all” so that you can see all settings and look for ‘architecture’ in the search box. Changed “Build Active Architecture Only” to no.
      Made sure I have all the relevant architectures selected.
    • In Build Settings, C++ Standard Library, chose libc++
      (I did the same for the project itself as well, I’m not sure it’s necessary)
  • Selected my new library as a build target and built the thing.
  • For my main project, under the app target, general, linked framework and libraries, added:
    • My new library
    • libstdc++.6.0.9.dylib (Here it’s a must)
  • Added tessdata to the project

Used Tesseract to recognise text in images to my heart’s content.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s