iOS पर, मोबाइल विज़न से एमएल किट पर माइग्रेट करना

इस दस्तावेज़ में बताया गया है कि iOS पर अपने प्रोजेक्ट को Google Mobile Vision (GMV) से एमएल किट में माइग्रेट करने के लिए, क्या करना होगा.

ज़रूरी शर्तें

अपने कोड को माइग्रेट करने से पहले, पक्का करें कि आपने इन ज़रूरी शर्तों को पूरा किया है:

  • मशीन लर्निंग किट, Xcode 13.2.1 या इसके बाद के वर्शन के साथ काम करती है.
  • ML किट, iOS 10 या इसके बाद के वर्शन पर काम करती है.
  • मशीन लर्निंग किट, 32-बिट आर्किटेक्चर (i386 और armv7) के साथ काम नहीं करती. मशीन लर्निंग किट, 64-बिट आर्किटेक्चर (x86_64 और arm64) के साथ काम करती है.

Cocoapods अपडेट करें

अपने ऐप्लिकेशन की Podfile में, ML Kit iOS कोको-पॉड के लिए डिपेंडेंसी अपडेट करें:

APIजीएमवी पॉडएमएल किट पॉड
बारकोड स्कैन करना GoogleMobileVision/BarcodeDetector GoogleMLKit/BarcodeScanning
चेहरे की पहचान GoogleMobileVision/FaceDetector GoogleMLKit/FaceDetection
टेक्स्ट की पहचान GoogleMobileVision/TextDetector GoogleMLKit/TextRecognition

एपीआई में हुए सभी बदलाव

ये बदलाव सभी एपीआई पर लागू होते हैं:

  • GMV के अनुमान एपीआई को इनपुट के तौर पर, UIImage या CMSampleBufferRef का इस्तेमाल किया जाता है. एमएल किट, उन्हें MLKVisionImage के अंदर रैप कर देती है और उसे इनपुट के तौर पर ले लेती है.
  • डिटेक्टर के अलग-अलग विकल्पों को पास करने के लिए, जीएमवी NSDictionary का इस्तेमाल करता है. ML किट इसी काम के लिए, खास विकल्प क्लास का इस्तेमाल करती है.
  • जब जीएमवी कोई डिटेक्टर बनाता है, तब वह डिटेक्टर टाइप को सिंगल GMVDetector क्लास में पास करता है. मशीन लर्निंग किट, अलग से डिटेक्टर, स्कैनर, और आइडेंटिफ़ायर के इंस्टेंस बनाने के लिए, खास क्लास का इस्तेमाल करती है.
  • GMV के एपीआई, सिर्फ़ सिंक्रोनस तरीके से पहचान करने की सुविधा के साथ काम करते हैं. एमएल किट के अनुमान एपीआई को सिंक्रोनस (एसिंक्रोनस) और एसिंक्रोनस रूप से कॉल किया जा सकता है.
  • जीएमवी, AVCaptureVideoDataOutput के दायरे में आता है. साथ ही, यह एक साथ कई तरीकों से पहचान करने के लिए, मल्टी-डिटेक्टर फ़्रेमवर्क उपलब्ध कराता है. मशीन लर्निंग किट में ऐसे तरीके उपलब्ध नहीं होते. हालांकि, अगर डेवलपर चाहें, तो वह उन सुविधाओं को लागू कर सकता है.

एपीआई से जुड़े बदलाव

इस सेक्शन में, हर Vision API के लिए GMV और ML Kit की क्लास के साथ-साथ एपीआई को शुरू करने के तरीकों के बारे में बताया गया है.

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 में पहचान करने वाले दो अलग-अलग एपीआई हैं. दोनों सिंक्रोनस ऑपरेशन हैं:

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

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

GMVDetector को MLKFaceDetector से बदलें. अनुमान एपीआई को सिंक्रोनस या एसिंक्रोनस रूप से कॉल किया जा सकता है.

सिंक्रोनस

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

एसिंक्रोनस

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

नीचे दी गई क्लास, तरीके, और नाम बदलें:

जीएमवी ML Kit
GMVFaceFeature MLKFace
GMVFaceContour MLKFaceContour
GMVDetectorImageOrientation MLKVisionImage.orientation
चेहरे की पहचान के NSDictionary विकल्प 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

इस उदाहरण में दिखाए गए तरीके से, शुरू करने की प्रोसेस को फिर से कोड करें:

जीएमवी

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 में पहचान करने वाले दो अलग-अलग एपीआई हैं. दोनों सिंक्रोनस ऑपरेशन हैं:

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

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

GMVDetector को MLKBarcodeScanner से बदलें. अनुमान एपीआई को सिंक्रोनस या एसिंक्रोनस रूप से कॉल किया जा सकता है.

सिंक्रोनस

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

एसिंक्रोनस

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

नीचे दी गई क्लास, तरीके, और नाम बदलें:

जीएमवी ML Kit
GMVDetectorImageOrientation MLKVisionImage.orientation
बारकोड की पहचान करने वाले विकल्पों में से NSDictionary 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

इस उदाहरण में दिखाए गए तरीके से, शुरू करने की प्रोसेस को फिर से कोड करें:

जीएमवी

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

ML Kit

MLKTextRecognizer *textRecognizer = [MLKTextRecognizer textRecognizer];

GMVDetector में पहचान करने वाले दो अलग-अलग एपीआई हैं. दोनों सिंक्रोनस ऑपरेशन हैं:

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

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

GMVDetector को MLKTextRecognizer से बदलें. अनुमान एपीआई को सिंक्रोनस या एसिंक्रोनस रूप से कॉल किया जा सकता है.

सिंक्रोनस

- (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

सहायता पाना

अगर आपको कोई समस्या आती है, तो हमारे कम्यूनिटी पेज पर जाएं. यहां हमने उन चैनलों की जानकारी दी है जिनकी मदद से हमसे संपर्क किया जा सकता है.