Demystifying HMS ML Kit with Product Visual Search API using Xamarin

HMS ML Kit allows your apps to easily leverage Huawei’s long-term proven expertise in machine learning to support diverse artificial intelligence (AI) applications throughout a wide range of industries.

Manoj Kumar
5 min readJan 25, 2021

Overview

In this article, I will create a demo app along with the integration of HMS ML Kit which based on Cross-platform Technology Xamarin. User can easily scan any items from this application with camera Product Vision Search ML Kit technique and choose best price and details of product.

Service Introduction

HMS ML Kit allows your apps to easily leverage Huawei’s long-term proven expertise in machine learning to support diverse artificial intelligence (AI) applications throughout a wide range of industries.

A user can take a photo of a product. Then the Product Visual Search service searches for the same or similar products in the pre-established product image library and returns the IDs of those products and related information. In addition, to better manage products in real-time, this service supports offline product import, online product addition, deletion, modification, query, and product distribution.

We can capture any kind of image for products to buy or check the price of a product using Machine Learning. It will give the other options so that you can improve your buying skills.

Prerequisite

1. Xamarin Framework

2. Huawei phone

3. Visual Studio 2019

App Gallery Integration process

1. Sign In and Create or Choose a project on AppGallery Connect portal.

2. Add SHA-256 key.

3. Navigate to Project settings and download the configuration file.

4. Navigate to General Information, and then provide Data Storage location.

5. Navigate to Manage APIs and enable APIs which require by application.

Xamarin ML Kit Setup Process

1. Download Xamarin Plugin all the aar and zip files from below url:

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Library-V1/xamarin-plugin-0000001053510381-V1

2. Open the XHms-ML-Kit-Library-Project.sln solution in Visual Studio.

3. Navigate to Solution Explore and right-click on jar Add > Exsiting Item and choose aar file which download in Step 1.

4. Right click on added aar file then choose Properties > Build Action > LibraryProjectZip

Note: Repeat Step 3 & 4 for all aar file.

5. Build the Library and make dll files.

Xamarin App Development

1. Open Visual Studio 2019 and Create A New Project.

2. Navigate to Solution Explore > Project > Assets > Add Json file.

3. Navigate to Solution Explore > Project > Add > Add New Folder.

4. Navigate to Folder(created) > Add > Add Existing and add all DLL files.

5. Select all DLL files.

6. Right-click on Properties, choose Build Action > None.

7. Navigate to Solution Explore > Project > Reference > Right Click > Add References, then navigate to Browse and add all DLL files from recently added folder.

8. Added reference, then click OK.

ML Product Visual Search API Integration

1. Create an analyzer for product visual search. You can create the analyzer using the MLRemoteProductVisionSearchAnalyzerSetting class.

2. Create an MLFrame object by using Android.Graphics.Bitmap. JPG, JPEG, PNG, and BMP images are supported.

3. Implement image detection.

4. After the recognition is complete, stop the analyzer to release recognition resources.

ProductVisionSearchAnalyseActivity.cs

This activity performs all the operation regarding product search with camera.

Xamarin App Build

1. Navigate to Solution Explore > Project > Right Click > Archive/View Archive to generate SHA-256 for build release and Click on Distribute.

2. Choose Distribution Channel > Ad Hoc to sign apk.

3. Choose Demo Keystore to release apk.

4. Finally here is the Result.

Tips and Tricks

1. HUAWEI ML Kit complies with GDPR requirements for data processing.

2. HUAWEI ML Kit does not support the recognition of the object distance and colour.

3. Images in PNG, JPG, JPEG, and BMP formats are supported. GIF images are not supported.

Conclusion

In this article, we have learned how to integrate HMS ML Kit in Xamarin based Android application. User can easily search items online with the help of product visual search API in this application.

Thanks for reading this article. Be sure to like and comments to this article, if you found it helpful. It means a lot to me.

References

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/about-service-0000001052602130

--

--

Manoj Kumar
Manoj Kumar

Responses (1)