Huawei ML Kit-Document Skew Correction

Prolusion

This era is revolutionary for the science and research as most of the innovation is for the consumer needs.

We all know that document scanning is routine errand for most of us and a dire need for today’s digital world.

In such needs, we often require a powerful mechanism which can correct the informalities and skew for our documents.

Document Skew Correction is a technique which helps in correcting the tilted images to the right facing angle which further improvise the visibility of the image.

Huawei ML Kit offers a robust API for skew correction which enables automatic position identification of a document in an image and corrects the shooting angle. It also allows users to customize the edge points.

Suggestions

It is recommended the shooting angle of the image should be within 30 degrees.

It is recommended that the image size be within the range of 320 x 320 px to 1920 x 1920 px.

Skew detection API supports JPG, JPEG, and PNG image formats.

Development Overview

Prerequisite

Must have a Huawei Developer Account

Must have Android Studio 3.0 or later

Must have a Huawei phone with HMS Core 4.0.2.300 or later

EMUI 3.0 or later

Software Requirements

Java SDK 1.7 or later

Android 5.0 or later

Preparation

Create an app or project in the Huawei app gallery connect.

Provide the SHA Key and App Package name of the project in App Information Section and enable the ML Kit API.

Download the agconnect-services.json file.

Create an Android project.

Integration

Add below to build.gradle (project)file, under buildscript/repositories and allprojects/repositories.

Maven {url ‘http://developer.huawei.com/repo/'}

Add below to build.gradle (app) file, under dependencies.

To use the Base SDK of ML Kit-Document Skew Correction, add the following dependencies:

dependencies{

// Import the base SDK.

implementation ‘com.huawei.hms:ml-computer-vision-documentskew:2.0.4.300’

}

To use the Full SDK of ML Kit- Document Skew Correction, add the following dependencies:

dependencies{

// Import the Model Package.

implementation ‘com.huawei.hms:ml-computer-vision-documentskew-model:2.0.4.300’

}

Adding permissions

<uses-permission android:name=”android.permission.CAMERA “ />

<uses-permission android:name=”android.permission.READ_EXTERNAL_STORAGE” />

Automatically Updating the Machine Learning Model

Add the following statements to the AndroidManifest.xml file to automatically install the machine learning model on the user’s device.

<meta-data

android:name=”com.huawei.hms.ml.DEPENDENCY”

android:value= “dsc”/>

Development Process

This article focuses on demonstrating the capabilities of Huawei’s ML Kit: Document Skew Correction API’s.

Here is the example of “SUPER DOC” application which allows user to capture and fetch the images from local memory of the device and let them correct using the document which explains how we can integrate this powerful API to leverage the benefits of correcting a skewed document image to provider the right angle to the document which eventually improves the readability of the document.

Skewdetect Activity

This activity is responsible to click and fetch the images and detect them for the skew correction and further align them and provide the output as aligned document image.

Skewdetect Activity View Class

This class is responsible for creating the UI definition of the application.

Results

Conclusion

In this article we took a small step to create and demonstrate the integration of Document Skew Correction API’s from Huawei ML Kit for better document image readability.

Upcoming article will have the integration of multiple ML API’s under one powerful application.

Stay tuned!!

References

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/documentskewcorrection-0000001051703156