[英]Use Tesseract ocr in Android studio but the program exits unexpectedly
I'm using Tesseract in Android Studio to recognize texts in a picture. 我正在Android Studio中使用Tesseract来识别图片中的文本。 When I call the following function like this:
当我这样调用以下函数时:
String textResult = doOcr(bitmapTreated,"eng");
Then the program exits. 然后程序退出。
public String doOcr(Bitmap bitmap, String language) {
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(getSDPath(), language);
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
baseApi.setImage(bitmap);
String text = baseApi.getUTF8Text();
baseApi.clear();
baseApi.end();
return text;
}
Here are the results: 结果如下:
06-24 21:37:23.205 30643-30643/? D/dalvikvm: Late-enabling CheckJNI
06-24 21:37:23.335 30643-30643/com.example.text_recognization D/dalvikvm: GetMethodID: not returning static method Landroid/os/Process;.getTotalMemory ()J
06-24 21:37:23.335 30643-30643/com.example.text_recognization D/dalvikvm: GetMethodID: not returning static method Landroid/os/Process;.getFreeMemory ()J
06-24 21:37:23.365 30643-30643/com.example.text_recognization I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
06-24 21:37:23.365 30643-30643/com.example.text_recognization W/dalvikvm: VFY: unable to resolve virtual method 422: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
06-24 21:37:23.365 30643-30643/com.example.text_recognization D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
06-24 21:37:23.365 30643-30643/com.example.text_recognization I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
06-24 21:37:23.365 30643-30643/com.example.text_recognization W/dalvikvm: VFY: unable to resolve virtual method 444: Landroid/content/res/TypedArray;.getType (I)I
06-24 21:37:23.365 30643-30643/com.example.text_recognization D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
06-24 21:37:23.435 30643-30643/com.example.text_recognization I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.2.2.1_RB1.04.04.04.090.052_msm8974_LNX.LA.3.5.2.2.1_RB1__release_AU ()
OpenGL ES Shader Compiler Version: E031.24.00.15
Build Date: 07/01/15 Wed
Local Branch: mybranch11515920
Remote Branch: quic/LNX.LA.3.5.2.2.1_rb1
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.2.2.1_RB1.04.04.04.090.052 + NOTHING
06-24 21:37:23.465 30643-30643/com.example.text_recognization D/OpenGLRenderer: Enabling debug mode 0
06-24 21:37:23.525 30643-30643/com.example.text_recognization I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@43519b38 time:579991957
I debug it, and it stops in the class TessBaseAPI 我调试它,它在类TessBaseAPI中停止
static {
System.loadLibrary("lept");
System.loadLibrary("tess");
nativeClassInit();
}
I don't know whether the environment configuration is wrong or my code is wrong. 我不知道环境配置是否错误或我的代码是否错误。 And the following is the build.grade file:
以下是build.grade文件:
com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.example.zhouying.text_recognization"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile files('libs/tess-two.tesseract3.01-leptonica1.68-LibJPEG6b.jar')
}
if I change the support library as follows: 如果我如下更改支持库:
compile 'com.android.support:appcompat-v7:22.0.1'
There will be a red line indicates that "The support library shouldn't use a different version than the compileSdkVersion". 红线表示“支持库不应使用与compileSdkVersion不同的版本”。 Then I change the compileSdkVersion and targetSdkVersion to 22, I can see errors.
然后将compileSdkVersion和targetSdkVersion更改为22,可以看到错误。
Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
Error:(24) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/Library/Android/sdk/build-tools/23.0.2/aapt'' finished with non-zero exit value 1
And I can see a red line under "compile 'com.android.support:design:23.1.1'".I continue to change it to "compile 'com.android.support:design:22.0.1'. It shows 我可以在“ compile'com.android.support:design:23.1.1'”下看到一条红线。我继续将其更改为“ compile'com.android.support:design:22.0.1”。
Failed to resolve com.android.support:appcompat-v7:22.0.1
Failed to resolve com.android.support:design:22.0.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.