Intermediate: How to extract the data from Image using Huawei HiAI Text Recognition service in Android

sujith E
Huawei Developers
Published in
4 min readJun 14, 2021

--

Introduction

In this article, we will learn how to implement Huawei HiAI kit using Text Recognition service into android application, this service helps us to extract the data from screen shots and photos.

Now a days everybody lazy to type the content, there are many reasons why we want to integrate this service into our apps. User can capture or pic image from gallery to retrieve the text, so that user can edit the content easily.

Use Case: Using this HiAI kit, user can extract the unreadable image content to make useful, let’s start.

Requirements

1. Any operating system (MacOS, Linux and Windows).

2. Any IDE with Android SDK installed (IntelliJ, Android Studio).

3. HiAI SDK.

4. Minimum API Level 23 is required.

5. Required EMUI 9.0.0 and later version devices.

6. Required process kirin 990/985/980/970/ 825Full/820Full/810Full/ 720Full/710Full

How to integrate HMS Dependencies

1. First of all, we need to create an app on AppGallery Connect and add related details about HMS Core to our project. For more information check this link

2. Download agconnect-services.json file from AGC and add into app’s root directory.

3. Add the required dependencies to the build.gradle file under root folder.

4. Add the required dependencies to the build.gradle file under root folder.

maven {https://developer.huawei.com/repo/'}

classpath 'com.huawei.agconnect:agcp:1.4.1.300'

5. Add the App level dependencies to the build.gradle file under app folder

apply plugin: 'com.huawei.agconnect'

6. Add the required permission to the Manifestfile.xml file.

<uses-permission android:name=”android.permission.INTERNET” />
<uses-permission android:name=”android.permission.CAMERA”/>
<uses-permission android:name=”android.permission.READ_EXTERNAL_STORAGE”/>
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/>
<uses-permission android:name=”android.hardware.camera”/>
<uses-permission android:name=”android.permission.HARDWARE_TEST.camera.autofocus”/>

7. Now, sync your project.

How to apply for HiAI Engine Library

1. Navigate to this URL, choose App Service > Development and click HUAWEI HiAI.

2. Click Apply for HUAWEI HiAI kit.

3. Enter required information like product name and Package name, click Next button.

4. Verify the application details and click Submit button.

5. Click the Download SDK button to open the SDK list.

6. Unzip downloaded SDK and add into your android project under lib folder.

7. Add jar files dependences into app build.gradle file.

8. After completing this above setup, now Sync your gradle file.

Let’s do code

I have created a project on Android studio with empty activity let’s start coding.

In the MainActivity.java we can create the business logic.

Demo

Tips & Tricks

1. Download latest Huawei HiAI SDK.

2. Set minSDK version to 23 or later.

3. Do not forget to add jar files into gradle file.

4. Screenshots size should be 1440*15210 pixels.

5. Photos recommended size is 720p.

6. Refer this URL for supported Countries/Regions list.

Conclusion

In this article, we have learned how to implement HiAI Text Recognition service in android application to extract the content from screen shots and photos.

Thanks for reading! If you enjoyed this story, please click the Like button and Follow. Feel free to leave a Comment 💬 below.

Reference

Huawei HiAI Kit URL

--

--