How to Recognizes 17,000+ Landmarks With Machine Learning

Jackson
4 min readNov 19, 2021

--

Ever seen a breathtaking landmark or scenery while flipping through a book or magazine, and been frustrated because you don’t know what it’s called or where it is? Wouldn’t it be great if there was an app that could tell you what you’re seeing! Fortunately, there’s our ML Kit. It comes with a landmark recognition service and makes it remarkably easy to develop such an app. So let’s take a look at how to use this service!

Introduction to Landmark Recognition​

The landmark recognition service enables you to obtain the landmark name, landmark longitude and latitude, and even a confidence value of the input image. When you input an image for recognition, a confidence value will be provided whereby a higher confidence value indicates that the landmark in the input image is more likely to be recognized. You can then use this information to create a highly-personalized experience for your users. Currently, the service is capable of recognizing more than 17,000 landmarks around the world.

When using landmark recognition, the device calls the on-cloud API for detection, and the detection algorithm model runs on the cloud. You’ll need to ensure that the device is connected to the Internet while using this service.

Preparations​

Configuring the development environment

  1. Create an app in AppGallery Connect.

For details, see Getting Started with Android.

2. Enable ML Kit.

Click here for more details.

3. Download the agconnect-services.json file, which is automatically generated after the app is created. Copy it to the app directory of the Android Studio project.

4. Configure the Maven repository address for the HMS Core SDK.
5. Integrate the landmark recognition SDK.
Configure the SDK in the build.gradle file in the app directory.

Add the AppGallery Connect plugin configuration as needed through either of the following methods:
Method 1: Add the following information under the declaration in the file header:

Method 2: Add the plugin configuration in the plugins block:

Code Development
1. Obtain the camera permission to use the camera.
(Mandatory) Set the static permission.

(Mandatory) Obtain the permission dynamically.

2. Set the API key. This service runs on the cloud, meaning an API key is required to set the cloud authentication information for the app. This step is mandatory, and failure to complete it will result in an error being reported when the app is running.

3. Create a landmark analyzer through either of the following methods:

4. Convert the image collected from the camera or album to a bitmap. This is not provided by the landmark recognition SDK, so you’ll need to implement it on your own.

Enable the landmark recognition service in the callback.

5. Start landmark recognition after obtaining the bitmap of the image. As this service runs on the cloud, a poor network connection may slow down data transmission. Therefore, it’s recommended that you add a mask to the bitmap prior to landmark recognition.

Result

The following illustrates how the service works, using the Oriental Pearl Tower in Shanghai and Pyramid of Menkaure as examples:

Conclusion

The ML Kit landmark recognition service enables you to obtain the landmark name, landmark longitude and latitude, and even a confidence value of the input image.

Tips

  1. Before performing landmark recognition, set the API key to set the cloud authentication information for the app. Otherwise, an error will be reported while the app is running.
  2. Landmark recognition runs on the cloud, so completion may be slow. It is recommended that you add a mask before performing landmark recognition.

References​

For more details, you can go to:

https://developer.huawei.com/consumer/en/hms/huawei-mlkit?ha_source=hms1

--

--

Jackson

Software engineer | Android app development | Java | JS | Python | Machine learning