Bu belgede, projelerinizi Google Mobile Vision'dan (GMV) iOS'te ML Kit'e taşımak için uygulamanız gereken adımlar açıklanmaktadır.
Ön koşullar
Kodunuzu taşımaya başlamadan önce şu koşulları karşıladığınızdan emin olun:
- ML Kiti, Xcode 13.2.1 veya sonraki sürümleri destekler.
- ML Kiti, 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'ında ML Kit iOS cocoapods'larının bağımlılıklarını güncelleyin:
API | GMV Pod | ML Kit Pod'u |
---|---|---|
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
veyaCMSampleBufferRef
alır. ML Kit, bunlarıMLKVisionImage
içine sarar ve giriş olarak alır. - GMV, çeşitli algılayıcı seçeneklerini iletmek için
NSDictionary
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
ile genişletilir ve aynı anda birden fazla algılama işlemi gerçekleştirmek için çoklu dedektör çerçevesi sağlar. ML Kit bu tür mekanizmalar sağlamaz ancak istenirse aynı işlev geliştirici tarafından uygulanabilir.
API'ye özgü değişiklikler
Bu bölümde, her bir 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şlatmayı bu ö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 Kit
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
koyun.
Çı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:
BarcodeDetector
Başlatmayı bu örnekte gösterildiği gibi yeniden kodlayın:
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
'nin iki farklı algılama API'si vardır. 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
koyun.
Çı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:
TextRecognition
Başlatmayı bu örnekte gösterildiği gibi yeniden kodlayın:
GMV
GMVDetector *textDetector = [GMVDetector detectorOfType:GMVDetectorTypeText options:nil];
ML Kit
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
koyun.
Çı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 Kit |
---|---|
GMVDetectorImageOrientation
|
MLKVisionImage.orientation
|
GMVTextBlockFeature
|
MLKTextBlock
|
GMVTextElementFeature
|
MLKTextElement
|
GMVTextLineFeature
|
MLKTextLine
|
Yardım alma
Herhangi bir sorunla karşılaşırsanız bizimle iletişime geçebileceğiniz kanalları özetlediğimiz topluluk sayfamıza göz atın.