Jump to top

Landmark Recognition

Get started with ML Landmark Recognition.

Landmark recognition can recognize well-known landmarks in an image. It returns the landmarks that were recognized, along with each landmark's geographic coordinates and the region of the image the landmark was found.

Given an image file, the Landmark Recognition service will attempt to recognize one or more landmarks, offering information such as:

  • The 4-point coordinates of the landmarks on the image.
  • Latitude & Longitude locations of the landmarks.
  • The confidence the Machine Learning service has in it's own results.
  • An entity ID for use on Google's Knowledge Graph Search API.

Cloud Landmark Recognition

The cloud based landmark recognition service uploads a given image document to the Firebase services, processes the results and returns them. To get started, call the cloudLandmarkRecognizerProcessImage method with a path to a local image file on your device:

import { utils } from '@react-native-firebase/app';
import ml from '@react-native-firebase/ml';

async function processLandmarks(localPath) {
  const landmarks = await ml().cloudLandmarkRecognizerProcessImage(localPath);

  landmarks.forEach(landmark => {
    console.log('Landmark name: ', landmark.landmark);
    console.log('Landmark locations: ', block.locations);
    console.log('Confidence score: ', block.confidence);
  });
}

// Local path to file on the device
const localFile = `${utils.FilePath.PICTURES_DIRECTORY}/image-file.jpg`;

processLandmarks(localFile).then(() => console.log('Finished processing file.'));

Configuration

To help speed up requests and improve results, the cloudLandmarkRecognizerProcessImage method accepts an optional configuration object.

import ml, { MLCloudLandmarkRecognizerModelType } from '@react-native-firebase/ml';

const landmarks = await ml().cloudLandmarkRecognizerProcessImage(localPath, {
  // Limit the results
  maxResults: 2,
  // Set the model type
  modelType: MLCloudLandmarkRecognizerModelType.LATEST_MODEL,
});

By default, the service will use a stable model to detect landmarks. However, if you feel results are not up-to-date, you can optionally use the latest model available. Results however may change unexpectedly.

View the MLCloudLandmarkRecognizerOptions documentation for more information.