このドキュメントでは、iOS でプロジェクトを Google Mobile Vision(GMV)から ML Kit に移行するために必要な手順について説明します。
前提条件
コードの移行を開始する前に、次の要件を満たしていることを確認してください。
- ML Kit は Xcode 13.2.1 以降をサポートしています。
- ML Kit は iOS バージョン 10 以降をサポートしています。
- ML Kit は 32 ビット アーキテクチャ(i386 と armv7)をサポートしていません。ML Kit は 64 ビット アーキテクチャ(x86_64 と arm64)をサポートしています。
cocoapods を更新する
アプリの Podfile で、ML Kit の iOS cocoapods の依存関係を更新します。
API | GMV 連続配信広告 | ML Kit Pod |
---|---|---|
バーコード スキャン | GoogleMobileVision/BarcodeDetector |
GoogleMLKit/BarcodeScanning |
顔検出 | GoogleMobileVision/FaceDetector |
GoogleMLKit/FaceDetection |
テキスト認識 | GoogleMobileVision/TextDetector |
GoogleMLKit/TextRecognition |
API の全体的な変更点
以下の変更はすべての API に適用されます。
- GMV の推論 API は、
UIImage
またはCMSampleBufferRef
を入力として受け取ります。ML Kit はこれらをMLKVisionImage
内にラップし、入力として受け取ります。 - GMV は
NSDictionary
を使用して、さまざまな検出項目を渡します。ML Kit は、この目的のために専用のオプションクラスを使用します。 - GMV は検出項目を作成するときに、単一の
GMVDetector
クラスに検出項目タイプを渡します。ML Kit は、専用のクラスを使用して、検出機能、スキャナ、認識機能の個別のインスタンスを作成します。 - GMV の API は、同期検出のみをサポートしています。ML Kit の推論 API は、同期的または非同期的に呼び出すことができます。
- GMV は
AVCaptureVideoDataOutput
を拡張したもので、複数の検出を同時に行うためのマルチ検出フレームワークを提供します。ML Kit にはこのようなメカニズムはありませんが、必要に応じてデベロッパーが同じ機能を実装できます。
API 固有の変更
このセクションでは、各 Vision API に対応する GMV と ML Kit のクラスとメソッドについて説明し、API の初期化方法について説明します。
FaceDetector
初期化を次の例のように変更し直します。
総取引額
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
には 2 種類の検出 API があります。どちらも同期オペレーションです。
- (nullable NSArray<__kindof GMVFeature *> *) featuresInImage:(UIImage *)image options:(nullable NSDictionary *)options; - (nullable NSArray<__kindof GMVFeature *> *) featuresInBuffer:(CMSampleBufferRef)sampleBuffer options:(nullable NSDictionary *)options;
GMVDetector
を MLKFaceDetector
に置き換えます。推論 API は同期的または非同期的に呼び出すことができます。
同期
- (nullable NSArray<MLKFace *> *) resultsInImage:(MLKVisionImage *)image error:(NSError **)error;
非同期
- (void)processImage:(MLKVisionImage *)image Completion: (MLKFaceDetectionCallback)completion NS_SWIFT_NAME(process(_:completion:));
次のクラス、メソッド、名前を変更します。
BarcodeDetector
初期化を次の例のように変更し直します。
総取引額
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
には、2 種類の検出 API があります。どちらも同期オペレーションです。
- (nullable NSArray<__kindof GMVFeature *> *) featuresInImage:(UIImage *)image options:(nullable NSDictionary *)options; - (nullable NSArray<__kindof GMVFeature *> *) featuresInBuffer:(CMSampleBufferRef)sampleBuffer options:(nullable NSDictionary *)options;
GMVDetector
を MLKBarcodeScanner
に置き換えます。推論 API は同期的または非同期的に呼び出すことができます。
同期
- (nullable NSArray<MLKBarcode *> *) resultsInImage:(MLKVisionImage *)image error:(NSError **)error;
非同期
- (void)processImage:(MLKVisionImage *)image Completion: (MLKBarcodeScanningCallback)completion NS_SWIFT_NAME(process(_:completion:));
次のクラス、メソッド、名前を変更します。
TextRecognition
初期化を次の例のように変更し直します。
総取引額
GMVDetector *textDetector = [GMVDetector detectorOfType:GMVDetectorTypeText options:nil];
ML Kit
MLKTextRecognizer *textRecognizer = [MLKTextRecognizer textRecognizer];
GMVDetector
には 2 種類の検出 API があります。どちらも同期オペレーションです。
- (nullable NSArray<__kindof GMVFeature *> *) featuresInImage:(UIImage *)image options:(nullable NSDictionary *)options; - (nullable NSArray<__kindof GMVFeature *> *) featuresInBuffer:(CMSampleBufferRef)sampleBuffer options:(nullable NSDictionary *)options;
GMVDetector
を MLKTextRecognizer
に置き換えます。推論 API は同期的または非同期的に呼び出すことができます。
同期
- (nullable MLKText *) resultsInImage:(MLKVisionImage *)image error:(NSError **)error;
非同期
- (void)processImage:(MLKVisionImage *)image Completion: (MLKTextRecognitionCallback)completion NS_SWIFT_NAME(process(_:completion:));
次のクラス、メソッド、名前を変更します。
総取引額 | ML Kit |
---|---|
GMVDetectorImageOrientation
|
MLKVisionImage.orientation
|
GMVTextBlockFeature
|
MLKTextBlock
|
GMVTextElementFeature
|
MLKTextElement
|
GMVTextLineFeature
|
MLKTextLine
|
参考情報
問題が発生した場合は、コミュニティ ページをご確認ください。このページには、お問い合わせに使用できるチャンネルの概要が記載されています。