iOS'te Mobil Vizyon'dan ML Kiti'ne geçiş

Bu dokümanda, projelerinizi Google Mobile Vision'dan (GMV) iOS'teki ML Kit'e taşımak için uygulamanız gereken adımlar açıklanmaktadır.

Ön koşullar

Kodunuzu taşımaya başlamadan önce, aşağıdaki gereksinimleri karşıladığınızdan emin olun:

  • ML Kit, Xcode 13.2.1 veya sonraki sürümlerini destekler.
  • ML Kit, iOS 10 veya sonraki sürümleri destekler.
  • Makine Öğrenimi Kiti, 32 bit mimarileri (i386 ve armv7) desteklemez. ML Kit, 64 bit mimarileri (x86_64 ve arm64) destekler.

Cocoapod'ları güncelleme

Uygulamanızın Podfile dosyasında ML Kit iOS cocoapod'larının bağımlılıklarını güncelleyin:

APIGMV KapsülüML Kiti Kapsülü
Barkod tarama GoogleMobileVision/BarcodeDetector GoogleMLKit/BarcodeScanning
Yüz algılama GoogleMobileVision/FaceDetector GoogleMLKit/FaceDetection
Metin tanıma GoogleMobileVision/TextDetector GoogleMLKit/TextRecognition

Genel API değişiklikleri

Bu değişiklikler tüm API'ler için geçerlidir:

  • GMV'nin çıkarım API'leri giriş olarak UIImage veya CMSampleBufferRef değerini alır. Makine Öğrenimi Kiti, bunları bir MLKVisionImage içine alır ve giriş olarak kullanır.
  • GMV, çeşitli algılayıcı seçeneklerini iletmek için NSDictionary özelliğini kullanır. ML Kit bu amaçla özel seçenek sınıfları kullanır.
  • GMV, bir algılayıcı oluşturduğunda algılayıcı türünü tek GMVDetector sınıfına iletir. ML Kit ayrı algılayıcı, tarayıcı ve tanıyıcı örnekleri oluşturmak için özel sınıflar kullanır.
  • GMV'nin API'leri yalnızca eşzamanlı algılamayı destekler. ML Kit'in çıkarım API'leri eşzamanlı ve eşzamansız olarak çağrılabilir.
  • GMV, AVCaptureVideoDataOutput'in kapsamını genişletir ve aynı anda birden fazla algılama gerçekleştirmenizi sağlayan bir birden fazla algılayıcı çerçevesi sağlar. ML Kit bu tür mekanizmalar sunmamaktadır, ancak istenirse aynı işlevler geliştirici tarafından uygulanabilir.

API'ye özel değişiklikler

Bu bölümde, her Vision API için ilgili GMV ve ML Kit sınıfları ile yöntemleri açıklanmakta ve API'nin nasıl başlatılacağı gösterilmektedir.

FaceDetector

Başlatma işlemini aşağıdaki örnekte gösterildiği gibi yeniden kodlayın:

GMV

NSDictionary *options = @{
    GMVDetectorFaceMode : @(GMVDetectorFaceAccurateMode),
    GMVDetectorFaceClassificationType : @(GMVDetectorFaceClassificationAll),
    GMVDetectorFaceLandmarkType : @(GMVDetectorFaceLandmarkAll)
};
GMVDetector *faceDetector =
    [GMVDetector detectorOfType:GMVDetectorTypeFace options:options];

ML Kiti

MLKFaceDetectorOptions *options = [[MLKFaceDetectorOptions alloc] init];
options.performanceMode = MLKFaceDetectorPerformanceModeAccurate;
options.classificationMode = MLKFaceDetectorClassificationModeAll;
options.landmarkMode = MLKFaceDetectorLandmarkModeAll;
MLKFaceDetector *faceDetector = [MLKFaceDetector faceDetectorWithOptions:options];

GMVDetector iki farklı algılama API'sine sahiptir. Her ikisi de eşzamanlı işlemlerdir:

- (nullable NSArray<__kindof GMVFeature *> *)
    featuresInImage:(UIImage *)image
            options:(nullable NSDictionary *)options;

- (nullable NSArray<__kindof GMVFeature *> *)
    featuresInBuffer:(CMSampleBufferRef)sampleBuffer
             options:(nullable NSDictionary *)options;

GMVDetector değerini MLKFaceDetector ile değiştirin. Çıkarım API'si eşzamanlı veya eşzamansız olarak çağrılabilir.

Senkronize

- (nullable NSArray<MLKFace *> *)
    resultsInImage:(MLKVisionImage *)image
             error:(NSError **)error;

Eşzamansız

- (void)processImage:(MLKVisionImage *)image
    Completion:
        (MLKFaceDetectionCallback)completion
    NS_SWIFT_NAME(process(_:completion:));

Aşağıdaki sınıfları, yöntemleri ve adları değiştirin:

GMV ML Kiti
GMVFaceFeature MLKFace
GMVFaceContour MLKFaceContour
GMVDetectorImageOrientation MLKVisionImage.orientation
NSDictionary yüz algılama seçeneği MLKFaceDetectorOptions
GMVDetectorFaceFastMode Set MLKFaceDetectorOptions.performanceMode to MLKFaceDetectorPerformanceModeFast
GMVDetectorFaceAccurateMode Set MLKFaceDetectorOptions.performanceMode to MLKFaceDetectorPerformanceModeAccurate
GMVDetectorFaceSelfieMode Set MLKFaceDetectorOptions.contourMode to MLKFaceDetectorContourModeAll
GMVDetectorFaceLandmarkType MLKFaceDetectorOptions.landmarkMode
GMVDetectorFaceLandmarkNone Set MLKFaceDetectorOptions.landmarkMode to MLKFaceDetectorLandmarkModeNone
GMVDetectorFaceLandmarkAll Set MLKFaceDetectorOptions.landmarkMode to MLKFaceDetectorLandmarkModeAll
GMVDetectorFaceLandmarkContour Set MLKFaceDetectorOptions.contourMode to MLKFaceDetectorContourModeAll
GMVDetectorFaceClassificationType MLKFaceDetectorOptions.classificationMode
GMVDetectorFaceClassificationNone Set MLKFaceDetectorOptions.classificationMode to MLKFaceDetectorClassificationModeNone
GMVDetectorFaceClassificationAll Set MLKFaceDetectorOptions.classificationMode to MLKFaceDetectorClassificationModeAll
GMVDetectorFaceTrackingEnabled MLKFaceDetectorOptions.trackingEnabled
GMVDetectorProminentFaceOnly Set MLKFaceDetectorOptions.contourMode to MLKFaceDetectorContourModeAll
GMVDetectorFaceMinSize MLKFaceDetectorOptions.minFaceSize

BarcodeDetector

Başlatma işlemini aşağıdaki örnekte gösterildiği gibi yeniden kodlayın:

GMV

NSDictionary *options = @{
    GMVDetectorBarcodeFormats : @(GMVDetectorBarcodeFormatCode128 |
                                  GMVDetectorBarcodeFormatQRCode)
};
GMVDetector *barcodeDetector =
    [GMVDetector detectorOfType:GMVDetectorTypeBarcode options:options];

ML Kiti

MLKBarcodeScannerOptions *options = [[MLKBarcodeScannerOptions alloc] init];
options.formats = MLKBarcodeFormatCode128 | MLKBarcodeFormatQRCode;
MLKBarcodeScanner *barcodeScanner =
    [MLKBarcodeScanner barcodeScannerWithOptions:options];

GMVDetector iki farklı algılama API'sine sahiptir. Her ikisi de eşzamanlı işlemlerdir:

- (nullable NSArray<__kindof GMVFeature *> *)
    featuresInImage:(UIImage *)image
            options:(nullable NSDictionary *)options;

- (nullable NSArray<__kindof GMVFeature *> *)
    featuresInBuffer:(CMSampleBufferRef)sampleBuffer
             options:(nullable NSDictionary *)options;

GMVDetector değerini MLKBarcodeScanner ile değiştirin. Çıkarım API'si eşzamanlı veya eşzamansız olarak çağrılabilir.

Senkronize

- (nullable NSArray<MLKBarcode *> *)
    resultsInImage:(MLKVisionImage *)image
             error:(NSError **)error;

Eşzamansız

- (void)processImage:(MLKVisionImage *)image
    Completion:
        (MLKBarcodeScanningCallback)completion
    NS_SWIFT_NAME(process(_:completion:));

Aşağıdaki sınıfları, yöntemleri ve adları değiştirin:

GMV ML Kiti
GMVDetectorImageOrientation MLKVisionImage.orientation
NSDictionary barkod dedektörü seçeneği MLKBarcodeScannerOptions
GMVDetectorBarcodeFormats MLKBarcodeScannerOptions.formats
GMVBarcodeFeature MLKBarcode
GMVBarcodeFeatureAddress MLKBarcodeAddress
GMVBarcodeFeatureCalendarEvent MLKBarcodeCalendarEvent
GMVBarcodeFeatureContactInfo MLKBarcodeContactInfo
GMVBarcodeFeatureDriverLicense MLKBarcodeDriverLicense
GMVBarcodeFeatureEmail MLKBarcodeEmail
GMVBarcodeFeatureGeoPoint MLKBarcodeGeoPoint
GMVBarcodeFeaturePersonName MLKBarcodePersonName
GMVBarcodeFeaturePhone MLKBarcodePhone
GMVBarcodeFeatureSMS MLKBarcodeSMS
GMVBarcodeFeatureURLBookmark MLKBarcodeURLBookmark
GMVBarcodeFeatureWiFi MLKBarcodeWiFi

TextRecognition

Başlatma işlemini aşağıdaki örnekte gösterildiği gibi yeniden kodlayın:

GMV

GMVDetector *textDetector =
    [GMVDetector detectorOfType:GMVDetectorTypeText options:nil];

ML Kiti

MLKTextRecognizer *textRecognizer = [MLKTextRecognizer textRecognizer];

GMVDetector iki farklı algılama API'sine sahiptir. Her ikisi de eşzamanlı işlemlerdir:

- (nullable NSArray<__kindof GMVFeature *> *)
    featuresInImage:(UIImage *)image
            options:(nullable NSDictionary *)options;

- (nullable NSArray<__kindof GMVFeature *> *)
    featuresInBuffer:(CMSampleBufferRef)sampleBuffer
             options:(nullable NSDictionary *)options;

GMVDetector değerini MLKTextRecognizer ile değiştirin. Çıkarım API'si eşzamanlı veya eşzamansız olarak çağrılabilir.

Senkronize

- (nullable MLKText *)
    resultsInImage:(MLKVisionImage *)image
             error:(NSError **)error;

Eşzamansız

- (void)processImage:(MLKVisionImage *)image
    Completion:
        (MLKTextRecognitionCallback)completion
    NS_SWIFT_NAME(process(_:completion:));

Aşağıdaki sınıfları, yöntemleri ve adları değiştirin:

GMV ML Kiti
GMVDetectorImageOrientation MLKVisionImage.orientation
GMVTextBlockFeature MLKTextBlock
GMVTextElementFeature MLKTextElement
GMVTextLineFeature MLKTextLine

Yardım alma

Herhangi bir sorunla karşılaşırsanız bize ulaşmak için kullanılabilecek kanalların açıklandığı Topluluk sayfamıza göz atın.