[Huawei Developers] Basavaraj.navi:
Introduction

In this article, we will learn how to integrate Huawei image category labeling. We will build an application with a smart search feature where using image from gallery or camera to find similar products.

What is Huawei Image category labeling?

Image category labeling identifies image elements such as objects, scenes, and actions, including flower, bird, fish, insect, vehicle and building based on deep learning methods. It identifies 100 different categories of objects, scenes, actions, tags information, and applying cutting-edge intelligent image recognition algorithms for a high degree of accuracy.

Features

Abundant labels: Supports recognition of 280 types of common objects, scenes, and actions.

Multiple-label support: Adds multiple labels with different confidence scores to a single image.

High accuracy: Identifies categories accurately by utilizing industry-leading device-side intelligent image recognition algorithms.

How to integrate Image category labeling

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 it to your android project under the 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'

}

}Copy code

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'Copy code

Root level gradle dependencies.

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

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

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

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");

}

});

}Copy code

Define the labelDetector instance with context as parameter

LabelDetector labelDetector = new LabelDetector(getApplicationContext());Copy code

Place the Bitmap image to be processed in VisionImage

bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();

VisionImage image = (bitmap == null) ? null : VisionImage.fromBitmap(bitmap);Copy code

Define Label, the image label result class.

Label label = new Label();Copy code

Call the detect method to obtain the label detection result.

int resultCode = labelDetector.detect(image, label, null);

Copy code

Category definitions

Find all categories definition here.

Result

Tips and Tricks

Check dependencies downloaded properly.

Latest HMS Core APK is required.

Min SDK is 21

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

Conclusion

In this article, we have learnt the following concepts.

What is Image category labeling?

Features of Image category labeling

How to integrate Image category labeling using Huawei HiAI

How to Apply Huawei HiAI

Search product by image label

Reference

Happy coding