AI-generated Key Takeaways
-
This guide provides step-by-step instructions for migrating projects from Google Mobile Vision (GMV) to ML Kit on iOS for features like Barcode Scanning, Face Detection, and Text Recognition.
-
Before starting the migration, ensure you have Xcode 13.2.1 or later, iOS 15.5 or greater, and a 64-bit architecture (x86_64 or arm64), as ML Kit no longer supports 32-bit architectures.
-
Update your app's Podfile to replace GMV pods with their corresponding ML Kit pods listed in the provided table.
-
Understand the key API changes which include using
MLKVisionImage
for input, dedicated options classes for detector settings, specific classes for creating detectors, support for both synchronous and asynchronous detection, and changes in classes and methods for each API. -
Refer to the detailed API-specific changes for Face Detection, Barcode Scanning, and Text Recognition to map GMV classes and methods to their ML Kit counterparts.
This document covers the steps you need to take to migrate your projects from Google Mobile Vision (GMV) to ML Kit on iOS.
Prerequisites
Before you start to migrate your code, be sure you meet these requirements:
- ML Kit supports Xcode 13.2.1 or later.
- ML Kit supports iOS version 15.5 or greater.
- ML Kit doesn't support 32-bit architectures (i386 and armv7). ML Kit does support 64-bit architectures (x86_64 and arm64).
Update cocoapods
Update the dependencies for the ML Kit iOS cocoapods in your app’s Podfile:
API | GMV Pod | ML Kit Pod |
---|---|---|
Barcode scanning | GoogleMobileVision/BarcodeDetector |
GoogleMLKit/BarcodeScanning |
Face detection | GoogleMobileVision/FaceDetector |
GoogleMLKit/FaceDetection |
Text recognition | GoogleMobileVision/TextDetector |
GoogleMLKit/TextRecognition |
Overall API changes
These changes apply to all APIs:
- GMV’s inference APIs take
UIImage
orCMSampleBufferRef
as input. ML Kit wraps them inside anMLKVisionImage
and takes that as input. - GMV uses
NSDictionary
to pass various detector options. ML Kit uses dedicated options classes for that purpose. - GMV passes the detector type to the single
GMVDetector
class when it creats a detector. ML Kit uses dedicated classes to create separate detector, scanner, and recognizer instances. - GMV's APIs support synchronous detection only. ML Kit's inference APIs can be called synchronously and asynchronously.
- GMV extends
AVCaptureVideoDataOutput
and provides a multi-detector framework for performing multiple detections at the same time. ML Kit doesn't provide such mechanisms, but the same functionality can be implemented by the developer if desired.
API-specific changes
This section describes corresponding GMV and ML Kit classes and methods for each Vision API, and shows how to initialize the API.
FaceDetector
Recode the initialization as shown in this example:
GMV
NSDictionary *options = @{ GMVDetectorFaceMode : @(GMVDetectorFaceAccurateMode), GMVDetectorFaceClassificationType : @(GMVDetectorFaceClassificationAll), GMVDetectorFaceLandmarkType : @(GMVDetectorFaceLandmarkAll) }; GMVDetector *faceDetector = [GMVDetector detectorOfType:GMVDetectorTypeFace options:options];
ML Kit
MLKFaceDetectorOptions *options = [[MLKFaceDetectorOptions alloc] init]; options.performanceMode = MLKFaceDetectorPerformanceModeAccurate; options.classificationMode = MLKFaceDetectorClassificationModeAll; options.landmarkMode = MLKFaceDetectorLandmarkModeAll; MLKFaceDetector *faceDetector = [MLKFaceDetector faceDetectorWithOptions:options];
GMVDetector
has two
different detection APIs. Both are synchronous operations:
- (nullable NSArray<__kindof GMVFeature *> *) featuresInImage:(UIImage *)image options:(nullable NSDictionary *)options; - (nullable NSArray<__kindof GMVFeature *> *) featuresInBuffer:(CMSampleBufferRef)sampleBuffer options:(nullable NSDictionary *)options;
Replace GMVDetector
with MLKFaceDetector
.
The inference API can be called synchronously or asynchronously.
Synchronous
- (nullable NSArray<MLKFace *> *) resultsInImage:(MLKVisionImage *)image error:(NSError **)error;
Asynchronous
- (void)processImage:(MLKVisionImage *)image Completion: (MLKFaceDetectionCallback)completion NS_SWIFT_NAME(process(_:completion:));
Change the following classes, methods, and names:
BarcodeDetector
Recode the initialization as shown in this example:
GMV
NSDictionary *options = @{ GMVDetectorBarcodeFormats : @(GMVDetectorBarcodeFormatCode128 | GMVDetectorBarcodeFormatQRCode) }; GMVDetector *barcodeDetector = [GMVDetector detectorOfType:GMVDetectorTypeBarcode options:options];
ML Kit
MLKBarcodeScannerOptions *options = [[MLKBarcodeScannerOptions alloc] init]; options.formats = MLKBarcodeFormatCode128 | MLKBarcodeFormatQRCode; MLKBarcodeScanner *barcodeScanner = [MLKBarcodeScanner barcodeScannerWithOptions:options];
GMVDetector
has two different detection APIs. Both are synchronous operations:
- (nullable NSArray<__kindof GMVFeature *> *) featuresInImage:(UIImage *)image options:(nullable NSDictionary *)options; - (nullable NSArray<__kindof GMVFeature *> *) featuresInBuffer:(CMSampleBufferRef)sampleBuffer options:(nullable NSDictionary *)options;
Replace GMVDetector
with
MLKBarcodeScanner
.
The inference API can be called synchronously or asynchronously.
Synchronous
- (nullable NSArray<MLKBarcode *> *) resultsInImage:(MLKVisionImage *)image error:(NSError **)error;
Asynchronous
- (void)processImage:(MLKVisionImage *)image Completion: (MLKBarcodeScanningCallback)completion NS_SWIFT_NAME(process(_:completion:));
Change the following classes, methods, and names:
TextRecognition
Recode the initialization as shown in this example:
GMV
GMVDetector *textDetector = [GMVDetector detectorOfType:GMVDetectorTypeText options:nil];
ML Kit
MLKTextRecognizer *textRecognizer = [MLKTextRecognizer textRecognizer];
GMVDetector
has two
different detection APIs. Both are synchronous operations:
- (nullable NSArray<__kindof GMVFeature *> *) featuresInImage:(UIImage *)image options:(nullable NSDictionary *)options; - (nullable NSArray<__kindof GMVFeature *> *) featuresInBuffer:(CMSampleBufferRef)sampleBuffer options:(nullable NSDictionary *)options;
Replace GMVDetector
with
MLKTextRecognizer
.
The inference API can be called synchronously or asynchronously.
Synchronous
- (nullable MLKText *) resultsInImage:(MLKVisionImage *)image error:(NSError **)error;
Asynchronous
- (void)processImage:(MLKVisionImage *)image Completion: (MLKTextRecognitionCallback)completion NS_SWIFT_NAME(process(_:completion:));
Change the following classes, methods, and names:
GMV | ML Kit |
---|---|
GMVDetectorImageOrientation
|
MLKVisionImage.orientation
|
GMVTextBlockFeature
|
MLKTextBlock
|
GMVTextElementFeature
|
MLKTextElement
|
GMVTextLineFeature
|
MLKTextLine
|
Getting help
If you run into any issues, check out our Community page where we outline the channels available for getting in touch with us.