Ever seen a breathtaking landmark or scenic attraction when flipping through a book or magazine, and been frustrated by failing to find its name or location — wouldn’t be so nice if there was an app that could tell you what you’re seeing!
Fortunately, there’s HUAWEI ML Kit, which 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 for the input image. 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.
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, you’ll need to make sure that the device can access the Internet.
Configuring the development environment
- Create an app in AppGallery Connect.
For details, see Getting Started with Android.
2.Enable ML Kit.
Click here for more details.
Download the agconnect-services.json file, which is automatically generated after the app is created. Copy it to the root directory of your Android Studio project.
Configure the Maven repository address for the HMS Core SDK.
Integrate the landmark recognition SDK.
Configure the SDK in the build.gradle file in the app directory.
Obtain the camera permission to use the camera.
Set the API key. This service runs on the cloud, which means that an API key is required to set the cloud authentication information for the app. This step is a must, and failure to complete it will result in an error being reported when the app is running.
Create a landmark analyzer through either of the following methods:
// Method 1: Use default parameter settings.
// Method 2: Use customized parameter settings through the MLRemoteLandmarkAnalyzerSetting class.
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.
Start landmark recognition after obtaining the bitmap of the image. Since this service runs on the cloud, if the network status is poor, data transmission can be slow. Therefore, it's recommended that you add a mask to the bitmap prior to landmark recognition.
Testing the App
The following illustrates how the service works, using the Oriental Pearl Tower in Shanghai and Pyramid of Menkaure as examples:
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 it may take some time to complete. It is recommended that you use the mask before performing landmark recognition.
3. If you are interested in other ML Kit services, feel free to check out our official materials.
To learn more, please visit:
>> Reddit to join developer discussions
>> Stack Overflow to solve integration problems
Follow our official account for the latest HMS Core-related news and updates.