[Huawei Developers] muraliameakula:
Introduction

In this article we will learn how to integrate Huawei semantic segmentation using Huawei HiAI.

What is Semantic Segmentation?

In simple “Semantic segmentation is the task of assigning a class to every pixel in a given image.”

Semantic segmentation performs pixel-level recognition and segmentation on a photo to obtain category information and accurate position information of objects in the image. The foregoing content is used as the basic information for semantic comprehension of the image, and can be subsequently used in multiple types of image enhancement processing.

Types of objects can be identified and segmented

People

Sky

Greenery (including grass and trees)

Food

Pet

Building

Flower

Water

Beach

Mountain

Features

Fast: This algorithm is currently developed based on the deep neural network, to fully utilize the NPU of Huawei mobile phones to accelerate the neural network, achieving an acceleration of over 10 times.

Lightweight: This API greatly reduces the computing time and ROM space the algorithm model takes up, making your app more lightweight.

How to integrate Semantic Segmentation

Configure the application on the AGC.

Apply for HiAI Engine Library

Client application development process.

Configure application on the AGC

Follow the steps

Step 1: We need to register as a developer account in AppGallery Connect. If you are already a developer ignore this step.

Step 2: Create an app by referring to Creating a Project and Creating an App in the Project

Step 3: Set the data storage location based on the current location.

Step 4: Generating a Signing Certificate Fingerprint.

Step 5: Configuring the Signing Certificate Fingerprint.

Step 6: Download your agconnect-services.json file, paste it into the app root directory.

Apply for HiAI Engine Library

What is Huawei HiAI ?

HiAI is Huawei’s AI computing platform. HUAWEI HiAI is a mobile terminal–oriented artificial intelligence (AI) computing platform that constructs three layers of ecology: service capability openness, application capability openness, and chip capability openness. The three-layer open platform that integrates terminals, chips, and the cloud brings more extraordinary experience for users and developers.

How to apply for HiAI Engine?

Follow the steps

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

Step 2: Click Apply for HUAWEI HiAI kit.

Step 3: Enter required information like Product name and Package name, click Next button.

Step 4: Verify the application details and click Submit button.

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

Step 6: Unzip downloaded SDK and add into your android project under libs folder.

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

implementation fileTree(include: ['*.aar', '*.jar'], dir: 'libs')
implementation 'com.google.code.gson:gson:2.8.6'
repositories {
flatDir {
dirs 'libs'
}
}

Client application development process

Follow the steps

Step 1: Create an Android application in the Android studio (Any IDE which is your favorite).

Step 2: Add the App level Gradle dependencies. Choose inside project Android > app > build.gradle.

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

Root level gradle dependencies.

maven { url 'https://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.4.1.300'

Step 3: Add permission in AndroidManifest.xml

<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"/>

Step 4: Build application.

Perform initialization by the VisionBase static class, to asynchronously obtain a connection to the service.

private void initHuaweiHiAI(Context context){
VisionBase.init(context, new ConnectionCallback(){
@Override
public void onServiceConnect(){
Log.i(TAG, "onServiceConnect");
}
@Override
public void onServiceDisconnect(){
Log.i(TAG, "onServiceDisconnect");
}
});
}

Define the imageSegmentation instance, and use the context of this app as the input parameter.

ImageSegmentation imageSegmentation = new ImageSegmentation(this);

Set the model type.

SegmentationConfiguration sc = new SegmentationConfiguration();
sc.setSegmentationType(SegmentationConfiguration.TYPE_SEMANTIC);
imageSegmentation.setSegmentationConfiguration(sc);

Define VisionImage.

VisionImage image = null;

Place the Bitmap image to be processed in VisionImage.

image = VisionImage.fromBitmap(bitmap);

Define the segmentation result class.

ImageResult out = new ImageResult();

Call doSegmentation to obtain the segmentation result.

int resultcode = is.doSegmentation (image, out, null);

Convert the result into the Bitmap format.

Bitmap bmp = out.getBitmap();

Result

​

Tips and Tricks

Check dependencies downloaded properly.

Latest HMS Core APK is required.

Min SDK is 21. Otherwise we get Manifest merge issue.

If you are taking image from a camera or gallery make sure your app has camera and storage permission.

Add the downloaded huawei-hiai-vision-ove-10.0.4.307.aar, huawei-hiai-pdk-1.0.0.aar file to libs folder.

Conclusion

In this article, we have learnt the following concepts.

What is Semantic segmentation?

Types of object identified and segmented

Features of sematic segmentation

How to integrate semantic segmentation using Huawei HiAI

How to Apply Huawei HiAI

How to build the application.

Reference

Semantic Segmentation

Apply for Huawei HiAI

Original Source