เอกสารนี้กล่าวถึงขั้นตอนที่คุณต้องทำเพื่อย้ายข้อมูลโปรเจ็กต์จาก Google Mobile Vision (GMV) ไปยัง ML Kit บน iOS
ข้อกำหนดเบื้องต้น
ก่อนที่จะเริ่มย้ายรหัส โปรดตรวจสอบว่าคุณมีคุณสมบัติตามข้อกำหนดต่อไปนี้
- ML Kit รองรับ Xcode 13.2.1 ขึ้นไป
- ML Kit รองรับ iOS เวอร์ชัน 10 ขึ้นไป
- ML Kit ไม่รองรับสถาปัตยกรรม 32 บิต (i386 และ armv7) ML Kit รองรับสถาปัตยกรรม 64 บิต (x86_64 และ arm64)
อัปเดต CocoaPods
อัปเดตทรัพยากร Dependency สำหรับ CocoaPods ของ ML Kit ใน Podfile ของแอปคุณดังนี้
API | พ็อด GMV | พ็อด ML Kit |
---|---|---|
การสแกนบาร์โค้ด | GoogleMobileVision/BarcodeDetector |
GoogleMLKit/BarcodeScanning |
การตรวจจับใบหน้า | GoogleMobileVision/FaceDetector |
GoogleMLKit/FaceDetection |
การรู้จำข้อความ | GoogleMobileVision/TextDetector |
GoogleMLKit/TextRecognition |
การเปลี่ยนแปลง API โดยรวม
การเปลี่ยนแปลงเหล่านี้จะมีผลกับ API ทั้งหมด
- API การอนุมานของ GMV จะนำ
UIImage
หรือCMSampleBufferRef
เป็นอินพุต โดย ML Kit จะรวมไว้ในMLKVisionImage
และใช้อินพุตเป็นอินพุต - GMV ใช้
NSDictionary
เพื่อผ่านตัวเลือกตัวตรวจจับต่างๆ โดย ML Kit จะใช้ชั้นเรียนตัวเลือกเฉพาะเพื่อวัตถุประสงค์ดังกล่าว - GMV จะส่งประเภทตัวตรวจจับไปยังคลาส
GMVDetector
เดี่ยวเมื่อสร้างตัวตรวจจับ ML Kit ใช้คลาสเฉพาะในการสร้างอินสแตนซ์ตัวตรวจจับ เครื่องสแกน และตัวจดจำแยกกัน - API ของ GMV รองรับการตรวจจับแบบซิงโครนัสเท่านั้น API การอนุมานของ ML Kit อาจเรียกว่าแบบซิงโครนัสและไม่พร้อมกัน
- GMV ขยายการให้บริการไปยัง
AVCaptureVideoDataOutput
และเป็นเฟรมเวิร์กตัวตรวจจับหลายตัวสำหรับการดำเนินการตรวจจับหลายรายการพร้อมกัน ML Kit ไม่มีกลไกดังกล่าว แต่นักพัฒนาซอฟต์แวร์ติดตั้งใช้งานฟังก์ชันเดียวกันได้หากต้องการ
การเปลี่ยนแปลงเฉพาะ API
ส่วนนี้จะอธิบายถึงคลาสและเมธอด GMV และ ML Kit ที่เกี่ยวข้องสำหรับ Vision API แต่ละรายการ รวมถึงแสดงวิธีเริ่มใช้ 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
มี API การตรวจจับ 2 แบบ ทั้ง 2 อย่างนี้เป็นการดำเนินการแบบพร้อมกัน
- (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
มี API การตรวจจับ 2 รายการที่แตกต่างกัน ทั้ง 2 อย่างนี้เป็นการดำเนินการแบบพร้อมกัน
- (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
มี API การตรวจจับ 2 แบบ ทั้ง 2 อย่างนี้เป็นการดำเนินการแบบพร้อมกัน
- (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
|
การขอความช่วยเหลือ
หากพบปัญหา โปรดไปที่หน้าชุมชนซึ่งเราได้ระบุช่องที่ช่องทางสำหรับติดต่อเราได้