World is evolving, are you?

Text Recognition using MLKit in Android…
Text Recognition using MLKit in Android…

ML (Machine Learning) Kit was one of the key highlights in Google I/O 2018. This kit is comprised of

  1. Image Labeling
  2. Text- Recognition
  3. Face- Detection
  4. Barcode- scanning
  5. Landmark- detection
From google site…
From google site…

What’s In this Post…

This post will focus on text recognition from image in Android. I have covered text recognition in Flutter in my previous post.

First things first, we need to create a firebase project. Don’t worry its not an daunting task.

Go to https://firebase.google.com/ and click Get Started.

Please note that the name of your app should be same in the Firebase, your project’s manifest.xml and in the app-level build.gradle.

Firebase console
Firebase console
app-level build.gradle
app-level build.gradle

Manifest.xml

Manifest.xml

Include the google-services.json in the app directory of android. (one of the steps in Firebase project setup).

Import the project from

https://github.com/AseemWangoo/Android-Programs/blob/master/text_recognition_mlkit_android.zip

Please note, I have used com.google.firebase.codelab.mlkit as my package name, feel free to try out with yours (change the manifest, app level gradles accordingly as shown in images above).

On Click of Find Text, following code snippet gets called :

Text Recognition…
Text Recognition…

You can see as the detector.detectInImage is successful, then processTextRecogntion gets called.

Process Text Recognition….
Process Text Recognition….

In the texts.getBlocks() (First line of function), following are the values of texts :

texts.getBlocks()
texts.getBlocks()

Inside the zzxq,

Developers text recognized…
Developers text recognized…

Similarly, in the List<FirebaseVisionText.Line> lines, following are the values of lines :

"List<FirebaseVisionText.Line

Finally, the text is displayed in the UI….

Text Recognized…
Text Recognized…

What happens on Find Text (cloud)…

The function which gets called on the Find Text (cloud) is runCloudTextRecognition….

Cloud based text recognition…
Cloud based text recognition…

Now here in detector.detectInImage, we observe onFailureListener alongwith the following stack trace :

{
“code”:403,
“errors”:[
{
“domain”:”usageLimits”,
“message”:”Cloud Vision API has not been used in project 894591301974 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/vision.googleapis.com/overview?project=894591301974 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.”,
“reason”:”accessNotConfigured”,
“extendedHelp”:”https://console.developers.google.com
}
],
“message”:”Cloud Vision API has not been used in project 894591301974 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/vision.googleapis.com/overview?project=894591301974 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.”,
“status”:”PERMISSION_DENIED
}

Visit this link for billing under Cloud Vision API,

https://cloud.google.com/vision/docs/before-you-begin

Video demonstration :

For complete source code, visit

https://github.com/AseemWangoo/Android-Programs/blob/master/text_recognition_mlkit_android.zip

P.S……………………….

Valuable comments