• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

Expert: Search product by Image category label using Huawei HiAI

Search This thread

muraliameakula

Senior Member
Dec 29, 2020
99
3
Introduction


In this article, we will learn how to integrate Huawei image category labeling. We will build an application with smart search feature where using image from gallery or camera to find the 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
  1. Configure the application on the AGC.
  2. Apply for HiAI Engine Library
  3. 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.
huawei-HiAI.png


Step 2: Click Apply for HUAWEI HiAI kit.
apply.png


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


Step 4: Verify the application details and click Submit button.
Step 5: Click the Download SDK button to open the SDK list.
download sdk.png


Step 6: Unzip downloaded SDK and add it to your android project under the libs folder.
cke_1409.png


Step 7: Add jar files dependences into app build.gradle file.
Code:
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.
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'

Root level gradle dependencies.
Code:
maven { url 'https://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.4.1.300'

Step 3: Add permission in AndroidManifest.xml
Code:
<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.
Code:
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 labelDetector instance with context as parameter
Code:
LabelDetector labelDetector = new LabelDetector(getApplicationContext());

Place the Bitmap image to be processed in VisionImage
Code:
bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
VisionImage image = (bitmap == null) ? null : VisionImage.fromBitmap(bitmap);

Define Label, the image label result class.
Code:
Label label = new Label();

Call the detect method to obtain the label detection result.
Code:
int resultCode = labelDetector.detect(image, label, null);

Category definitions
cke_1410.png


Find all categories definition here.

Result

cke_1411.png

cke_1412.png

cke_1413.png

cke_1414.png

cke_1415.png
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.
  1. What is Image category labeling?
  2. Features of Image category labeling
  3. How to integrate Image category labeling using Huawei HiAI
  4. How to Apply Huawei HiAI
  5. Search product by image label
Reference



Happy coding

Original Source