Introduction to HMS ML Kit — Landmark Recognition

Ismail Oguzhan Ay
Huawei Developers
Published in
4 min readNov 30, 2020

Hello, we will talk about landmark recognition service of HMS ML Kit today. Wouldn’t you want to quickly access the information of landmarks in your applications? If your answer is yes, the landmark recognition service does it so easily for you in your application.

What is the Landmark Recognition Service ?

The landmark recognition service enables you to obtain the landmark name, landmark longitude and latitude, and confidence of the input image. A higher confidence indicates that the landmark in the input image is more likely to be recognized. Based on the obtained information, you can create more personalized app experience for users. Currently, more than 17,000 global landmarks can be recognized.

With the landmark recognition service, we can reach the information of landmark name and its coordinates as like longitude and latitude. Landmark recognition can be used in tourism scenarios. For example, you can integrate this service into a travel app so that images taken by users are detected by ML Kit to return the landmark name and address, and the app can provide the brief introduction and tour suggestions based on the returned information.

Before the starting implementation, some important points

  • In landmark recognition, the device calls the on-cloud API for detection and the detection algorithm model runs on the cloud.
  • During commissioning and usage, ensure that the device can access the Internet.
  • Set authentication information for your app. For details, please refer to Notes on Using Cloud Authentication Information.
  • Check the assigning permissions, the scene detection needs INTERNET in AndroidManifest.xml. For all permission necessaries, please check that list.

Development Process

We need to follow some steps for the integration of Huawei ML Kit.

  1. We need to register as a developer account in AppGallery Connect.
  2. We create an application and enable ML Kit from AppGallery Connect.
  3. After the configuration in AppGallery Connect, let’s integrate the Huawei ML Kit into our demo application.

a. We need to get agconnect-services.json file for configurations from AppGallery Connect. Then, we add it into our application project level under the app folder.

b. After that, we need to add dependencies into gradle files.

Let’s start coding !

We create an activity which name is LandmarkRecognitionActivity. It’s layout has an button for getting landmark image from device storage. It sends the image to landmark recognition service to cloud for recognizing the landmark and it returns landmark name, possibility and coordinates(longitude and latitude). We need api key for setting the api key usages on cloud. We can reach our api key from the agconnect-services.json file which is under the project level side in app folder, the api key is under the client part.

After the getting required permissions, we called startActivityForResult() method. In onActivityResult() method, we get the image from storage as a bitmap, then we called performLandmarkRecogOnCloud() method with bitmap.

We set the settings MLRemoteLandmarkAnalyzerSetting and set the pattern type as STEADY_PATTERN for stable results. There are two options for that STEADY_PATTERN for stable results and NEWEST_PATTERN for latest results. Lastly in settings, we set the setLargestNumOfReturns for maximum number of recognition results.

After the set the settings, we create the analyzer with settings value. Then, we set the frame with bitmap. Lastly, we created a task for list of MLRemoteLandmark object. We have listener functions for success and failure. The service returns list of results. We need landmark name, possibility and latitude, longitude parameters for our demo case. You can use these informations for your necessaries in your application use cases and integrate landmark recognition service easily.

Finally, we completed demo application about the usage of landmark recognition service with Huawei ML Kit. I hope this article will be useful for implementation and use case usages.

Thank You ! ..

For more details, please check these useful links :

--

--