2

我从这里下载了适用于 Android 的 Tesseract OCR,我正在尝试使用 NDK 将其构建为我自己的应用程序的库项目。我在这里收到了一些关于如何执行此操作的有用反馈。首先,我在命令行上执行此操作([path] 是 tess-two 项目路径的简写):

> cd [path]\tess-two

> C:\android-ndk-r8b-windows\android-ndk-r8b\ndk-build -j8

"Compile thumb : lept <= adaptmap.c

[...]

"Compile++ thumb : lept <= writefile.cpp

Prebuilt       : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/

"Compile++ thumb : tess <= applybox.cpp

[...]

"Compile++ thumb : tess <= tessbaseapi.cpp

"Compile thumb : lept <= adaptmap.c

[...]

"Compile++ thumb : lept <= pixa.cpp

Prebuilt       : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/

"Compile++ thumb : lept <= jni.cpp

[...]

"Compile++ thumb : tess <= tessbaseapi.cpp

"Compile x86  : lept <= affine.c

[...]

"Compile++ x86  : lept <= readfile.cpp

Prebuilt       : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/x86/

"Compile++ x86  : tess <= baseapi.cpp

[...]

"Compile++ x86  : tess <= wordclass.cpp

SharedLibrary  : liblept.so

SharedLibrary  : liblept.so

"Compile++ x86  : tess <= tessbaseapi.cpp

SharedLibrary  : liblept.so

"Compile++ x86  : tess <= wordrec.cpp

SharedLibrary  : libtess.so

Install        : liblept.so => libs/x86/liblept.so

Install        : liblept.so => libs/armeabi/liblept.so

SharedLibrary  : libtess.so

Install        : liblept.so => libs/armeabi-v7a/liblept.so

SharedLibrary  : libtess.so

Install        : libtess.so => libs/armeabi/libtess.so

Install        : libtess.so => libs/armeabi-v7a/libtess.so

Install        : libtess.so => libs/x86/libtess.so


> C:\Users\User\android-sdk\tools\android.bat update project --path .

Failed to convert path to a short DOS path: C:\Windows\system32\java.exe
'javaw_exe' is not recognized as an internal or external command,
operable program or batch file.
Updated local.properties

Updated file [path]\tess-two\proguard-project.txt

It seems that there are sub-projects. If you want to update them

please use the --subprojects parameter.

> set JAVA_HOME=C:\Java\JDK
> Buildfile: [path]\tess-two\build.xml

-set-mode-check:

-set-release-mode:

-release-obfuscation-check:
     [echo] proguard.config is ${proguard.config}

-check-env:
 [checkenv] Android SDK Tools Revision 20.0.3
 [checkenv] Installed at C:\Users\User\android-sdks

-setup:
     [echo] Project Name: tess-two
  [gettype] Project Type: Android Library

-build-setup:
     [echo] Resolving Build Target for tess-two...
[gettarget] Project Target:   Google APIs
[gettarget] Vendor:           Google Inc.
[gettarget] Platform Version: 4.1
[gettarget] API level:        16
     [echo] ----------
     [echo] Creating output directories if needed...
     [echo] ----------
     [echo] Resolving Dependencies for tess-two...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency] 
[dependency] ------------------
[dependency] API<=15: Adding annotations.jar to the classpath.
     [echo] ----------
     [echo] Building Libraries with 'release'...
   [subant] No sub-builds to iterate on

-pre-build:

-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
[renderscript] No RenderScript files to compile.
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Found new input file
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.

-pre-compile:

-compile:
     [echo] Creating library output jar file...

-post-compile:

-obfuscate:

-dex:
     [echo] Library project: do not convert bytecode...

-crunch:
   [crunch] Crunching PNG Files in source dir: [path]\tess-two\res
   [crunch] To destination dir: [path]\tess-two\bin\res
   [crunch] Crunched 0 PNG files to update cache

-package-resources:
     [echo] Library project: do not package resources...

-package:
     [echo] Library project: do not package apk...

-post-package:

-release-prompt-for-password:

-release-nosign:
     [echo] 
[propertyfile] Updating property file: [path]\tess-two\bin\build.prop
[propertyfile] Updating property file: [path]\tess-two\bin\build.prop
[propertyfile] Updating property file: [path]\tess-two\bin\build.prop
[propertyfile] Updating property file: [path]\tess-two\bin\build.prop

-release-sign:

-post-build:

release:

BUILD SUCCESSFUL
Total time: 1 second

然后,我这样做:文件 -> 导入 -> Android -> 现有代码到工作区 -> 浏览 -> 选择当前工作区目录 -> 确保在出现的列表中选择了 tess-two -> 完成。

然后我右键单击我自己的应用程序,转到属性-> Android 选项卡-> 添加...(在库部分下)-> 选择 tess-two -> 单击确定-> 检查“是库”-> 确定。

但是,毕竟这一切,我在运行我的应用程序时仍然收到以下错误:

09-23 13:02:42.532: E/AndroidRuntime(675): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load lept: findLibrary returned null
09-23 13:02:42.532: E/AndroidRuntime(675):  at java.lang.Runtime.loadLibrary(Runtime.java:365)
09-23 13:02:42.532: E/AndroidRuntime(675):  at java.lang.System.loadLibrary(System.java:535)
09-23 13:02:42.532: E/AndroidRuntime(675):  at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:47)

我自己的应用程序的 project.properties 是:

target=android-16
android.library.reference.1=..\\OpenCV\\sdk\\java
android.library.reference.2=../Tesseract/tess-two
android.library=true

这是怎么回事?

4

2 回答 2

2

我明白了,问题是我没有在我的代码中正确初始化 API。正确的语法是:

tesseract.init("/mnt/sdcard/", "eng");

假设您在 mnt/sdcard 下有一个文件夹“tessdata”。现在它完美加载!非常感谢您的帮助,rmthesis!

于 2012-09-24T02:41:47.283 回答
0

对我来说,而不是 2 loadlibrary 我做了所有 4

System.loadLibrary("jpgt"); System.loadLibrary("pngt"); System.loadLibrary("lept"); System.loadLibrary("tess"); 它奏效了。

于 2016-02-17T00:26:22.833 回答