在 Android 上使用 OpenCV 进行 OCR

发布于 2024-12-09 00:16:08 字数 123 浏览 0 评论 0原文

我正在考虑为 Android 创建 OCR。不过我还没有开始,我在谷歌和谷歌上搜索了很多。没有找到任何合理的答案来解决这个问题。最近我开始了解Android OpenCV项目。现在我正在寻找一些有关入门的提示。你能建议正确的方法吗?

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 reasonable 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稳稳的幸福 2024-12-16 00:16:08

1)如何进行Android OCR?

我在互联网上找到了两种方法。

a) 使用 Tesseract - Tesseract 由 google 维护并托管在 git 上。下载和构建的说明可在互联网上找到(在谷歌中搜索“rmtheis tesseract”,点击第一个链接)。以下是方便参考的快速步骤。

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

我没有使用ANT构建,而是在eclipse中创建了自己的APK项目并导入了示例代码来测试该库。

我的系统上安装了 ubuntu。我按照上述说明没有遇到任何问题。我发现安装 git 客户端然后按照上面的步骤操作更容易。构建 tesseract 库后,您需要在 Android 应用程序中加载该库,然后在应用程序中使用 API。网上有很多可用的示例,我发现它很容易使用。

b) 使用 openCV - 您可以使用 open cv 并创建 OCR 功能。 OpenCV 指令有点长。但如果正确遵循这些说明,您可以构建 Open CV 库并在 Android 应用程序中使用静态库。

您将需要 CMAKE 来构建 openCV 库。 CMAKE 还有 3 个其他依赖项。然而,如果严格遵循说明,构建 openCV 并不困难。

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

我发现 tesseract 很容易用于基于字体的 OCR,而 OpenCV 则适合识别手写体。

2) 从哪里开始?

openCV 和 tesseract 都有样本目录。这些示例是自启动套件。
有关 openCV 手写 OCR 的更多示例,请在 google 上搜索关键字“OCR using openCV”。谷歌搜索的前两个匹配是非常好的参考点。

希望以上解释有所帮助。

编辑:

如果您的系统上安装了 oracle jdk 7(就像我的情况一样),您可能会遇到这些问题。为了解决这些问题,我必须编辑 /usr/share/cmake-2.8/Modules/FindJNI.cmake 文件。在此文件中,我注释掉了对 openjdk 和 default 的引用,并添加了对 oracle jdk 7 的引用,如下所示。

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
  )

在脚本查找包含库的部分...

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
  )

然后我按照确切的说明为 android 构建 openCV...

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文