Firebase Series | Blog 7 | Firebase Text Recognition: Extract the Text You Need From images.

Sreedev
3 min readJan 6, 2020

--

Picture courtesy: Wallace Chuck

Text recognition is one of the API’s that developers use very frequently. Fortunately, firebase exposes the feature through its SDK. Firebase text recognition can recognise all the Latin languages. If you want more language support, you can switch to cloud-based recognition which supports more language.

There are endless use-cases and possibilities with Firebase text recognition. It can be used to extract text from vehicles, credit cards, hoardings and any other place. When it comes to accessibility, Firebase support is enormous. In this blog, we will discuss the implementation of text recognition using Firebase and Kotlin.

  1. Connect your Project with Firebase Face detection
  2. Create a bitmap from the camera or the gallery. (In this project I am taking a picture using phone’s camera)
  3. Using FirebaseVisionImage create to convert the bitmap to FirebaseVisionImage getting it ready to extract the text.
  4. Create a FirebaseVision detector instance and use the onDeviceTextRecognizer for extracting the text from the picture
  5. Pass your bitmap to this detector which will be returning the extracted text.

Connect your Project with Firebase Face detection

In your new project, select Tools>Firebase>
Select the option in the highlighted box
Once connected to firebase, it will show like this.

Create a bitmap from the camera or from the gallery. (In this project I am taking a picture using phone’s camera)

The above code is very straight forward. takepicture method takes the user straight to the camera. Once the user clicks the picture and clicks on the “OK” button, the app will return the bitmap to the method activityforresult.

Using FirebaseVisionImage create to convert the bitmap to FirebaseVisionImage getting it ready to extract the text.

Create a FirebaseVision detector instance and use the onDeviceTextRecognizer for extracting the text from the picture

Pass your bitmap to this detector which will be returning the extracted text.

Text recognition can be done both on-device and cloud, which is pretty awesome. Comparatively text recognition seems to be very simple and straightforward which is what I felt, maybe it’s because I am trying it after face detection. Try it by yourself and see the magic.

You can find the whole project here in Github. This is a public repo which has many demo projects. You can use GitZip to download a specific project from this repo. Paste this link in GitZip and you have it.

Follow me on Twitter and medium. Feel free to contribute to Repo — AndroidAppSamples. Let’s grow together 💚

--

--

Sreedev

A passionate coder👨‍💻, Data science enthusiast📉, Love to learn and travel🧗🏽‍♂️ . Twitter: @Sreedevr5, https://github.com/Sreedev