You can use Firebase ML to recognize well-known landmarks in an image.
Before you begin
- If you have not already added Firebase to your app, do so by following the
steps in the getting started guide
.
- In Xcode, with your app project open, navigate to File > Add Packages .
- When prompted, add the Firebase Apple platforms SDK repository:
- Choose the Firebase ML library.
- Add the
-ObjCflag to the Other Linker Flags section of your target's build settings. - When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.
- In your app, import Firebase:
Swift
import FirebaseMLModelDownloader
Objective-C
@import FirebaseMLModelDownloader ;
-
If you haven't already enabled Cloud-based APIs for your project, do so now:
- Open the Firebase ML APIs page in the Firebase console.
-
If you haven't already upgraded your project to the pay-as-you-go Blaze pricing plan , click Upgrade to do so. (You'll be prompted to upgrade only if your project isn't on the Blaze pricing plan.)
Only projects on the Blaze pricing plan can use Cloud-based APIs.
- If Cloud-based APIs aren't already enabled, click Enable Cloud-based APIs .
Use Swift Package Manager to install and manage Firebase dependencies.
https://github.com/firebase/firebase-ios-sdk.git
Next, perform some in-app setup:
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 VisionCloudDetectorOptions
object as
in the following example:
Swift
let options = VisionCloudDetectorOptions () options . modelType = . latest options . maxResults = 20
Objective-C
FIRVisionCloudDetectorOptions * options = [[ FIRVisionCloudDetectorOptions alloc ] init ]; options . modelType = FIRVisionCloudModelTypeLatest ; options . maxResults = 20 ;
In the next step, pass the VisionCloudDetectorOptions
object when you create the Cloud detector object.
Run the landmark detector
To recognize landmarks in an image, pass the image as aUIImage
or a CMSampleBufferRef
to the VisionCloudLandmarkDetector
's detect(in:)
method: - Get an instance of
VisionCloudLandmarkDetector:Swift
lazy var vision = Vision . vision () let cloudDetector = vision . cloudLandmarkDetector ( options : options ) // Or, to use the default settings: // let cloudDetector = vision.cloudLandmarkDetector()

