iOS के लिए लैंडमार्क की पहचान करने वाली गाइड

पोज़ लैंडमार्कर टास्क की मदद से, किसी इमेज में इंसानी शरीर के लैंडमार्क का पता लगाया जा सकता है या वीडियो. इस टास्क की मदद से, शरीर की प्रमुख जगहों की पहचान की जा सकती है, पॉस्चर का विश्लेषण किया जा सकता है, और गतिविधियों को अलग-अलग कैटगरी में बांट सकता है. यह टास्क, ऐसे मशीन लर्निंग (एमएल) मॉडल का इस्तेमाल करता है जो काम करता है उसे अलग-अलग इमेज या वीडियो के तौर पर इस्तेमाल किया जा सकता है. टास्क, इमेज में बॉडी पोज़ लैंडमार्क दिखाता है निर्देशांकों और 3-आयामी दुनिया के निर्देशांकों में भी देखा जा सकता है.

ये निर्देश आपको iOS ऐप्लिकेशन के साथ पोज़ लैंडमार्कर का इस्तेमाल करने का तरीका बताते हैं. कोड इन निर्देशों में बताया गया सैंपल, यहां उपलब्ध है GitHub.

आप इस वेब पर, इस टास्क को काम करते हुए देख सकते हैं डेमो. क्षमताओं, मॉडल, और कॉन्फ़िगरेशन के विकल्पों के बारे में ज़्यादा जानकारी पाने के लिए उस टास्क की जानकारी देखें, तो खास जानकारी.

कोड का उदाहरण

MediaPipe टास्क का उदाहरण कोड, पोज़ लैंडमार्कर को बुनियादी तौर पर लागू करने का तरीका है iOS के लिए ऐप. इस उदाहरण में, iOS डिवाइस के कैमरे का इस्तेमाल करके यह पता लगाया गया है कि लगातार वीडियो स्ट्रीम में पोज़ का पता लगाने में मदद करता है. ऐप्लिकेशन, आस-पास मौजूद पोज़ का पता भी लगा सकता है डिवाइस की गैलरी से इमेज और वीडियो.

इस ऐप्लिकेशन का इस्तेमाल, अपने iOS ऐप्लिकेशन के लिए शुरुआती पॉइंट के तौर पर किया जा सकता है या इसे रेफ़रंस के तौर पर इस्तेमाल किया जा सकता है. को अपडेट करें. पोज़ लैंडमार्कर का उदाहरण कोड इन पर होस्ट किया जाता है GitHub.

कोड डाउनलोड करें

नीचे दिए गए निर्देशों में आपको उदाहरण की स्थानीय कॉपी बनाने का तरीका बताया गया है git कमांड लाइन टूल का इस्तेमाल करके कोड बनाना और उसमें बदलाव करना.

उदाहरण कोड डाउनलोड करने के लिए:

  1. नीचे दिए गए कमांड का इस्तेमाल करके git रिपॉज़िटरी का क्लोन बनाएं:

    git clone https://github.com/google-ai-edge/mediapipe-samples
    
  2. वैकल्पिक रूप से, विरल चेकआउट का इस्तेमाल करने के लिए अपने git इंस्टेंस को कॉन्फ़िगर करें, ताकि सिर्फ़ पोज़ लैंडमार्क के उदाहरण ऐप्लिकेशन की फ़ाइलें:

    cd mediapipe
    git sparse-checkout init --cone
    git sparse-checkout set examples/pose_landmarker/ios/
    

उदाहरण के कोड का लोकल वर्शन बनाने के बाद, MediaPipe टास्क लाइब्रेरी में, Xcode का इस्तेमाल करके प्रोजेक्ट खोलें और ऐप्लिकेशन चलाएं. इसके लिए निर्देशों के लिए, iOS के लिए सेटअप गाइड देखें.

मुख्य कॉम्पोनेंट

इन फ़ाइलों में पोज़ लैंडमार्कर के उदाहरण के लिए, ज़रूरी कोड शामिल है ऐप्लिकेशन:

  • PoseLandmarkerService.swift: लैंडमार्क को शुरू करता है, मॉडल चुनने का काम हैंडल करता है, और अनुमान चलाता है इनपुट डेटा पर.
  • CameraViewController: यह लाइव कैमरा फ़ीड के इनपुट मोड के लिए, यूज़र इंटरफ़ेस (यूआई) लागू करता है. साथ ही, लैंडमार्क.
  • MediaLibraryViewController.swift: स्टिल इमेज और वीडियो फ़ाइल के इनपुट मोड के लिए यूज़र इंटरफ़ेस (यूआई) लागू करता है और लैंडमार्क को विज़ुअलाइज़ करता है.

सेटअप

इस सेक्शन में, आपके डेवलपमेंट एनवायरमेंट को सेट अप करने और पोज़ लैंडमार्कर का इस्तेमाल करने के लिए कोड प्रोजेक्ट. अपना खाता सेट अप करने के बारे में MediaPipe टास्क के लिए डेवलपमेंट एनवायरमेंट. इसमें प्लैटफ़ॉर्म वर्शन भी शामिल है ज़रूरी शर्तों के बारे में जानने के लिए, iOS के लिए सेटअप गाइड देखें.

डिपेंडेंसी

पोज़ लैंडमार्कर, MediaPipeTasksVision लाइब्रेरी का इस्तेमाल करता है, जिसे इंस्टॉल करना ज़रूरी होता है CocoaPods का इस्तेमाल करके. यह लाइब्रेरी Swift और Objective-C, दोनों ऐप्लिकेशन के साथ काम करती है इसके लिए, अलग से किसी भाषा के सेटअप की ज़रूरत नहीं होती.

macOS पर CocoaPods को इंस्टॉल करने के निर्देशों के लिए, CocoaPods को देखें इंस्टॉल करने की गाइड देखें. अपने ऐप्लिकेशन के लिए ज़रूरी पॉड के साथ Podfile बनाने का तरीका जानने के लिए, देखने के लिए, Google Play Store में CocoaPods.

नीचे दिए गए कोड का इस्तेमाल करके, Podfile में MediaPipeTasksVision पॉड जोड़ें:

target 'MyPoseLandmarkerApp' do
  use_frameworks!
  pod 'MediaPipeTasksVision'
end

अगर आपके ऐप्लिकेशन में यूनिट टेस्ट टारगेट शामिल हैं, तो iOS सेट अप करने के बारे में ज़्यादा जानकारी पाएं Podfile.

मॉडल

MediaPipe पोज़ लैंडमार्कर टास्क के लिए, एक प्रशिक्षित बंडल की ज़रूरत होती है, जो इस टास्क को पूरा करें. इसके लिए उपलब्ध प्रशिक्षित मॉडल के बारे में ज़्यादा जानकारी पाने के लिए लैंडमार्क पोज़ करें, टास्क की खास जानकारी मॉडल देखें सेक्शन में दिया गया है.

download_models.sh का इस्तेमाल करें स्क्रिप्ट मॉडल डाउनलोड करने और Xcode का इस्तेमाल करके उसे अपनी प्रोजेक्ट डायरेक्ट्री में जोड़ने के लिए. इसके लिए अपने Xcode प्रोजेक्ट में फ़ाइलें जोड़ने के तरीके के बारे में निर्देश, फ़ाइलें मैनेज करना और आपके Xcode के फ़ोल्डर प्रोजेक्ट.

मॉडल का पाथ बताने के लिए, BaseOptions.modelAssetPath प्रॉपर्टी का इस्तेमाल करें शामिल हैं. कोड के उदाहरण के लिए, अगला सेक्शन देखें.

टास्क बनाएं

आप पोज़ लैंडमार्कर टास्क को उसके किसी भी शुरू करने वाले को कॉल करके बना सकते हैं. कॉन्टेंट बनाने PoseLandmarker(options:) शुरू करने वाला, कॉन्फ़िगरेशन के लिए वैल्यू स्वीकार करता है के विकल्प.

अगर आपको पसंद के मुताबिक बनाए गए कॉन्फ़िगरेशन के साथ शुरू किए गए पोज़ लैंडमार्क की ज़रूरत नहीं है, तो विकल्पों के लिए, आप PoseLandmarker(modelPath:) प्रारंभकर्ता का उपयोग करके लैंडमार्क को डिफ़ॉल्ट विकल्पों के साथ पोज़ करें. कॉन्फ़िगरेशन के बारे में ज़्यादा जानकारी पाने के लिए विकल्पों के लिए, कॉन्फ़िगरेशन की खास जानकारी देखें.

पोज़ लैंडमार्कर टास्क तीन इनपुट डेटा टाइप के साथ काम करता है: स्टिल इमेज, वीडियो फ़ाइलें साथ ही, लाइव वीडियो स्ट्रीम भी दिखेंगी. डिफ़ॉल्ट रूप से, PoseLandmarker(modelPath:) स्टिल इमेज के लिए टास्क. अगर आपको वीडियो प्रोसेस करने के लिए टास्क शुरू करना है फ़ाइलें या लाइव वीडियो स्ट्रीम हैं, तो वीडियो की जानकारी देने के लिए PoseLandmarker(options:) का इस्तेमाल करें या लाइव स्ट्रीम मोड का इस्तेमाल करें. लाइव स्ट्रीम मोड इस्तेमाल करने के लिए, poseLandmarkerLiveStreamDelegate कॉन्फ़िगरेशन विकल्प, जो प्रतिनिधि को पोज़ लैंडमार्क की पहचान करने के नतीजे डिलीवर करने के लिए, लैंडमार्कर को पोज़ करें एसिंक्रोनस रूप से.

टास्क बनाने का तरीका जानने के लिए, अपने रनिंग मोड से जुड़ा टैब चुनें अनुमान लगाने के लिए कहा जा सकता है.

Swift

इमेज

import MediaPipeTasksVision

let modelPath = Bundle.main.path(forResource: "pose_landmarker",
                                      ofType: "task")

let options = PoseLandmarkerOptions()
options.baseOptions.modelAssetPath = modelPath
options.runningMode = .image
options.minPoseDetectionConfidence = minPoseDetectionConfidence
options.minPosePresenceConfidence = minPosePresenceConfidence
options.minTrackingConfidence = minTrackingConfidence
options.numPoses = numPoses

let poseLandmarker = try PoseLandmarker(options: options)
    

वीडियो

import MediaPipeTasksVision

let modelPath = Bundle.main.path(forResource: "pose_landmarker",
                                      ofType: "task")

let options = PoseLandmarkerOptions()
options.baseOptions.modelAssetPath = modelPath
options.runningMode = .video
options.minPoseDetectionConfidence = minPoseDetectionConfidence
options.minPosePresenceConfidence = minPosePresenceConfidence
options.minTrackingConfidence = minTrackingConfidence
options.numPoses = numPoses

let poseLandmarker = try PoseLandmarker(options: options)
    

लाइवस्ट्रीम

import MediaPipeTasksVision

// Class that conforms to the `PoseLandmarkerLiveStreamDelegate` protocol and
// implements the method that the pose landmarker calls once it finishes
// performing pose landmark detection in each input frame.
class PoseLandmarkerResultProcessor: NSObject, PoseLandmarkerLiveStreamDelegate {

  func poseLandmarker(
    _ poseLandmarker: PoseLandmarker,
    didFinishDetection result: PoseLandmarkerResult?,
    timestampInMilliseconds: Int,
    error: Error?) {

    // Process the pose landmarker result or errors here.

  }
}

let modelPath = Bundle.main.path(forResource: "pose_landmarker",
                                      ofType: "task")

let options = PoseLandmarkerOptions()
options.baseOptions.modelAssetPath = modelPath
options.runningMode = .liveStream
options.minPoseDetectionConfidence = minPoseDetectionConfidence
options.minPosePresenceConfidence = minPosePresenceConfidence
options.minTrackingConfidence = minTrackingConfidence
options.numPoses = numPoses

// Assign an object of the class to the `poseLandmarkerLiveStreamDelegate`
// property.
let processor = PoseLandmarkerResultProcessor()
options.poseLandmarkerLiveStreamDelegate = processor

let poseLandmarker = try PoseLandmarker(options: options)
    

Objective-C

इमेज

@import MediaPipeTasksVision;

NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"pose_landmarker"
                                                      ofType:@"task"];

MPPPoseLandmarkerOptions *options = [[MPPPoseLandmarkerOptions alloc] init];
options.baseOptions.modelAssetPath = modelPath;
options.runningMode = MPPRunningModeImage;
options.minPoseDetectionConfidence = minPoseDetectionConfidence;
options.minPosePresenceConfidence = minPosePresenceConfidence;
options.minTrackingConfidence = minTrackingConfidence;
options.numPoses = numPoses;

MPPPoseLandmarker *poseLandmarker =
  [[MPPPoseLandmarker alloc] initWithOptions:options error:nil];
    

वीडियो

@import MediaPipeTasksVision;

NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"pose_landmarker"
                                                      ofType:@"task"];

MPPPoseLandmarkerOptions *options = [[MPPPoseLandmarkerOptions alloc] init];
options.baseOptions.modelAssetPath = modelPath;
options.runningMode = MPPRunningModeVideo;
options.minPoseDetectionConfidence = minPoseDetectionConfidence;
options.minPosePresenceConfidence = minPosePresenceConfidence;
options.minTrackingConfidence = minTrackingConfidence;
options.numPoses = numPoses;

MPPPoseLandmarker *poseLandmarker =
  [[MPPPoseLandmarker alloc] initWithOptions:options error:nil];
    

लाइवस्ट्रीम

@import MediaPipeTasksVision;

// Class that conforms to the `MPPPoseLandmarkerLiveStreamDelegate` protocol
// and implements the method that the pose landmarker calls once it finishes
// performing pose landmarks= detection in each input frame.

@interface APPPoseLandmarkerResultProcessor : NSObject 

@end

@implementation APPPoseLandmarkerResultProcessor

-   (void)poseLandmarker:(MPPPoseLandmarker *)poseLandmarker
    didFinishDetectionWithResult:(MPPPoseLandmarkerResult *)poseLandmarkerResult
         timestampInMilliseconds:(NSInteger)timestampInMilliseconds
                           error:(NSError *)error {

    // Process the pose landmarker result or errors here.

}

@end

NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"pose_landmarker"
                                                      ofType:@"task"];

MPPPoseLandmarkerOptions *options = [[MPPPoseLandmarkerOptions alloc] init];
options.baseOptions.modelAssetPath = modelPath;
options.runningMode = MPPRunningModeLiveStream;
options.minPoseDetectionConfidence = minPoseDetectionConfidence;
options.minPosePresenceConfidence = minPosePresenceConfidence;
options.minTrackingConfidence = minTrackingConfidence;
options.numPoses = numPoses;

// Assign an object of the class to the `poseLandmarkerLiveStreamDelegate`
// property.
APPPoseLandmarkerResultProcessor *processor =
  [APPPoseLandmarkerResultProcessor new];
options.poseLandmarkerLiveStreamDelegate = processor;

MPPPoseLandmarker *poseLandmarker =
  [[MPPPoseLandmarker alloc] initWithOptions:options error:nil];
    

ध्यान दें: अगर वीडियो मोड या लाइव स्ट्रीम मोड का इस्तेमाल किया जाता है, तो पोज़ लैंडमार्कर हर फ़्रेम पर हथेली की पहचान करने वाले मॉडल को ट्रिगर होने से बचाने के लिए, ट्रैकिंग से बचें. इससे, इंतज़ार का समय कम करें.

कॉन्फ़िगरेशन विकल्प

इस टास्क में iOS ऐप्लिकेशन के लिए, नीचे दिए गए कॉन्फ़िगरेशन के विकल्प मौजूद हैं:

विकल्प का नाम ब्यौरा मान की सीमा डिफ़ॉल्ट मान
running_mode टास्क के लिए रनिंग मोड सेट करता है. तीन मोड:

इमेज: सिंगल इमेज इनपुट का मोड.

वीडियो: किसी वीडियो के डिकोड किए गए फ़्रेम के लिए मोड.

LIVE_STREAM: इनपुट की लाइवस्ट्रीम करने का मोड जैसी निजी जानकारी को किसी भी समय रिकॉर्ड कर सकते हैं. इस मोड में, poseLandmarkerLiveStreamDelegate को इस पर सेट होना चाहिए क्लास का एक इंस्टेंस जो नतीजे पाने के लिए PoseLandmarkerLiveStreamDelegate पोज़ लैंडमार्क की पहचान एसिंक्रोनस तरीके से की जा रही है.
{RunningMode.image, RunningMode.video, RunningMode.liveStream} RunningMode.image
num_poses ज़्यादा से ज़्यादा पोज़ की संख्या जिनका पता लैंडमार्क पोज़ दें. Integer > 0 1
min_pose_detection_confidence पोज़ की पहचान के लिए कम से कम कॉन्फ़िडेंस स्कोर यह होना चाहिए सफल माना जाता है. Float [0.0,1.0] 0.5
min_pose_presence_confidence पोज़ की मौजूदगी का कम से कम कॉन्फ़िडेंस स्कोर पोज़ लैंडमार्क की पहचान करने के लिए स्कोर किया जा सकता है. Float [0.0,1.0] 0.5
min_tracking_confidence पोज़ ट्रैकिंग के लिए कम से कम कॉन्फ़िडेंस स्कोर इन्हें सफल माना जाता है. Float [0.0,1.0] 0.5
output_segmentation_masks क्या पोज़ लैंडमार्कर, पहचाने गए आइटम के लिए सेगमेंटेशन मास्क देता है पोज़. Boolean False
result_callback लैंडमार्कर के नतीजे पाने के लिए, यह नतीजा लिसनर को सेट करता है जब Pose मार्कर लाइव स्ट्रीम मोड में हो, तब यह एसिंक्रोनस रूप से उपलब्ध नहीं होता है. इसका इस्तेमाल सिर्फ़ तब किया जा सकता है, जब रनिंग मोड को LIVE_STREAM पर सेट किया गया हो ResultListener N/A

लाइव स्ट्रीम कॉन्फ़िगरेशन

जब रनिंग मोड को लाइव स्ट्रीम पर सेट किया जाता है, तब पोज़ लैंडमार्कर के लिए अतिरिक्त poseLandmarkerLiveStreamDelegate कॉन्फ़िगरेशन विकल्प मिलता है, जो पोज़ लैंडमार्कर को पोज़ लैंडमार्क की पहचान के नतीजे देने में मदद करता है एसिंक्रोनस रूप से. प्रतिनिधि को poseLandmarker(_:didFinishDetection:timestampInMilliseconds:error:) तरीका, जिसे पोज़ लैंडमार्कर, पोज़ देने के नतीजों को प्रोसेस करने के बाद कॉल करता है लैंडमार्क की पहचान करने की सुविधा.

विकल्प का नाम ब्यौरा मान की सीमा डिफ़ॉल्ट मान
poseLandmarkerLiveStreamDelegate पोज़ लैंडमार्कर को पोज़ देने के नतीजे पाने में मदद करता है लैंडमार्क की पहचान करने की सुविधा, एसिंक्रोनस तरीके से लाइव स्ट्रीम मोड में मिलती है. वह क्लास जिसकी वजह से इंस्टेंस इस प्रॉपर्टी पर सेट है तो poseLandmarker(_:didFinishDetection:timestampInMilliseconds:error:) तरीका. लागू नहीं सेट नहीं है

डेटा तैयार करें

आपको पहले, इनपुट इमेज या फ़्रेम को MPImage ऑब्जेक्ट में बदलना होगा उसे पोज़ लैंडमार्कर के पास भेजना. MPImage में, अलग-अलग तरह की iOS इमेज इस्तेमाल की जा सकती हैं साथ ही, अनुमान लगाने के लिए किसी भी रनिंग मोड में इनका इस्तेमाल किया जा सकता है. ज़्यादा के लिए MPImage के बारे में जानकारी पाने के लिए, MPImage API

अपने इस्तेमाल के उदाहरण और रनिंग मोड के हिसाब से iOS इमेज फ़ॉर्मैट चुनें ऐप्लिकेशन के लिए आवश्यक है.MPImage UIImage, CVPixelBuffer, और CMSampleBuffer iOS इमेज फ़ॉर्मैट.

UIImage

UIImage फ़ॉर्मैट, नीचे दिए गए दौड़ने मोड के लिए सबसे सही है:

  • इमेज: किसी ऐप्लिकेशन बंडल, उपयोगकर्ता गैलरी या फ़ाइल सिस्टम से ली गई इमेज, इस फ़ॉर्मैट में दी गई हैं UIImage इमेज को MPImage ऑब्जेक्ट में बदला जा सकता है.

  • वीडियो: AVAssetImageGenerator का इस्तेमाल करें वीडियो फ़्रेम एक्सट्रैक्ट करने के लिए CGImage फ़ॉर्मैट करें, फिर उन्हें UIImage इमेज में बदलें.

Swift

// Load an image on the user's device as an iOS `UIImage` object.

// Convert the `UIImage` object to a MediaPipe's Image object having the default
// orientation `UIImage.Orientation.up`.
let image = try MPImage(uiImage: image)
    

Objective-C

// Load an image on the user's device as an iOS `UIImage` object.

// Convert the `UIImage` object to a MediaPipe's Image object having the default
// orientation `UIImageOrientationUp`.
MPImage *image = [[MPPImage alloc] initWithUIImage:image error:nil];
    

उदाहरण में MPImage को डिफ़ॉल्ट वैल्यू के साथ शुरू किया गया है UIImage.Orientation.Up स्क्रीन की दिशा. MPImage को इस्तेमाल करने वाली किसी भी सुविधा के साथ शुरू किया जा सकता है UIImage.Orientation वैल्यू. पोज़ लैंडमार्कर, मिरर किए गए ओरिएंटेशन के साथ काम नहीं करता. जैसे, .upMirrored, .downMirrored, .leftMirrored, .rightMirrored.

UIImage के बारे में ज़्यादा जानकारी के लिए, UIImage Apple Developer पर जाएं दस्तावेज़.

CVPixelBuffer

CVPixelBuffer फ़ॉर्मैट, फ़्रेम जनरेट करने वाले ऐप्लिकेशन के लिए सबसे सही है और iOS CoreImage का इस्तेमाल करें प्रोसेसिंग के लिए फ़्रेमवर्क.

CVPixelBuffer फ़ॉर्मैट, नीचे दिए गए दौड़ने मोड के लिए सबसे सही है:

  • इमेज: ऐसे ऐप्लिकेशन जो कुछ प्रोसेसिंग के बाद CVPixelBuffer इमेज जनरेट करते हैं का इस्तेमाल करके iOS के CoreImage फ़्रेमवर्क का इस्तेमाल करके, इमेज रनिंग मोड.

  • वीडियो: वीडियो फ़्रेम को CVPixelBuffer फ़ॉर्मैट में बदला जा सकता है प्रोसेस किया जाता है और फिर वीडियो मोड में पोज़ लैंडमार्कर पर भेजा जाता है.

  • लाइव स्ट्रीम: फ़्रेम जनरेट करने के लिए, iOS कैमरे का इस्तेमाल करने वाले ऐप्लिकेशन को बदला जा सकता है को भेजने से पहले प्रोसेसिंग के लिए CVPixelBuffer फ़ॉर्मैट में लैंडमार्क को लाइव स्ट्रीम मोड में पोज़ दें.

Swift

// Obtain a CVPixelBuffer.

// Convert the `CVPixelBuffer` object to a MediaPipe's Image object having the default
// orientation `UIImage.Orientation.up`.
let image = try MPImage(pixelBuffer: pixelBuffer)
    

Objective-C

// Obtain a CVPixelBuffer.

// Convert the `CVPixelBuffer` object to a MediaPipe's Image object having the
// default orientation `UIImageOrientationUp`.
MPImage *image = [[MPPImage alloc] initWithUIImage:image error:nil];
    

CVPixelBuffer के बारे में ज़्यादा जानकारी के लिए, CVPixelBuffer Apple पर जाएं डेवलपर दस्तावेज़.

CMSampleBuffer

CMSampleBuffer फ़ॉर्मैट में, यूनिफ़ॉर्म मीडिया टाइप के मीडिया सैंपल सेव किए जाते हैं और यह होता है ये लाइव स्ट्रीम रनिंग मोड के लिए ज़्यादा काम के होते हैं. iOS कैमरों से लाइव फ़्रेम की सुविधा iOS के ज़रिए CMSampleBuffer फ़ॉर्मैट में एसिंक्रोनस रूप से डिलीवर किया जाता है AVCaptureVideoDataOutput.

Swift

// Obtain a CMSampleBuffer.

// Convert the `CMSampleBuffer` object to a MediaPipe's Image object having the default
// orientation `UIImage.Orientation.up`.
let image = try MPImage(sampleBuffer: sampleBuffer)
    

Objective-C

// Obtain a `CMSampleBuffer`.

// Convert the `CMSampleBuffer` object to a MediaPipe's Image object having the
// default orientation `UIImageOrientationUp`.
MPImage *image = [[MPPImage alloc] initWithSampleBuffer:sampleBuffer error:nil];
    

CMSampleBuffer के बारे में ज़्यादा जानकारी के लिए, CMSampleBuffer Apple देखें डेवलपर दस्तावेज़.

टास्क को पूरा करें

पोज़ लैंडमार्कर चलाने के लिए, असाइन किए गए detect() तरीके का इस्तेमाल करें रनिंग मोड:

  • फ़ोटो: detect(image:)
  • वीडियो: detect(videoFrame:timestampInMilliseconds:)
  • लाइवस्ट्रीम: detectAsync(image:timestampInMilliseconds:)

नीचे दिए गए कोड सैंपल, Pose मार्कर को चलाने के आसान उदाहरण दिखाते हैं ये अलग-अलग रनिंग मोड हैं:

Swift

इमेज

let result = try poseLandmarker.detect(image: image)
    

वीडियो

let result = try poseLandmarker.detect(
  videoFrame: image,
  timestampInMilliseconds: timestamp)
    

लाइवस्ट्रीम

try poseLandmarker.detectAsync(
  image: image,
  timestampInMilliseconds: timestamp)
    

Objective-C

इमेज

MPPPoseLandmarkerResult *result =
  [poseLandmarker detectImage:image error:nil];
    

वीडियो

MPPPoseLandmarkerResult *result =
  [poseLandmarker detectVideoFrame:image
           timestampInMilliseconds:timestamp
                             error:nil];
    

लाइवस्ट्रीम

BOOL success =
  [poseLandmarker detectAsyncImage:image
           timestampInMilliseconds:timestamp
                             error:nil];
    

पॉज़ लैंडमार्कर कोड के उदाहरण में, इनमें से हर मोड को लागू करने का तरीका दिखाया गया है ज़्यादा जानकारी detect(image:), detect(videoFrame:timestampInMilliseconds:), और detectAsync(image:timestampInMilliseconds:). उदाहरण कोड आपको उपयोगकर्ता को एक से दूसरे मोड पर स्विच करना होगा, जो शायद आपके इस्तेमाल के लिए ज़रूरी नहीं है केस.

निम्न पर ध्यान दें:

  • वीडियो मोड या लाइव स्ट्रीम मोड में चलाते समय, आपको पोज़ लैंडमार्कर टास्क के इनपुट फ़्रेम का टाइमस्टैंप.

  • इमेज या वीडियो मोड में चलते समय, पोज़ लैंडमार्कर टास्क को मौजूदा थ्रेड को तब तक सबमिट नहीं किया जा सकता, जब तक कि यह इनपुट इमेज या फ़्रेम की प्रोसेस पूरी नहीं कर लेता. यहां की यात्रा पर हूं मौजूदा थ्रेड को ब्लॉक होने से बचाएं और बैकग्राउंड में प्रोसेसिंग चलाएं iOS पर थ्रेड डिस्पैच करें या NSOperation फ़्रेमवर्क शामिल हैं.

  • लाइव स्ट्रीम मोड में इस्तेमाल करते समय, 'पोज़ लैंडमार्कर' टास्क तुरंत वापस आ जाता है और मौजूदा थ्रेड को ब्लॉक नहीं करता. यह poseLandmarker(_:didFinishDetection:timestampInMilliseconds:error:) तरीका हर इनपुट फ़्रेम को प्रोसेस करने के बाद, पोज़ लैंडमार्कर नतीजा मिलेगा. कॉन्टेंट बनाने पॉज़ लैंडमार्कर, खास सीरियल नंबर पर इस तरीके को एसिंक्रोनस तरीके से इस्तेमाल करता है भेजने की सूची. यूज़र इंटरफ़ेस पर नतीजे दिखाने के लिए, नतीजों को प्रोसेस करने के बाद मुख्य सूची में जोड़ दिया जाता है. अगर detectAsync फ़ंक्शन को तब कॉल किया जाता है, जब पोज़ लैंडमार्कर टास्क किसी दूसरे फ़ंक्शन को प्रोसेस करने में व्यस्त हो फ़्रेम के लिए, पोज़ लैंडमार्कर नए इनपुट फ़्रेम को अनदेखा करता है.

नतीजों को हैंडल करना और दिखाना

अनुमान लगाने पर, पोज़ लैंडमार्कर टास्क, PoseLandmarkerResult दिखाता है जिसमें हर पोज़ लैंडमार्क के लिए निर्देशांक होते हैं.

इस टास्क के आउटपुट डेटा का एक उदाहरण नीचे दिया गया है:

PoseLandmarkerResult:
  Landmarks:
    Landmark #0:
      x            : 0.638852
      y            : 0.671197
      z            : 0.129959
      visibility   : 0.9999997615814209
      presence     : 0.9999984502792358
    Landmark #1:
      x            : 0.634599
      y            : 0.536441
      z            : -0.06984
      visibility   : 0.999909
      presence     : 0.999958
    ... (33 landmarks per pose)
  WorldLandmarks:
    Landmark #0:
      x            : 0.067485
      y            : 0.031084
      z            : 0.055223
      visibility   : 0.9999997615814209
      presence     : 0.9999984502792358
    Landmark #1:
      x            : 0.063209
      y            : -0.00382
      z            : 0.020920
      visibility   : 0.999976
      presence     : 0.999998
    ... (33 world landmarks per pose)
  SegmentationMasks:
    ... (pictured below)

आउटपुट में नॉर्मलाइज़ किए गए निर्देशांक (Landmarks) और दुनिया, दोनों शामिल होते हैं हर लैंडमार्क के लिए निर्देशांक (WorldLandmarks) डालें.

आउटपुट में नीचे दिए गए नॉर्मलाइज़ किए गए निर्देशांक शामिल हैं (Landmarks):

  • x और y: लैंडमार्क कोऑर्डिनेट को 0.0 और 1.0 के बीच इमेज की चौड़ाई (x) और ऊंचाई (y).

  • z: लैंडमार्क गहराई, कूल्हे के मध्य बिंदु से गहराई के रूप में ऑरिजिन. वैल्यू जितनी कम होती है, लैंडमार्क, कैमरे के उतना ही करीब होता है. कॉन्टेंट बनाने z की मात्रा का मान करीब-करीब x के बराबर होता है.

  • visibility: इमेज में लैंडमार्क के दिखने की संभावना.

आउटपुट में दुनिया के ये निर्देशांक शामिल हैं (WorldLandmarks):

  • x, y, और z: मीटर में, वास्तविक दुनिया के 3-डाइमेंशन वाले निर्देशांक, मूल रूप से कूल्हे के बीच का हिस्सा.

  • visibility: इमेज में लैंडमार्क के दिखने की संभावना.

नीचे दी गई इमेज, टास्क के आउटपुट का विज़ुअलाइज़ेशन दिखाती है:

वैकल्पिक सेगमेंटेशन मास्क, हर पिक्सल से जुड़े होने की संभावना दिखाता है को नुकसान पहुंचता है. नीचे दी गई इमेज, टास्क आउटपुट:

पोज़ लैंडमार्कर के उदाहरण कोड से, पोज़ लैंडमार्कर को दिखाने का तरीका पता चलता है नतीजे.