繁体   English   中英

在Android Studio中使用Tesseract ocr,但程序意外退出

[英]Use Tesseract ocr in Android studio but the program exits unexpectedly

我正在Android Studio中使用Tesseract来识别图片中的文本。 当我这样调用以下函数时:

String textResult = doOcr(bitmapTreated,"eng"); 

然后程序退出。

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;
    } 

结果如下:

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

我调试它,它在类TessBaseAPI中停止

static {
        System.loadLibrary("lept");
        System.loadLibrary("tess"); 
        nativeClassInit();
    }

我不知道环境配置是否错误或我的代码是否错误。 以下是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')
}

如果我如下更改支持库:

compile 'com.android.support:appcompat-v7:22.0.1'

红线表示“支持库不应使用与compileSdkVersion不同的版本”。 然后将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

我可以在“ compile'c​​om.android.support:design:23.1.1'”下看到一条红线。我继续将其更改为“ compile'c​​om.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

这可能是由于某些版本的Android支持库中的错误导致的。

尝试更新您的支持库:

compile 'com.android.support:appcompat-v7:22.1.0'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM