[Huawei Developers] Sherlock F:
Introduction

Often, when you take screenshots of text and images you find online and share them with your friends, the apps you use to send them will automatically compress the screenshots. This means the people receiving them get low definition images which are hard to read.

Is there any way to solve this problem? Of course! ML Kit's text super-resolution capability improves text resolution in images. It enables users to magnify images containing text until they're 9 times bigger while greatly enhancing the text’s definition, making it easier to read.

Application Scenarios

The text super-resolution capability is useful in a huge range of situations. For example, when screenshots are compressed, the text super-resolution capability will restore them to their original definition.

When you take a photograph of a document from far away, or can't properly adjust the focus, the text may not be clear. In this situation, you can use the text super-resolution capability to improve the definition and readability of the document.

Pretty useful, right? Below, I'll show you how to integrate this capability

Text Super-Resolution Development

1. Configure the Maven Repository Address

1.1 Open the build.gradle File in the Root Directory of Your Android Studio Project

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/431/408/2640065000000431408.20201013075421.80564375187952586730458674412878:50511020032940:2800:12397E65694A39C2565EE55DCCAB3479FF19B8A655B13CCE359C806042392219.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/431/408/2640065000000431408.20201013075421.80564375187952586730458674412878:50511020032940:2800:12397E65694A39C2565EE55DCCAB3479FF19B8A655B13CCE359C806042392219.jpg[/IMG]

1.2 Add the AppGallery Connect Plug-in and the Maven Repository

Go to allprojects > repositories and configure the Maven repository address for the HMS Core SDK.

allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}

Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.

buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}

2. Integrate the Text Image Super-Resolution SDK

2.1 Full SDK Integration (Recommended)

dependencies{
// Import the base SDK.
Implementation 'com.huawei.hms:ml-computer-vision-textimagesuperresolution:2.0.3.300'
// Import the text image super-resolution model package.
implementation 'com.huawei.hms:ml-computer-vision-textimagesuperresolution-model:2.0.3.300'
}

2.2 Add Configurations to the File Header

apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'

2.3 Update the Machine Learning Model

<meta-data
android:name="com.huawei.hms.ml.DEPENDENCY"
android:value= "tisr"/>

3. Code Development

3.1 Create a Text Image Super-Resolution Analyzer

MLTextImageSuperResolutionAnalyzer analyzer = MLTextImageSuperResolutionAnalyzerFactory.getInstance().getTextImageSuperResolutionAnalyzer();

3.2 Create an MLFrame Object by Using android.graphics.Bitmap

The bitmap type must be ARGB8888. If it isn’t, you’ll need to convert it.

// Create an MLFrame object using the bitmap. The bitmap parameter indicates the input image.
MLFrame frame = new MLFrame.Creator().setBitmap(bitmap).create();

3.3 Processing Super-Resolution for Images That Contain Texts

Task<MLTextImageSuperResolutionResult> task = analyzer.asyncAnalyseFrame(frame);
task.addOnSuccessListener(new OnSuccessListener<MLTextImageSuperResolutionResult>() {
public void onSuccess(MLTextImageSuperResolutionResult result) {
// Processing logic for super-resolution success.
}})
.addOnFailureListener(new OnFailureListener() {
public void onFailure(Exception e) {
// Processing logic for super-resolution failure.
if (e instanceof MLException) {
MLException mlException = (MLException)e;
// Obtain the result code. You can process the result code and customize the messages displayed to users.
int errorCode = mlException.getErrCode();
// Obtain the error information. You can quickly locate the fault based on the result code.
String errorMessage = mlException.getMessage();
} else {
// Other errors.
}
});

3.4 Stop the Analyzer to Release Detection Resources Once the Super-Resolution is Complete

if (analyzer != null) {
analyzer.stop();
}

GitHub Source Code