Firebase ML Kit 101 : Landmark Recognition

Hitanshu Dhawan
Nov 20, 2018 · 4 min read
Image for post
Image for post

Landmark Recognition is the process of recognising popular landmarks in an image.

Many social media giants use this landmark recognition technology in their apps to know and understand their users better. It also helps them to provide a unique and personalised experience to their users. Hence, improving the overall user experience.

With ML Kit’s Landmark Recognition API, you can get the landmarks that were recognised in the image along with their geographic coordinates.

Firebase ML Kit Series

Let’s look into the ML Kit’s Landmark Recognition API and how we can integrate it into our apps.

ML Kit’s Landmark Recognition

With ML Kit’s Landmark Recognition API you can get the following information about the landmarks from an image.

Image for post
Image for post
image courtesy: https://firebase.google.com/docs/ml-kit/recognize-landmarks

Note: Firebase ML Kit is in beta as of January ‘19.

Let’s Code!

Step 1 : Add Firebase to your app

Step 2 : Include the dependency

dependencies {
// ...
implementation 'com.google.firebase:firebase-ml-vision:19.0.2'
}

Step 3 : Get! — the Image

Image for post
Image for post
creating FirebaseVisionImage object from different image types

In my sample app I’ve used a Bitmap image to create a FirebaseVisionImage object.

val image = FirebaseVisionImage.fromBitmap(bitmap)

To create FirebaseVisionImage object from other image types, please refer to the official documentation.

Step 4 : Set! — the Model

val detector = FirebaseVision.getInstance().visionCloudLandmarkDetector

By default, the landmark recognition API uses the STABLE version of the model and returns not more than 10 landmarks.

You can change this configuration by passing in an object of FirebaseVisionCloudDetectorOptions to the landmark recognition model.

val options = FirebaseVisionCloudDetectorOptions.Builder()
.setModelType(FirebaseVisionCloudDetectorOptions.LATEST_MODEL)
.setMaxResults(5)
.build()

val detector = FirebaseVision.getInstance().getVisionCloudLandmarkDetector(options)

Step 5 : Gooo!

detector.detectInImage(image)
.addOnSuccessListener {
//
Task completed successfully
}
.addOnFailureListener {
//
Task failed with an exception
}

Step 6 : Extract the information

You can extract all this information like this.

Have a Look!

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

The full source-code with other ML Kit APIs can be found here!

Thanks for reading! Share this article if you found it useful.
Please do Clap 👏 to show some love :)

Let’s become friends on LinkedIn, GitHub, Facebook, Twitter.

AndroIDIOTS

An android developer publication to stay updated with whats…

Hitanshu Dhawan

Written by

Software Engineer @UrbanClap | Google Certified Android Developer

AndroIDIOTS

An android developer publication to stay updated with whats new in android, best practices and how to become a better android developer

Hitanshu Dhawan

Written by

Software Engineer @UrbanClap | Google Certified Android Developer

AndroIDIOTS

An android developer publication to stay updated with whats new in android, best practices and how to become a better android developer

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store