开发者

OCR using OpenCV on Android

开发者 https://www.devze.com 2023-04-12 05:27 出处:网络
I was thinking of creating an OCR for android. I have not started it though, I searched a lot in google & did not found any reas开发者_如何学编程onable answer to solvethis.Recently I came to know

I was thinking of creating an OCR for android. I have not started it though, I searched a lot in google & did not found any reas开发者_如何学编程onable answer to solve this.Recently I came to know about Android OpenCV project. Now I am looking for some hints about getting started. Can you please suggest the right way?


1) How to go about OCR for Android ?

There are two ways which I have found on Internet.

a) Using Tesseract - Tesseract is maintained by google and is hosted on git. The instructions to download and build are available on internet (Search google with "rmtheis tesseract", follow the first link). Here are the quick steps for easy reference.

git clone git://github.com/rmtheis/tess-two tess
   cd tess
   cd tess-two
   ndk-build

I did not used ANT built, but created my own APK project in eclipse and imported the sample code to test the library.

I have ubuntu installed on my system. I did not faced any problems with above instructions. I found it easier to install git client and then follow the steps above. Once tesseract library is built, you will need to load this library in your android application and then use the APIs in your application. There are lots of samples available on net and I found it easy to use.

b) Using openCV - You can use open cv and creat OCR functionlity. OpenCV instructions are little lengthy. But if these instructions are followed correctly, you can build Open CV library and use the static library in your android application.

You will need CMAKE for building the openCV library. CMAKE has 3 other dependencies. However, it is not difficult to build openCV, if instructions are followed exactly.

http://code.opencv.org/projects/opencv/wiki/Building_OpenCV4Android_from_trunk

I found tesseract easy to use for font based OCR while OpenCV is good for recognizing hand writing.

2) Where to start ?

Both openCV and tesseract have samples directory. These samples are self starter kits. For more examples on openCV hand writing OCR, search on google with keyword "OCR using openCV". The first two matches of the google search are very good reference points.

Hope above explanation helps.

EDIT :

If you have oracle jdk 7 installed on your system, as was my case, you might run into the issues. For resolving those issues I had to edit /usr/share/cmake-2.8/Modules/FindJNI.cmake file. In this file, I commented out the lines with references to openjdk and default and added references of oracle jdk 7 as shown below.

JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
  ${_JAVA_HOME}/jre/lib/{libarch}
  ${_JAVA_HOME}/jre/lib
  ${_JAVA_HOME}/lib
  ${_JAVA_HOME}
  /usr/lib
  /usr/local/lib
  /usr/lib/jvm/java/lib
  /usr/lib/java/jre/lib/{libarch}
  /usr/lib/jvm/jre/lib/{libarch}
  /usr/local/lib/java/jre/lib/{libarch}
  /usr/local/share/java/jre/lib/{libarch}
  /usr/lib/j2sdk1.4-sun/jre/lib/{libarch}
  /usr/lib/j2sdk1.5-sun/jre/lib/{libarch}
  /opt/sun-jdk-1.5.0.04/jre/lib/{libarch}
  /usr/lib/jvm/java-6-sun/jre/lib/{libarch}
  /usr/lib/jvm/java-1.5.0-sun/jre/lib/{libarch}
  /usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/{libarch}       # can this one be removed according to #8821 ? Alex
  #/usr/lib/jvm/java-6-openjdk/jre/lib/{libarch}        # Commented by Atul
  #/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/lib/{libarch}        # fedora
  # Debian specific paths for default JVM
  #/usr/lib/jvm/default-java/jre/lib/{libarch}        # Commented by Atul
  #/usr/lib/jvm/default-java/jre/lib          # Commented by Atul
  #/usr/lib/jvm/default-java/lib              # Commented by Atul
  # OpenBSD specific paths for default JVM
  /usr/local/jdk-1.7.0/jre/lib/{libarch}
  /usr/local/jre-1.7.0/lib/{libarch}
  /usr/local/jdk-1.6.0/jre/lib/{libarch}
  /usr/local/jre-1.6.0/lib/{libarch}
  /usr/lib/jvm/java-7-oracle/jre/lib/{libarch} # This is added Atul
  )

and in the section where the script looks for include library...

set(JAVA_AWT_INCLUDE_DIRECTORIES
  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
  ${_JAVA_HOME}/include
  /usr/include
  /usr/local/include
  /usr/lib/java/include
  /usr/local/lib/java/include
  /usr/lib/jvm/java/include
  /usr/lib/jvm/java-6-sun/include
  /usr/lib/jvm/java-1.5.0-sun/include
  /usr/lib/jvm/java-6-sun-1.6.0.00/include       # can this one be removed according to #8821 ? Alex
  #/usr/lib/jvm/java-6-openjdk/include
  /usr/local/share/java/include
  /usr/lib/j2sdk1.4-sun/include
  /usr/lib/j2sdk1.5-sun/include
  /opt/sun-jdk-1.5.0.04/include
  # Debian specific path for default JVM
  #/usr/lib/jvm/default-java/include
  # OpenBSD specific path for default JVM
  /usr/local/jdk-1.7.0/include
  /usr/local/jdk-1.6.0/include
  /usr/lib/jvm/java-7-oracle/include
  )

Then I followed exact instructions to build the openCV for android...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号