Skip to content

Vision Landmarks Recognize Landmarks

Tua Rua edited this page Oct 14, 2018 · 5 revisions

The contents of this page are based on the original Firebase Documentation

You can use ML Kit to recognize well-known landmarks in an image.

Use of ML Kit to access Cloud ML functionality is subject to the Google Cloud Platform License Agreement and Service Specific Terms, and billed accordingly. For billing information, see the Firebase Pricing page.

Before you begin

  1. If you have not upgraded your project to a Blaze plan, do so in the Firebase console. Only Blaze-level projects can use the Cloud Vision APIs.
  2. In the Google Cloud Console, enable the Cloud Vision API:
    • Open the Cloud Vision API in the Cloud Console API library.
    • Ensure that your Firebase project is selected in the menu at the top of the page.
    • If the API is not already enabled, click Enable.

Before you deploy to production an app that uses a Cloud API, you should take some additional steps to prevent and mitigate the effect of unauthorized API access.

Configure the landmark detector

By default, the Cloud detector uses the stable version of the model and returns up to 10 results. If you want to change either of these settings, specify them with a CloudDetectorOptions object as in the following example:

var options:CloudDetectorOptions = new CloudDetectorOptions();
options.modelType = CloudModelType.latest;
options.maxResults = 20;

In the next step, pass the CloudDetectorOptions object when you create the Cloud detector object.

Run the landmark detector

To recognize landmarks in an image, pass the image as a Bitmapdata to the CloudLandmarkDetector's detect() method:

  1. Get an instance of CloudLandmarkDetector:
var vision:VisionANE = VisionANE.vision;
var cloudDetector: CloudLandmarkDetector = vision.cloudLandmarkDetector(options);
// Or, to use the default settings:
// var cloudDetector = vision.cloudLandmarkDetector();
  1. Create a VisionImage object using a Bitmapdata.
var visionImage:VisionImage = new VisionImage(bmpLandmarkImage.bitmapData);
  1. Then, pass the image to the detect() method:
cloudLandmarkDetector.detect(visionImage, function (landmarks:Vector.<CloudLandmark>, error:LandmarkError):void {
    if (error) {
        // ...
        return;
    }
    // Recognized landmarks
    // ...
}

Get information about the recognized landmarks

If landmark recognition succeeds, an array of CloudLandmark objects will be passed to the completion handler. From each object, you can get information about a landmark recognized in the image. For example:

for each (var landmark:CloudLandmark in landmarks) {
    var landmarkDesc:String = landmark.landmark;
    var boundingPoly:Retangle = landmark.frame;
    var entityId:String = landmark.entityId;

    // A landmark can have multiple locations: for example, the location the image
    // was taken, and the location of the landmark depicted.
    for each (var location:LatitudeLongitude in landmark.locations) {
        var latitude:Number = location.latitude
        var longitude:Number = location.longitude
    }
    var confidence:Number = landmark.confidence
}

Next steps

Before you deploy to production an app that uses a Cloud API, you should take some additional steps to prevent and mitigate the effect of unauthorized API access.

Clone this wiki locally