World is evolving, are you?

ML (Machine Learning) Kit was one of the key highlights in Google I/O 2018. This kit is comprised of
- Image Labeling
- Text- Recognition
- Face- Detection
- Barcode- scanning
- Landmark- detection

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.


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 :

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

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

Inside the zzxq,

Similarly, in the List<FirebaseVisionText.Line> lines, following are the values of lines :
Finally, the text is displayed in the UI….

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

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……………………….