Search code examples
androidfirebase-mlkittext-recognition

Text Recognition not accurate on Android device using camera and Firebase ML Kit


I am using Firebase ML Kit on Android device for text recognition using a camera without clicking image. I am using it by receiving frames and getting bitmaps from the frames. Then passing the Bitmaps into the Text Recognition method. But the text recognized is not accurate. Also, it is constantly changing but never giving accurate results. Please let me know what I am doing wrong.

getting frames and Bitmaps:

  public void onSurfaceTextureUpdated(SurfaceTexture surface) {
            frame = Bitmap.createBitmap(textureView.getWidth(), textureView.getHeight(), Bitmap.Config.ARGB_8888);
            textureView.getBitmap(frame);

            Bitmap emptyBitmap = Bitmap.createBitmap(textureView.getBitmap(frame).getWidth(), textureView.getBitmap(frame).getHeight(), textureView.getBitmap(frame).getConfig());
            if (textureView.getBitmap(frame).sameAs(emptyBitmap)) {
                // myBitmap is empty/blank
                System.out.println(" empty !!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            } else {
                System.out.println(" bitmap");


                        bitmap = textureView.getBitmap(frame);
                                runTextRecognition();
            }

text recognition:

private void runTextRecognition() {
    System.out.println(" text recognition!!!");
    FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
    FirebaseVisionTextRecognizer recognizer = FirebaseVision.getInstance().getOnDeviceTextRecognizer();
    recognizer.processImage(image).addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
        @Override
        public void onSuccess(FirebaseVisionText texts) {
            System.out.println("Text recognized ::: " + texts);
            textRecognized = true;
            processTextRecognitionResult(texts);

        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            e.printStackTrace();
        }
    });

}

Solution

  • The text I was trying to recognize was MRZ. I contacted Firebase Support, they themselves performed tests and concluded that ML Kit API isn't capable of reading MRZ type text and that they might incorporate it in future.