Huawei ML Kit-Document Skew Correction


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.


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


Must have a Huawei Developer Account

Must have Android Studio 3.0 or later

Must have a Huawei phone with HMS Core or later

EMUI 3.0 or later

Software Requirements

Java SDK 1.7 or later

Android 5.0 or later


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.


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

Maven {url ‘'}

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

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


// Import the base SDK.

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


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


// Import the Model Package.

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


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.



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.



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!!