
Introduction
In this tutorial, we will learn how to do Optical Character Recognition in Android using Vision API. Here, we will just import the Google Vision API Library with Android Studio and implement the OCR for retrieving text from the image.
Android Mobile Vision API
The Mobile Vision API provides a framework for finding objects in photos and videos. The framework includes detectors, which locate and describe visual objects in images or video frames, and an event-driven API that tracks the position of those objects in video. The Mobile Vision API includes face, bar code, and text detectors, which can be applied separately or together.
This is not only used to get a text from images, but also for structuring the text retrieved. It will divide the captured text into the following categories.
- TextBlock - In this category, the scanned paragraph is captured.
- Line - In this category, the line of text captured from Textblock takes place.
- Element- In this category, the word captured from the line takes place.
Coding Part
Steps
I have split this part into 3 steps as in the following.
Step 1
Creating a New Project with Empty Activity and Gradle Setup.
Step 2
Setting up Manifest for OCR.
Step 3
Implementing OCR in Application.
Step 1
We will start coding for OCR. Create a New Android Project. Add the following line in your app level build.gradle file to import the library.
For Android Studio before 3.0
compile'com.google.android.gms:play-services-vision:11.8.0'
From Android Studio 3.0
implementation 'com.google.android.gms:play-services-vision:11.8.0'
Step 2
Open your Manifest file and add the following code block to instruct the app to install or download the dependencies at the time of installing the app.
<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="ocr"/>
Step 3
Open your activity_main.xml file and paste the following code. It just the designer part of the application.
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:padding="15dp">
- <ImageView
- android:id="@+id/image_view"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:scaleType="centerInside" />
- <Button
- android:id="@+id/btnProcess"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Process" />
- <TextView
- android:id="@+id/txtView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="No Text"
- android:layout_gravity="center"
- android:textSize="25sp" />
- </LinearLayout>


IT pediaPosted Apr 30, 2018, 2:30 PM
This OCR run on drawable image my question is how to run OCR on camera taken image?
Sagar Pandurang KapPosted Jan 3, 2018, 12:02 AM
Very interesting...Keeep posting..