I am working with Android Studio to develop an app that, once a picture is taken, will return text that is detected in the image. My problem is that every time I take a picture, it does not find any text within images (no matter how apparent the text is). I followed the ML Kit documentation on Google's site and don't see anything wrong with my code. Each time I take a picture my task is unsuccessful and "Text Detection Failed" is printed to the results. Any help on something I am doing wrong or something I am missing?
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// extract image
assert data != null;
Bundle image_bundle = data.getExtras();
Bitmap image_bitmap = (Bitmap) image_bundle.get("data");
// set image in image_view of application
image_view.setImageBitmap(image_bitmap);
// process the given image to get the text
// this is using Firebase ML and Cloud Vision API
// 1. create InputImage obj from Bitmap obj
InputImage input_image = InputImage.fromBitmap(image_bitmap, 0);
// 2. create TextRecognizer obj as entry point to analyzing image
TextRecognizer text_recognizer = TextRecognition.getClient();
// 3. perform text recognition on the image
Task<Text> task = text_recognizer.process(input_image);
// 4. handle the success of the task
task.addOnCompleteListener(new OnCompleteListener<Text>() {
@Override
public void onComplete(@NonNull Task<Text> task_) {
if (task_.isSuccessful()) {
text_view.setText("Text Detected");
}
else {
text_view.setText("Text Detection Failed");
}
}
});
text_recognizer.close();
}
}
We made some changes to Firebase ML Kit to better distinguish the on-device APIs from cloud based APIs. "ML Kit"(without firebase branding) contains all the on-device APIs. Here's the migration guide from firebase mlkit to mlkit.
For text recognition, since the model is downloaded from GMSCore, you may need to wait for it to be downloaded first before your initial usage.
If you still encounter the same problem, feel free to report a bug with a logcat trace or bugreport.