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 ele alınmaktadır.

Ön koşullar

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

  • ML Kit, Xcode 13.2.1 veya sonraki sürümleri destekler.
  • ML Kit, iOS 15.5 veya sonraki sürümleri destekler.
  • ML Kit, 32 bit mimarileri (i386 ve armv7) desteklemez. ML Kit, 64 bit mimarileri (x86_64 ve arm64) destekler.

cocoapods'u güncelleme

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

APIGMV KapsülüML Kit 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 alır. ML Kit, bunları bir MLKVisionImage içine sarmalayarak giriş olarak alır.
  • GMV, çeşitli dedektör seçeneklerini iletmek için NSDictionary kullanır. ML Kit bu amaç için özel seçenek sınıfları kullanır.
  • GMV, 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ımlayı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'ü genişletir ve aynı anda birden fazla algılama gerçekleştirmek için çoklu algılayıcı çerçevesi sağlar. ML Kit bu tür mekanizmalar sağlamaz ancak geliştirici isterse aynı işlevi uygulayabilir.

API'ye özgü değişiklikler

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

FaceDetector

Başlangıç ayarını bu örnekte gösterildiği gibi yeniden kodlayın:

GMVML Kit
NSDictionary *options = @{
    GMVDetectorFaceMode : @(GMVDetectorFaceAccurateMode),
    GMVDetectorFaceClassificationType : @(GMVDetectorFaceClassificationAll),
    GMVDetectorFaceLandmarkType : @(GMVDetectorFaceLandmarkAll)
};
GMVDetector *faceDetector =
    [GMVDetector detectorOfType:GMVDetectorTypeFace options:options];
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 yerine MLKFaceDetector yazın. Çıkarsama API'si eşzamanlı veya eşzamansız olarak çağrılabilir.

- (nullable NSArray<MLKFace *> *)
    resultsInImage:(MLKVisionImage *)image
             error:(NSError **)error;
- (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:

BarcodeDetector

Başlangıç ayarını bu örnekte gösterildiği gibi yeniden kodlayın:

GMVML Kit
NSDictionary *options = @{
    GMVDetectorBarcodeFormats : @(GMVDetectorBarcodeFormatCode128 |
                                  GMVDetectorBarcodeFormatQRCode)
};
GMVDetector *barcodeDetector =
    [GMVDetector detectorOfType:GMVDetectorTypeBarcode options:options];
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 yerine MLKBarcodeScanner yazın. Çıkarsama API'si eşzamanlı veya eşzamansız olarak çağrılabilir.

- (nullable NSArray<MLKBarcode *> *)
    resultsInImage:(MLKVisionImage *)image
             error:(NSError **)error;
- (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:

TextRecognition

Başlangıç ayarını bu örnekte gösterildiği gibi yeniden kodlayın:

GMVML Kit
GMVDetector *textDetector =
    [GMVDetector detectorOfType:GMVDetectorTypeText options:nil];
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 yerine MLKTextRecognizer yazın. Çıkarsama API'si eşzamanlı veya eşzamansız olarak çağrılabilir.

- (nullable MLKText *)
    resultsInImage:(MLKVisionImage *)image
             error:(NSError **)error;
- (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:

Yardım alma

Herhangi bir sorunla karşılaşırsanız bizimle iletişime geçebileceğiniz kanalları açıkladığımız Topluluk sayfamıza göz atın.