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)
Here my code
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
}
}
Also i tried :
1- Settings->Apps->Google Play Services->Storage->Manage Space->Clear All Data
2- Low storage check (At least 1Gig free)
And add meta-data
<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="ocr,text" />
But still the same error!
UPDATE
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'
And use this article for OCR and in this code
//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()
return always false
. that mean it does not work too . I think there is something common with this two problem.
So i am steel stuck on text recognizer for android !
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?
I've noticed that sometimes the problem is the slow internet connection and just need more time the model to be downloaded. To minimize the bad user experience I've added this warm up method and call it as soon as the app starts, so when the actual recognition occurs the model to be already downloaded.