首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >工具包无法加载OCR模块

工具包无法加载OCR模块
EN

Stack Overflow用户
提问于 2019-10-20 22:10:12
回答 4查看 15.9K关注 0票数 13

我正在开发一个涉及ML工具包的android应用程序。我研究了一下如何设置Android来使用Firebase的教程。然后我开始使用文本识别API。下面是我在某个按钮单击监听器中的代码:

代码语言:javascript
复制
        FirebaseVisionTextRecognizer detector = FirebaseVision.getInstance()
            .getOnDeviceTextRecognizer();
        Task<FirebaseVisionText> result = detector.processImage(
            FirebaseVisionImage.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.test))
        )
            .addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
                @Override
                public void onSuccess(FirebaseVisionText firebaseVisionText) {
                    System.out.println(firebaseVisionText);
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    e.printStackTrace();
                }
            });

我得到以下日志:

代码语言:javascript
复制
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite.ocr:0 and remote module com.google.android.gms.vision.dynamite.ocr:0
D/TextNativeHandle: Cannot load feature, fall back to load dynamite module.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.ocr:0 and remote module com.google.android.gms.vision.ocr:0
E/Vision: Error loading module com.google.android.gms.vision.ocr optional module true: com.google.android.gms.dynamite.DynamiteModule$LoadingException: No acceptable module found. Local version is 0 and remote version is 0.
D/TextNativeHandle: Broadcasting download intent for dependency ocr
W/TextNativeHandle: Native handle not yet available. Reverting to no-op handle.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite.ocr:0 and remote module com.google.android.gms.vision.dynamite.ocr:0
D/TextNativeHandle: Cannot load feature, fall back to load dynamite module.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.ocr:0 and remote module com.google.android.gms.vision.ocr:0
E/Vision: Error loading module com.google.android.gms.vision.ocr optional module true: com.google.android.gms.dynamite.DynamiteModule$LoadingException: No acceptable module found. Local version is 0 and remote version is 0.
W/System.err: com.google.firebase.ml.common.FirebaseMLException: Waiting for the text recognition model to be downloaded. Please wait.
        at com.google.android.gms.internal.firebase_ml.zzrw.zzd(com.google.firebase:firebase-ml-vision@@24.0.0:21)
        at com.google.android.gms.internal.firebase_ml.zzrw.zza(com.google.firebase:firebase-ml-vision@@24.0.0:39)
        at com.google.android.gms.internal.firebase_ml.zzpd.zza(com.google.firebase:firebase-ml-common@@22.0.0:31)
        at com.google.android.gms.internal.firebase_ml.zzpf.call(Unknown Source:8)
        at com.google.android.gms.internal.firebase_ml.zzoz.zza(com.google.firebase:firebase-ml-common@@22.0.0:32)
        at com.google.android.gms.internal.firebase_ml.zzoy.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:873)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.google.android.gms.internal.firebase_ml.zze.dispatchMessage(com.google.firebase:firebase-ml-common@@22.0.0:6)
        at android.os.Looper.loop(Looper.java:193)
        at android.os.HandlerThread.run(HandlerThread.java:65)

我搜索了一下,看看如何修复这些错误:

代码语言:javascript
复制
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite.ocr:0 and remote module com.google.android.gms.vision.dynamite.ocr:0
D/TextNativeHandle: Cannot load feature, fall back to load dynamite module.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.ocr:0 and remote module com.google.android.gms.vision.ocr:0
E/Vision: Error loading module com.google.android.gms.vision.ocr optional module true: com.google.android.gms.dynamite.DynamiteModule$LoadingException: No acceptable module found. Local version is 0 and remote version is 0.
代码语言:javascript
复制
W/System.err: com.google.firebase.ml.common.FirebaseMLException: Waiting for the text recognition model to be downloaded. Please wait.

到目前为止,我已经尝试过清除Google服务数据(版本19.4.20),重新启动/重新创建模拟器,调整Gradle配置(例如添加/消除firebase-core依赖项)。项目级配置:

代码语言:javascript
复制
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath 'com.google.gms:google-services:4.3.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用程序模块级配置:

代码语言:javascript
复制
apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.user.app"
        minSdkVersion 24
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.gms:play-services-vision:19.0.0'
    implementation 'com.google.firebase:firebase-ml-vision:24.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}

apply plugin: 'com.google.gms.google-services'

我决定给条形码API一个机会,并补充说

代码语言:javascript
复制
implementation 'com.google.firebase:firebase-ml-vision-barcode-model:16.0.1'

作为依赖。令我惊讶的是,当我对它进行API调用时,成功列表被击中,出现了以下日志:

代码语言:javascript
复制
I/DynamiteModule: Considering local module com.google.firebase.ml.vision.dynamite.barcode:10000 and remote module com.google.firebase.ml.vision.dynamite.barcode:0
    Selected local version of com.google.firebase.ml.vision.dynamite.barcode
W/is.moneytravel: Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
I/tflite: Initialized TensorFlow Lite runtime.
I/native: barcode_detector_client.cc:222 Not using NNAPI

而OCR仍然产生相同的错误。我认为它必须处理从库中获取的存储库。条形码API:

代码语言:javascript
复制
Considering local module com.google.firebase.ml.vision.dynamite.barcode:10000 and remote module com.google.firebase.ml.vision.dynamite.barcode:0

代码语言:javascript
复制
Considering local module com.google.android.gms.vision.dynamite.ocr:0 and remote module com.google.android.gms.vision.dynamite.ocr:0

我对Gradle和Firebase的经验太少,弄不清楚这一点。为什么从android.gms获取OCR,而条形码API来自firebase.ml

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2019-10-27 13:15:48

解决方案是更新Google应用程序。一开始我并不认为这是一种选择,因为我本来希望API 29模拟器安装一个最新的Google服务。我在模拟器上登录到Google,搜索Google服务,卸载它(没有“更新”选项),然后再次安装它。它仍然说已安装的版本是19.4.20,尽管文本识别开始像预期的那样工作。下面是一些相关的日志:

代码语言:javascript
复制
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite.ocr:0 and remote module com.google.android.gms.vision.dynamite.ocr:0
D/TextNativeHandle: Cannot load feature, fall back to load dynamite module.
I/DynamiteModule: Considering local module com.google.android.gms.vision.ocr:0 and remote module com.google.android.gms.vision.ocr:1
I/DynamiteModule: Selected remote version of com.google.android.gms.vision.ocr, version >= 1
V/DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils
票数 6
EN

Stack Overflow用户

发布于 2020-07-20 12:54:53

尝试在AndroidManifest.xml中添加以下内容

代码语言:javascript
复制
<application>
    ...

    <meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="ocr"/>

</application>

文档可以在https://developers.google.com/ml-kit/vision/text-recognition/android上找到

票数 1
EN

Stack Overflow用户

发布于 2020-04-09 11:12:24

这是清单上的一些代码,请检查您的清单中是否遗漏了什么。

ManifestFile installLocation

代码语言:javascript
复制
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.******.***"
    android:installLocation="auto"
/>
<!-- make sure to add 'android:installLocation="auto"', it was missing for me -->

ManifestFile元数据

代码语言:javascript
复制
<application
    <!-- ..... -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" /> <!--version--><!-- make sure added-->
    <meta-data
        android:name="com.google.android.gms.vision.DEPENDENCIES"
        android:value="barcode" /><!-- barcode,face,ocr make sure added-->
    <!-- ..... -->
</application>
  • 检查Internet连接
  • 检查存储空间是否空闲

如果您使用仿真器

  • 检查google服务是否正常工作。
  • 如果需要的话更新
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58477758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档