本文介绍了Firebase ML套件提供FirebaseMLException:等待文本识别模型下载.请稍等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用firebase ml套件进行文本识别,但在模拟器和真实设备上会出现此异常.

I'm use firebase ml kit for text recognition but give this exception on emulator and real device.

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.zzjz.zzc(Unknown Source)
    at com.google.android.gms.internal.firebase_ml.zzjz.zza(Unknown Source)
    at com.google.android.gms.internal.firebase_ml.zzic.call(Unknown Source)
    at com.google.android.gms.internal.firebase_ml.zzhx.zza(Unknown Source)
    at com.google.android.gms.internal.firebase_ml.zzhy.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at com.google.android.gms.internal.firebase_ml.zze.dispatchMessage(Unknown Source)
    at android.os.Looper.loop(Looper.java:136)
    at android.os.HandlerThread.run(HandlerThread.java:61)

这是我的代码

private fun MlProcessText(imageUri:Uri) {
    val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, imageUri)
    val textVision = FirebaseVisionImage.fromBitmap(bitmap)
    val detector = FirebaseVision.getInstance().onDeviceTextRecognizer

    detector.processImage(textVision).addOnSuccessListener { it ->
        val blocks = it.textBlocks
        if (blocks.size == 0 ){

            tvVision.text = "NO TEXT"
        }else{
            blocks.forEach {
                tvVision.append(" ${it.text}")
            }
        }

    }.addOnFailureListener {
        it.printStackTrace() // this is the exception log
        tvVision.text = it.message
    }
}

我也尝试过:

1- 设置->应用程序-> Google Play服务->存储->管理空间->清除所有数据

2-低存储空间检查(至少1Gig免费)

2- Low storage check (At least 1Gig free)

并添加元数据

 <meta-data
        android:name="com.google.firebase.ml.vision.DEPENDENCIES"
        android:value="ocr,text" />

但是仍然是同样的错误!

But still the same error!

更新

卡住几天后,我尝试使用 Google Mobile Vision

After getting stuck for several days i try to use Google Mobile Vision

所以我将其添加到我的依赖项中

So i add this to my dependencies

implementation 'com.google.android.gms:play-services-vision:17.0.2'

并使用本文 OCR 并在此代码中

    //Create the TextRecognizer
    final TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();

    if (!textRecognizer.isOperational()) {
        Log.w(TAG, "Detector dependencies not loaded yet");
    } else {

        //Initialize camerasource to use high resolution and set Autofocus on.
        mCameraSource = new CameraSource.Builder(getApplicationContext(), textRecognizer)
                .setFacing(CameraSource.CAMERA_FACING_BACK)
                .setRequestedPreviewSize(1280, 1024)
                .setAutoFocusEnabled(true)
                .setRequestedFps(2.0f)
                .build();
     }

textRecognizer.isOperational()总是返回false.这意味着它也不起作用.我认为这两个问题有些共同点.

textRecognizer.isOperational() return always false. that mean it does not work too . I think there is something common with this two problem.

因此,我坚决坚持使用适用于android的文本识别器!

So i am steel stuck on text recognizer for android !

在以下设备上测试:Nox模拟器,google Nexus 5X API 26模拟器以及华为p10和三星Galaxy S7真实设备.

Test on : Nox emulator , google Nexus 5X API 26 emulator and on Huawei p10 and Samsung Galaxy S7 real device.

有解决这个问题的主意吗?

is there any idea to solve this problem?

推荐答案

TextRecognizer textRecognizer = new TextRecognizer.Builder(this).build();

    if(!textRecognizer.isOperational()) {
        // Note: The first time that an app using a Vision API is installed on a
        // device, GMS will download a native libraries to the device in order to do detection.
        // Usually this completes before the app is run for the first time.  But if that
        // download has not yet completed, then the above call will not detect any text,
        // barcodes, or faces.
        // isOperational() can be used to check if the required native libraries are currently
        // available.  The detectors will automatically become operational once the library
        // downloads complete on device.
        Log.w(LOG_TAG, "Detector dependencies are not yet available.");

        // Check for low storage.  If there is low storage, the native library will not be
        // downloaded, so detection will not become operational.
        IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
        boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;

        if (hasLowStorage) {
            Toast.makeText(this,"Low Storage", Toast.LENGTH_LONG).show();
            Log.w(LOG_TAG, "Low Storage");
        }

这篇关于Firebase ML套件提供FirebaseMLException:等待文本识别模型下载.请稍等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 08:26