簡體   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