Skip to main content

Text recognition Using Firebase ML Kit 2020 In Android Studio (Complete Guide) | Step By Step Tutorial

Today, in this post we are going to make an android app that recognizes text from an image using a firebase ml kit in the android studio.


So without wasting more time let's develop this.

Step 1: Add Firebase to your android project:

I recommend you to see how to add firebase to the android project in 5minutes to know how to add it or if you already add it then you can move on to 2nd Step.

Step 2: Add this dependency :

implementation 'com.google.firebase:firebase-ml-vision:24.0.1'

in your app-level build.gradle file in order to use the java classes of ML Kit Android libraries as shown below:


and now click on Sync Now.

Step 3: Now, here is the thing there are two models which u can use to generate a response:

a. On-Device Model (In Spark plan (Default))
b. Cloud-Based Model (In Blaze plan(Need to upgrade))

Only Blaze-level projects can use Cloud-based APIs.

Here is a brief comparison b/w on-device and cloud-based model from the official firebase doc.



If you want to use the cloud-based model then do this:

Upgrade to Blaze Plan and enable Cloud-based APIs.

Step 4: Design the layout of the activity:


Step 5: Select Image from the device:

I recommend you to first go through the post on how to select or capture an image from the device before going further.

So now, let's open the image cropping activity to select the image on button click:


and now get the image by overriding onActivityResult method :


Step 6: Extract text from the image :

We can extract the text if we have one of the following things: 
a. path of the file (Uri of the image) (recommend) or
b. A bitmap of image or
c. Byte Array of image or
d. Byte Buffer of image or
e. Media Image

In this post, we're using the path of the file if you want a guide on the remaining option then comment down I will make for that too.

So now here is a brief summary of how we can extract text from the image:
1. Create a FirebaseVisionImage object from either a Bitmap, Media Image, ByteBuffer, byte array or a file on the device.

2. Then pass this FirebaseVisionImage object to the FirebaseVisionText- Recognizer's processImage method.

As shown below:


Take a moment to see what are the things happening in the method.

Now, Run the app, if everything is done correctly then you see output something like this:



The Source code of this text recognizer app is available at Github.

If you face any problem or have any suggestion please comment it down we love to answer it.

Comment down what next topic you need a guide on? or Drop a message on our social media handle.
 
 Happy coding and designing : )



Comments

Popular posts from this blog

How To Set Up Android Studio/VS Code For Flutter 2021 (Complete Guide) In Ubuntu | Step By Step Tutorial

In this post, we're going to set up the android studio for flutter - Google’s most awaited UI tool kit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase.  So a single codebase for making an application for multiple platforms. Step 1: Download flutter SDK from flutter.dev and after extracting it place the flutter folder inside it at your desired location like this:- Step 2: Open the terminal and Set the path up to the bin folder inside flutter:-  export PATH=$PATH:/home/himanshu/Desktop/fluttersdk/flutter/bin Step 3: Download java 8 and set JAVA_HOME and JRE_HOME path. Run this command in terminal:- sudo apt install openjdk-8-jdk openjdk-8-jre It will download the java 8 package in /usr/lib/jvm/ and now set the JAVA_HOME and JRE_HOME path up to this location for this, Run this command in the terminal:- export JAVA_HOME=/usr/lib/jvm/java...

Detect and Track Object Using Firebase ML Kit In Android Studio 2020(Complete Guide) With Source Code | Step By Step Tutorial

In this post, we're going to detect and track an object in an image using a firebase ml kit in an android studio. This is the output after doing all the steps: So, now make it happen: Step 1: Add Firebase to your android project: I recommend you to see  how to add firebase to the android project in 5minutes  to know how to add it or if you already add it then you can move on to 2nd Step.  Step 2: Add this dependency for the ml kit android libraries to your app-level build.gradle file: implementation 'com.google.firebase:firebase-ml-vision:24.0.1' implementation 'com.google.firebase:firebase-ml-vision-object-detection-model:19.0.3' as shown below and then click on Sync Now. Step 3: Design the layout of the activity: <? xml version ="1.0" encoding ="utf-8" ?> <RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android" android :layout_width ="match_parent" android :la...

Translate Text Using Firebase ML Kit In Android Studio 2020 (Complete Guide) With Source Code |

In this post, we're going to translate the text from one to another language using ml kit of a firebase in android studio. We're translating to English but you can translate to any language you required So, This is the output after you are done with all step: So, now make it happen :) Step 1: Add Firebase to your android project: I recommend you to see  how to add firebase to the android project in 5minutes  to know how to add it or if you already add it then you can move on to 2nd Step. Step 2: Add this dependency for the ml kit android libraries to your app-level build.gradle file:   implementation 'com.google.firebase:firebase-ml-natural-language:22.0.0'   implementation 'com.google.firebase:firebase-ml-natural-language-translate-model:20.0.7' as shown below and then click on Sync Now.: Step 3: Design the layout of the activity: <? xml version ="1.0" encoding ="utf-8" ?> <RelativeLayout xmlns: andr...



DMCA.com Protection Status

Copywrite © 2021 The MindfulCode