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.

Debug a Bluetooth App with Android Emulator on PC

  1. Install VirtualBox. I have version 4.2.10.
  2. Follow these instructions to create a new VM and install android-x86 on it.

Bluetooth Configuration

  1. If you use a Bluetooth USB adapter, follow these instructions to access it from the guest OS (I stopped at “Verification Under the Guest OS”). 
  2. If you use a laptop’s built in Bluetooth device, this should do the trick.
  3. Enable Bluetooth on the guest OS, make sure you can see and pair with whatever device you want.

Network and Remote Debug Configuration

  1. Follow these instructions to enable internet connection on your VM.
  2. Find the IP of your VM by goint to the terminal (Alt+F1 and Alt+F7 to toggle) and running netcfg.
  3. On the host machine, navigate to your android installation folder > platform-tools and execute “adb connect IP” where IP is the IP of your VM.

Now you can see your device in the devices view in eclipse and play with it to your heart’s content.

Other nuisances

  1. If the cursor is not responding when you start your machine, go to Machine ->Disable Mouse Integration. You will have to click on the VM screen to interact with it and press “host” key to escape.
  2. Seems like the current version of Android-x86 has a bug that prevents it from “waking up” when it is locked. You probably want to disable screen locking so that you don’t have to restart the machine after every time you go to the loo.
  3. You can configure the “adb connect” command as an external tool in eclipse so that you can run it inside your IDE:
    1. Click the little arrow near the external tools button, and choose “External Tools Configurations…”
    2. Click “new”
    3. Name your configuration (i.e: “Remote connect adb”)
    4. Location: path to your adb.exe
    5. Working Directory: platform-tools folder in android installation folder
    6. Arguments: connect IP
      Alternatively, you can use ${string_prompt} instead of IP if you want eclipse to ask you which IP you cant to connect to each time you run the command.
    7. Click “Apply”

And that’s it.