Reputation: 117
I am developing a text recognizer app for android using firebase ML Kit. The issue when I capture the text image is not getting the actual result of the image why??. I think my app does not identify the language well. How can I solve this issue?
#I am new to android Pls help me in this regard
Dependency I have used
implementation 'com.google.firebase:firebase-ml-vision:20.0.0'
Recognize Text & Process Text code
/**
* This method is used to extract the text from the image
* @param image
*/
private void recognizeText(FirebaseVisionImage image){
FirebaseVisionTextRecognizer detector = FirebaseVision.getInstance()
.getOnDeviceTextRecognizer();
detector.processImage(image)
.addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
@Override
public void onSuccess(FirebaseVisionText firebaseVisionText) {
processText(firebaseVisionText);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
e.printStackTrace();
Toast.makeText(getActivity(), "No text found", Toast.LENGTH_SHORT).show();
}
});
}
/**
* This method is used to process the text and send the result (text) to ResultLayout fragment
* @param firebaseVisionText
*/
private void processText(FirebaseVisionText firebaseVisionText) {
if(firebaseVisionText.getTextBlocks().isEmpty()){
Toast.makeText(getActivity(), "No text found or Text may not be clear", Toast.LENGTH_LONG).show();
}
else {
String text = "";
for (FirebaseVisionText.TextBlock block : firebaseVisionText.getTextBlocks()){
text = text + block.getText() + " ";
}
String tag = ((MainActivity)getActivity()).getTag_ResultLayout();
ResultLayout fragment = (ResultLayout)getActivity().getSupportFragmentManager()
.findFragmentByTag(tag);
fragment.setResult(text);
((MainActivity)getActivity()).openResultLayout();
}
I am ready to provide more information in this regard
Upvotes: 0
Views: 1776
Reputation: 605
we made some changes to Firebase ML Kit for Firebase 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.
This issue might be resulted in a misformatted image. Could you try to refer to the sample here for constructing a InputImage from different sources?
Upvotes: 1
Reputation: 66
Could you share your AndroidManifest.xml?
If you want to achieve better results, you can try to use multiple models like this:
<application ...>
...
<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="ocr" />
<!-- To use multiple models: android:value="ocr,model2,model3" -->
</application>
More info on this can be found in the official documentation here: https://firebase.google.com/docs/ml-kit/android/recognize-text
Upvotes: 1