Application and Use Cases

Firebase’s ML Kit enables you to you can recognize text in any Latin-based language. It can also detect multiple languages in a single image. Implementing text recognition into your application can automate tedious data entry tasks for receipts, credit cards, business cards — just to mention a few.

Add Firebase to Flutter

The first step involves adding Firebase to your Flutter project. This is done by creating a Firebase project and registering your app. Follow the comprehensive guide below to set that up:

Install Required Packages

Now that your app’s communication with Firebase is set up, you have to install two packages. The first is image_picker and the second is firebase_ml_vision. We’ll use the image_picker to pick the images from the phone’s gallery or take a new picture.

firebase_ml_vision will provide the functionality for recognizing the text.

Select Image

At this point, we can now select the image that contains the text. We can choose an image either from the gallery or camera. We check if the image has been loaded using imageLoaded . If the image has been loaded, we display it and read the contents of the image. We also initialize an empty text string that will contain the contents of the image:

If you’d rather use the camera, change the source to ImageSource.camera .

Create a FirebaseVisionImage

In this step, we create a FirebaseVisionImage object from the selected image.

FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(pickedImage);

Create an Instance of a Detector

The next step is to create an instance of the detector that we’d like to use. The available detectors are BarcodeDetector , ImageLabeler , FaceDetector , ImageLabeler , and TextRecognizer . In this case, we’re interested in the TextRecognizer .

TextRecognizer textRecognizer = FirebaseVision.instance.textRecognizer();

Process the Image

We’re now ready to process the image using the detector. This will recognize the text in the image.