我正在使用Firebase ML Kit进行文本识别,但在模拟器和真实设备上都出现了这个异常。
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- 检查可用空间(至少有1GB可用空间)
并添加元数据
<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="ocr,text" />
但是还是出现同样的错误!
更新
在卡了几天之后,我试着使用了谷歌移动视觉
于是我将这个添加到我的依赖关系中
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
,这意味着它也不起作用。 我认为这两个问题有共同点。
所以我还在为Android的文本识别器卡住了!
测试环境:Nox模拟器、Google Nexus 5X API 26模拟器、华为P10和三星Galaxy S7真实设备。
有没有什么想法可以解决这个问题?