एमएल किट, पोज़ का पता लगाने वाली सुविधा के लिए, दो ऑप्टिमाइज़ किए गए SDK टूल उपलब्ध कराती है.
SDK टूल का नाम | आस-पास की हलचल का पता लगाना | सही से जांच करना |
---|---|---|
लागू करना | बेस डिटेक्टर के लिए एसेट, बिल्ड टाइम पर आपके ऐप्लिकेशन से स्टैटिक तौर पर लिंक की गई होती हैं. | सटीक डिटेक्टर की एसेट, बिल्ड टाइम पर आपके ऐप्लिकेशन से स्टैटिक तौर पर लिंक की गई होती हैं. |
ऐप्लिकेशन का साइज़ | 29.6 एमबी तक | 33.2 एमबी तक |
परफ़ॉर्मेंस | iPhone X: ~45FPS | iPhone X: ~29FPS |
इसे आज़माएं
- इस एपीआई के इस्तेमाल के उदाहरण देखने के लिए, सैंपल ऐप्लिकेशन का इस्तेमाल करें.
शुरू करने से पहले
अपने Podfile में नीचे दिए गए ML Kit पॉड शामिल करें:
# If you want to use the base implementation: pod 'GoogleMLKit/PoseDetection', '3.2.0' # If you want to use the accurate implementation: pod 'GoogleMLKit/PoseDetectionAccurate', '3.2.0'
अपने प्रोजेक्ट के पॉड इंस्टॉल या अपडेट करने के बाद,
xcworkspace
का इस्तेमाल करके अपना Xcode प्रोजेक्ट खोलें. एमएल किट, Xcode के 13.2.1 या इसके बाद के वर्शन में काम करती है.
1. PoseDetector
का इंस्टेंस बनाएं
किसी इमेज में पोज़ का पता लगाने के लिए, पहले PoseDetector
का एक इंस्टेंस बनाएं और
वैकल्पिक रूप से, पहचानकर्ता की सेटिंग बताएं.
PoseDetector
विकल्प
पहचान मोड
PoseDetector
, दो डिटेक्शन मोड में काम करता है. पक्का करें कि आपने वही इस्तेमाल किया है जो
आपके इस्तेमाल के उदाहरण से मेल खाता है.
stream
(डिफ़ॉल्ट)- पॉज़ डिटेक्टर सबसे पहले इमेज में सबसे प्रमुख व्यक्ति का पता लगाता है और फिर पोज़ की पहचान करता है. बाद के फ़्रेम में, व्यक्ति की पहचान करने का चरण तब तक पूरा नहीं किया जाएगा, जब तक कि वह व्यक्ति अंधेरे में न हो या उसके बारे में पता न हो. पोज़ डिटेक्टर सबसे बेहतरीन व्यक्ति को ट्रैक करने की कोशिश करता है. साथ ही, हर अनुमान में पोज़ दिखाता है. इससे इंतज़ार का समय और स्मूद डिटेक्शन कम होता है. इस मोड का इस्तेमाल तब करें, जब आपको वीडियो स्ट्रीम में पोज़ का पता लगाना हो.
singleImage
- पॉज़ डिटेक्टर से किसी व्यक्ति की पहचान होगी और फिर पोज़ की पहचान की जा सकेगी. हर इमेज के लिए व्यक्ति की पहचान की प्रक्रिया पूरी होगी, इसलिए इंतज़ार का समय ज़्यादा होगा और कोई व्यक्ति ट्रैकिंग नहीं होगी. स्टैटिक इमेज पर या आस-पास की चीज़ों का पता लगाने की सुविधा का इस्तेमाल करते समय या इस मोड का इस्तेमाल करके, इमेज को ट्रैक न करें.
पोज़ पहचानकर्ता का विकल्प दें:
Swift
// Base pose detector with streaming, when depending on the PoseDetection SDK let options = PoseDetectorOptions() options.detectorMode = .stream // Accurate pose detector on static images, when depending on the // PoseDetectionAccurate SDK let options = AccuratePoseDetectorOptions() options.detectorMode = .singleImage
Objective-C
// Base pose detector with streaming, when depending on the PoseDetection SDK MLKPoseDetectorOptions *options = [[MLKPoseDetectorOptions alloc] init]; options.detectorMode = MLKPoseDetectorModeStream; // Accurate pose detector on static images, when depending on the // PoseDetectionAccurate SDK MLKAccuratePoseDetectorOptions *options = [[MLKAccuratePoseDetectorOptions alloc] init]; options.detectorMode = MLKPoseDetectorModeSingleImage;
आखिर में, PoseDetector
का इंस्टेंस पाएं. बताए गए विकल्पों को पास करें:
Swift
let poseDetector = PoseDetector.poseDetector(options: options)
Objective-C
MLKPoseDetector *poseDetector = [MLKPoseDetector poseDetectorWithOptions:options];
2. इनपुट इमेज तैयार करें
पोज़ का पता लगाने के लिए, हर इमेज या वीडियो के फ़्रेम के लिए ये करें.
अगर आपने स्ट्रीम मोड चालू किया है, तो आपको
CMSampleBuffer
से VisionImage
ऑब्जेक्ट बनाना होगा.
UIImage
या
CMSampleBuffer
का इस्तेमाल करके, VisionImage
ऑब्जेक्ट बनाएं.
अगर UIImage
का इस्तेमाल किया जाता है, तो यह तरीका अपनाएं:
UIImage
की मदद सेVisionImage
ऑब्जेक्ट बनाएं..orientation
का सही नाम डालना न भूलें.Swift
let image = VisionImage(image: UIImage) visionImage.orientation = image.imageOrientation
Objective-C
MLKVisionImage *visionImage = [[MLKVisionImage alloc] initWithImage:image]; visionImage.orientation = image.imageOrientation;
अगर CMSampleBuffer
का इस्तेमाल किया जाता है, तो यह तरीका अपनाएं:
-
CMSampleBuffer
में शामिल इमेज डेटा का ओरिएंटेशन बताएं.इमेज का ओरिएंटेशन पाने के लिए:
Swift
func imageOrientation( deviceOrientation: UIDeviceOrientation, cameraPosition: AVCaptureDevice.Position ) -> UIImage.Orientation { switch deviceOrientation { case .portrait: return cameraPosition == .front ? .leftMirrored : .right case .landscapeLeft: return cameraPosition == .front ? .downMirrored : .up case .portraitUpsideDown: return cameraPosition == .front ? .rightMirrored : .left case .landscapeRight: return cameraPosition == .front ? .upMirrored : .down case .faceDown, .faceUp, .unknown: return .up } }
Objective-C
- (UIImageOrientation) imageOrientationFromDeviceOrientation:(UIDeviceOrientation)deviceOrientation cameraPosition:(AVCaptureDevicePosition)cameraPosition { switch (deviceOrientation) { case UIDeviceOrientationPortrait: return cameraPosition == AVCaptureDevicePositionFront ? UIImageOrientationLeftMirrored : UIImageOrientationRight; case UIDeviceOrientationLandscapeLeft: return cameraPosition == AVCaptureDevicePositionFront ? UIImageOrientationDownMirrored : UIImageOrientationUp; case UIDeviceOrientationPortraitUpsideDown: return cameraPosition == AVCaptureDevicePositionFront ? UIImageOrientationRightMirrored : UIImageOrientationLeft; case UIDeviceOrientationLandscapeRight: return cameraPosition == AVCaptureDevicePositionFront ? UIImageOrientationUpMirrored : UIImageOrientationDown; case UIDeviceOrientationUnknown: case UIDeviceOrientationFaceUp: case UIDeviceOrientationFaceDown: return UIImageOrientationUp; } }
CMSampleBuffer
ऑब्जेक्ट और ओरिएंटेशन का इस्तेमाल करकेVisionImage
ऑब्जेक्ट बनाएं:Swift
let image = VisionImage(buffer: sampleBuffer) image.orientation = imageOrientation( deviceOrientation: UIDevice.current.orientation, cameraPosition: cameraPosition)
Objective-C
MLKVisionImage *image = [[MLKVisionImage alloc] initWithBuffer:sampleBuffer]; image.orientation = [self imageOrientationFromDeviceOrientation:UIDevice.currentDevice.orientation cameraPosition:cameraPosition];
3. इमेज प्रोसेस करें
पोज़ डिटेक्टर की इमेज प्रोसेसिंग के तरीकों में से किसी एक में VisionImage
पास करें. इसमें एसिंक्रोनस process(image:)
या सिंक्रोनस results()
तरीके का इस्तेमाल किया जा सकता है.
ऑब्जेक्ट को सिंक्रोनस रूप से पहचानने के लिए:
Swift
var results: [Pose] do { results = try poseDetector.results(in: image) } catch let error { print("Failed to detect pose with error: \(error.localizedDescription).") return } guard let detectedPoses = results, !detectedPoses.isEmpty else { print("Pose detector returned no results.") return } // Success. Get pose landmarks here.
Objective-C
NSError *error; NSArray*poses = [poseDetector resultsInImage:image error:&error]; if (error != nil) { // Error. return; } if (poses.count == 0) { // No pose detected. return; } // Success. Get pose landmarks here.
एसिंक्रोनस रूप से ऑब्जेक्ट का पता लगाने के लिए:
Swift
poseDetector.process(image) { detectedPoses, error in guard error == nil else { // Error. return } guard !detectedPoses.isEmpty else { // No pose detected. return } // Success. Get pose landmarks here. }
Objective-C
[poseDetector processImage:image completion:^(NSArray* _Nullable poses, NSError * _Nullable error) { if (error != nil) { // Error. return; } if (poses.count == 0) { // No pose detected. return; } // Success. Get pose landmarks here. }];
4. पहचानी गई पोज़ के बारे में जानकारी पाएं
अगर इमेज में किसी व्यक्ति का पता चलता है, तो पोज़ पहचानने वाला एपीआई या तो Pose
ऑब्जेक्ट के ऐरे को पूरा होने वाले हैंडलर के लिए पास करता है या श्रेणी दिखाता है. यह इस बात पर निर्भर करता है कि आपने एसिंक्रोनस या सिंक्रोनस तरीके को कॉल किया है या नहीं.
अगर कोई व्यक्ति पूरी तरह से इमेज में मौजूद नहीं है, तो मॉडल, फ़्रेम के बाहर मौजूद छूटे हुए लैंडमार्क को असाइन करता है और उन्हें कम iFrameAConfidence वैल्यू देता है.
अगर किसी व्यक्ति की पहचान नहीं की जा सकी, तो ऐरे खाली है.
Swift
for pose in detectedPoses { let leftAnkleLandmark = pose.landmark(ofType: .leftAnkle) if leftAnkleLandmark.inFrameLikelihood > 0.5 { let position = leftAnkleLandmark.position } }
Objective-C
for (MLKPose *pose in detectedPoses) { MLKPoseLandmark *leftAnkleLandmark = [pose landmarkOfType:MLKPoseLandmarkTypeLeftAnkle]; if (leftAnkleLandmark.inFrameLikelihood > 0.5) { MLKVision3DPoint *position = leftAnkleLandmark.position; } }
परफ़ॉर्मेंस को बेहतर बनाने के लिए सलाह
आपके नतीजों की क्वालिटी, इनपुट इमेज की क्वालिटी पर निर्भर करती है:
- एमएल किट ठीक से पोज़ का पता लगाने के लिए, इमेज में दिखने वाले व्यक्ति की फ़ोटो को ज़रूरत के मुताबिक पिक्सल डेटा में दिखाना चाहिए. सबसे अच्छी परफ़ॉर्मेंस के लिए, ऑब्जेक्ट की ऊंचाई कम से कम 256x256 पिक्सल होनी चाहिए.
- अगर आपको किसी रीयल-टाइम ऐप्लिकेशन में पोज़ का पता चलता है, तो हो सकता है कि आप इनपुट इमेज के सभी डाइमेंशन पर भी विचार करना चाहें. छोटी इमेज ज़्यादा तेज़ी से प्रोसेस की जा सकती हैं, इसलिए इंतज़ार का समय कम करने के लिए, कम रिज़ॉल्यूशन वाली इमेज कैप्चर करें और ऊपर दी गई रिज़ॉल्यूशन की ज़रूरी शर्तों को ध्यान में रखें. साथ ही, पक्का करें कि सब्जेक्ट इमेज के जितना हो सके उतना दिखे.
- इमेज का ठीक से न फ़ोकस न होना, उसके सटीक होने पर भी असर डाल सकता है. अगर आपको स्वीकार किए जा सकने वाले नतीजे नहीं दिखते हैं, तो उपयोगकर्ता से इमेज को फिर से देखने के लिए कहें.
अगर आपको रीयल-टाइम ऐप्लिकेशन में 'हाव-भाव' की सुविधा का इस्तेमाल करना है, तो सबसे सही फ़्रेम दर पाने के लिए इन दिशा-निर्देशों का पालन करें:
- पोज़ डिटेक्शन SDK टूल का इस्तेमाल करें और
stream
का पता लगाने वाले मोड का इस्तेमाल करें. - कम रिज़ॉल्यूशन में इमेज कैप्चर करें. हालांकि, इस एपीआई की इमेज डाइमेंशन से जुड़ी ज़रूरी शर्तों का भी ध्यान रखें.
- वीडियो फ़्रेम प्रोसेस करने के लिए,
results(in:)
सिंक्रोनस एपीआई का इस्तेमाल करें. AVCaptureVideoDataSampleSampleBufferDelegate के capture आउटपुट(_, didआउट:from:) फ़ंक्शन से इस तरीके को कॉल करके, दिए गए वीडियो फ़्रेम से सिंक्रोनस रूप से नतीजे पाएं. कॉल को थ्रॉटल करने के लिए, AVCaptureVideoDataInput के हमेशा के लिए खारिज करेंLateVideoFrames को 'सही' रखें. अगर डिटेक्टर के चलने के दौरान नया वीडियो फ़्रेम उपलब्ध होता है, तो उसे छोड़ दिया जाएगा. - अगर इनपुट इमेज पर ग्राफ़िक ओवरले करने के लिए डिटेक्टर के आउटपुट का इस्तेमाल किया जाता है, तो पहले एमएल किट से नतीजा पाएं. इसके बाद, एक ही चरण में इमेज और ओवरले को रेंडर करें. ऐसा करके, प्रोसेस किए गए हर इनपुट फ़्रेम के लिए, डिसप्ले के प्लैटफ़ॉर्म को सिर्फ़ एक बार रेंडर किया जाता है. उदाहरण के लिए, शोकेस सैंपल ऐप्लिकेशन में previewOverlayView और MLKDetectionOverlayView क्लास देखें.
अगले चरण
- पोज़ को अलग-अलग कैटगरी में बांटने के लिए, पोज़ (पोज़िशन) का इस्तेमाल करने का तरीका जानने के लिए, पोज़ क्लासिफ़िकेशन से जुड़ी सलाह लेख पढ़ें.
- इस्तेमाल किए जा रहे इस एपीआई का उदाहरण देखने के लिए, GitHub पर ML Kit Quickstart सैंपल देखें.