MediaPipe हैंड लैंडमार्क टास्क की मदद से, इमेज में मौजूद हाथों के लैंडमार्क का पता लगाया जा सकता है. इन निर्देशों में iOS ऐप्लिकेशन पर 'हैंड लैंडमार्कर' इस्तेमाल करने का तरीका बताया गया है. इन निर्देशों में बताया गया कोड सैंपल, GitHub पर उपलब्ध है.
इस टास्क की क्षमताओं, मॉडल, और कॉन्फ़िगरेशन विकल्पों के बारे में ज़्यादा जानकारी के लिए, खास जानकारी देखें.
कोड का उदाहरण
MediaPipe Tasks उदाहरण कोड, iOS के लिए एक हैंड लैंडमार्कर ऐप्लिकेशन को बुनियादी तौर पर लागू करने का तरीका है. इस उदाहरण में, एक iOS डिवाइस के कैमरे का इस्तेमाल किया गया है, ताकि लगातार वीडियो स्ट्रीम में खास पहचानों का पता लगाया जा सके. ऐप्लिकेशन, डिवाइस की गैलरी से इमेज और वीडियो में मौजूद हाथ की खास बातों का भी पता लगा सकता है.
इस ऐप्लिकेशन को, अपने iOS ऐप्लिकेशन के लिए शुरुआती पॉइंट के तौर पर इस्तेमाल किया जा सकता है. इसके अलावा, किसी मौजूदा ऐप्लिकेशन में बदलाव करते समय इसका इस्तेमाल भी किया जा सकता है. हैंड लैंडमार्कर के उदाहरण वाले कोड को GitHub पर होस्ट किया जाता है.
कोड डाउनलोड करें
नीचे दिए गए निर्देशों में git कमांड लाइन टूल का इस्तेमाल करके, उदाहरण कोड की लोकल कॉपी बनाने का तरीका बताया गया है.
उदाहरण कोड डाउनलोड करने के लिए:
नीचे दिए गए कमांड का इस्तेमाल करके, गिट रिपॉज़िटरी का क्लोन बनाएं:
git clone https://github.com/google-ai-edge/mediapipe-samples
इसके अलावा, स्पार्स चेकआउट का इस्तेमाल करने के लिए अपना गिट इंस्टेंस कॉन्फ़िगर करें, ताकि आपके पास सिर्फ़ हैंड लैंडमार्कर के उदाहरण वाले ऐप्लिकेशन की फ़ाइलें हों:
cd mediapipe git sparse-checkout init --cone git sparse-checkout set examples/hand_landmarker/ios/
उदाहरण कोड का स्थानीय वर्शन बनाने के बाद, आप MediaPipe टास्क लाइब्रेरी इंस्टॉल कर सकते हैं, Xcode का इस्तेमाल करके प्रोजेक्ट खोलें और ऐप्लिकेशन चलाएं. निर्देशों के लिए, iOS के लिए सेटअप गाइड देखें.
मुख्य कॉम्पोनेंट
इन फ़ाइलों में हैंड लैंडमार्कर के उदाहरण वाले ऐप्लिकेशन का ज़रूरी कोड दिया गया है:
- HandLandmarkerService.swift: हैंड लैंडमार्कर को शुरू करता है, चुने गए मॉडल को हैंडल करता है, और इनपुट डेटा का अनुमान लगाता है.
- CameraViewController.swift: लाइव कैमरा फ़ीड इनपुट मोड के लिए यूज़र इंटरफ़ेस (यूआई) लागू करता है और नतीजों को विज़ुअलाइज़ करता है.
- MediaLibraryViewController.swift: स्टिल इमेज और वीडियो फ़ाइल के इनपुट मोड के लिए यूज़र इंटरफ़ेस (यूआई) लागू करता है और नतीजों को विज़ुअलाइज़ करता है.
सेटअप
इस सेक्शन में हैंड लैंडमार्कर का इस्तेमाल करने वाले कोड प्रोजेक्ट और डेवलपमेंट एनवायरमेंट को सेट अप करने के मुख्य चरणों के बारे में बताया गया है. प्लैटफ़ॉर्म के वर्शन की ज़रूरी शर्तों के साथ-साथ MediaPipe टास्क का इस्तेमाल करने के लिए, अपना डेवलपमेंट एनवायरमेंट सेट अप करने की सामान्य जानकारी के लिए, iOS के लिए सेटअप गाइड देखें.
डिपेंडेंसी
हैंड लैंडमार्कर, MediaPipeTasksVision
लाइब्रेरी का इस्तेमाल करता है. इसे CocoaPods की मदद से इंस्टॉल किया जाना चाहिए. यह लाइब्रेरी, Swift और Objective-C ऐप्लिकेशन, दोनों के साथ काम करती है
और इसके लिए अलग से किसी भाषा के सेटअप की ज़रूरत नहीं होती.
macOS पर CocoaPods इंस्टॉल करने के निर्देशों के लिए, CocoaPods को इंस्टॉल करने से जुड़ी गाइड देखें.
अपने ऐप्लिकेशन के लिए ज़रूरी पॉड के साथ Podfile
बनाने का तरीका जानने के लिए, CocoaPods का इस्तेमाल करना देखें.
नीचे दिए गए कोड का इस्तेमाल करके, Podfile
में MediaPipeTasksVision पॉड जोड़ें:
target 'MyHandLandmarkerApp' do
use_frameworks!
pod 'MediaPipeTasksVision'
end
अगर आपके ऐप्लिकेशन में यूनिट टेस्ट टारगेट शामिल हैं, तो अपने Podfile
को सेट अप करने के बारे में ज़्यादा जानकारी के लिए iOS के लिए सेट अप करने से जुड़ी गाइड देखें.
मॉडल
MediaPipe हैंड लैंडमार्कर टास्क के लिए एक प्रशिक्षित मॉडल की ज़रूरत होती है, जो इस टास्क के साथ काम कर सके. हैंड लैंडमार्कर के लिए उपलब्ध ट्रेनिंग मॉडल के बारे में ज़्यादा जानकारी के लिए, टास्क की खास जानकारी वाला मॉडल सेक्शन देखें.
कोई मॉडल चुनें और डाउनलोड करें और Xcode का इस्तेमाल करके उसे अपनी प्रोजेक्ट डायरेक्ट्री में जोड़ें. अपने Xcode प्रोजेक्ट में फ़ाइलें जोड़ने के तरीके से जुड़े निर्देशों के लिए, अपने Xcode प्रोजेक्ट में फ़ाइलें और फ़ोल्डर मैनेज करना देखें.
अपने ऐप्लिकेशन बंडल में मॉडल का पाथ बताने के लिए, BaseOptions.modelAssetPath
प्रॉपर्टी का इस्तेमाल करें. कोड के उदाहरण के लिए, अगला सेक्शन देखें.
टास्क बनाएं
हैंड लैंडमार्कर टास्क बनाने के लिए, इसके किसी इनिशलाइज़र को कॉल किया जा सकता है. HandLandmarker(options:)
शुरू करने वाला टूल, कॉन्फ़िगरेशन के विकल्पों के लिए वैल्यू स्वीकार करता है.
अगर आपको पसंद के मुताबिक बनाए गए कॉन्फ़िगरेशन के विकल्पों के साथ शुरू करने वाला हैंड लैंडमार्कर नहीं चाहिए, तो
डिफ़ॉल्ट विकल्पों वाले हैंड लैंडमार्कर को बनाने के लिए,
HandLandmarker(modelPath:)
इनिशलाइज़र का इस्तेमाल किया जा सकता है. कॉन्फ़िगरेशन के विकल्पों के बारे में ज़्यादा जानने के लिए, कॉन्फ़िगरेशन की खास जानकारी देखें.
हैंड लैंडमार्क टास्क में तीन तरह के इनपुट डेटा टाइप काम करते हैं: स्टिल इमेज, वीडियो फ़ाइलें, और लाइव वीडियो स्ट्रीम. डिफ़ॉल्ट रूप से, HandLandmarker(modelPath:)
स्टिल इमेज के लिए टास्क शुरू करता है. अगर आपको वीडियो फ़ाइलों या लाइव वीडियो स्ट्रीम को प्रोसेस करने के लिए, टास्क शुरू करना है, तो वीडियो या लाइव स्ट्रीम के रनिंग मोड के बारे में बताने के लिए HandLandmarker(options:)
का इस्तेमाल करें. लाइव स्ट्रीम मोड के लिए, handLandmarkerLiveStreamDelegate
को कॉन्फ़िगर करने के एक और विकल्प की भी ज़रूरत होती है. इससे हैंड लैंडमार्कर, प्रतिनिधियों को एसिंक्रोनस तरीके से हैंड लैंडमार्कर नतीजे दे पाता है.
टास्क बनाने और अनुमान लगाने का तरीक़ा जानने के लिए, अपने रनिंग मोड से जुड़ा टैब चुनें.
Swift
Image
import MediaPipeTasksVision let modelPath = Bundle.main.path(forResource: "hand_landmarker", ofType: "task") let options = HandLandmarkerOptions() options.baseOptions.modelAssetPath = modelPath options.runningMode = .image options.minHandDetectionConfidence = minHandDetectionConfidence options.minHandPresenceConfidence = minHandPresenceConfidence options.minTrackingConfidence = minHandTrackingConfidence options.numHands = numHands let handLandmarker = try HandLandmarker(options: options)
वीडियो
import MediaPipeTasksVision let modelPath = Bundle.main.path(forResource: "hand_landmarker", ofType: "task") let options = HandLandmarkerOptions() options.baseOptions.modelAssetPath = modelPath options.runningMode = .video options.minHandDetectionConfidence = minHandDetectionConfidence options.minHandPresenceConfidence = minHandPresenceConfidence options.minTrackingConfidence = minHandTrackingConfidence options.numHands = numHands let handLandmarker = try HandLandmarker(options: options)
लाइव स्ट्रीम
import MediaPipeTasksVision // Class that conforms to the `HandLandmarkerLiveStreamDelegate` protocol and // implements the method that the hand landmarker calls once it finishes // performing landmarks detection in each input frame. class HandLandmarkerResultProcessor: NSObject, HandLandmarkerLiveStreamDelegate { func handLandmarker( _ handLandmarker: HandLandmarker, didFinishDetection result: HandLandmarkerResult?, timestampInMilliseconds: Int, error: Error?) { // Process the hand landmarker result or errors here. } } let modelPath = Bundle.main.path( forResource: "hand_landmarker", ofType: "task") let options = HandLandmarkerOptions() options.baseOptions.modelAssetPath = modelPath options.runningMode = .liveStream options.minHandDetectionConfidence = minHandDetectionConfidence options.minHandPresenceConfidence = minHandPresenceConfidence options.minTrackingConfidence = minHandTrackingConfidence options.numHands = numHands // Assign an object of the class to the `handLandmarkerLiveStreamDelegate` // property. let processor = HandLandmarkerResultProcessor() options.handLandmarkerLiveStreamDelegate = processor let handLandmarker = try HandLandmarker(options: options)
Objective-C
Image
@import MediaPipeTasksVision; NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"hand_landmarker" ofType:@"task"]; MPPHandLandmarkerOptions *options = [[MPPHandLandmarkerOptions alloc] init]; options.baseOptions.modelAssetPath = modelPath; options.runningMode = MPPRunningModeImage; options.minHandDetectionConfidence = minHandDetectionConfidence; options.minHandPresenceConfidence = minHandPresenceConfidence; options.minTrackingConfidence = minHandTrackingConfidence; options.numHands = numHands; MPPHandLandmarker *handLandmarker = [[MPPHandLandmarker alloc] initWithOptions:options error:nil];
वीडियो
@import MediaPipeTasksVision; NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"hand_landmarker" ofType:@"task"]; MPPHandLandmarkerOptions *options = [[MPPHandLandmarkerOptions alloc] init]; options.baseOptions.modelAssetPath = modelPath; options.runningMode = MPPRunningModeVideo; options.minHandDetectionConfidence = minHandDetectionConfidence; options.minHandPresenceConfidence = minHandPresenceConfidence; options.minTrackingConfidence = minHandTrackingConfidence; options.numHands = numHands; MPPHandLandmarker *handLandmarker = [[MPPHandLandmarker alloc] initWithOptions:options error:nil];
लाइव स्ट्रीम
@import MediaPipeTasksVision; // Class that conforms to the `MPPHandLandmarkerLiveStreamDelegate` protocol // and implements the method that the hand landmarker calls once it finishes // performing landmarks detection in each input frame. @interface APPHandLandmarkerResultProcessor : NSObject@end @implementation APPHandLandmarkerResultProcessor - (void)handLandmarker:(MPPHandLandmarker *)handLandmarker didFinishDetectionWithResult:(MPPHandLandmarkerResult *)handLandmarkerResult timestampInMilliseconds:(NSInteger)timestampInMilliseconds error:(NSError *)error { // Process the hand landmarker result or errors here. } @end NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"hand_landmarker" ofType:@"task"]; MPPHandLandmarkerOptions *options = [[MPPHandLandmarkerOptions alloc] init]; options.baseOptions.modelAssetPath = modelPath; options.runningMode = MPPRunningModeLiveStream; options.minHandDetectionConfidence = minHandDetectionConfidence; options.minHandPresenceConfidence = minHandPresenceConfidence; options.minTrackingConfidence = minHandTrackingConfidence; options.numHands = numHands; // Assign an object of the class to the `handLandmarkerLiveStreamDelegate` // property. APPHandLandmarkerResultProcessor *processor = [APPHandLandmarkerResultProcessor new]; options.handLandmarkerLiveStreamDelegate = processor; MPPHandLandmarker *handLandmarker = [[MPPHandLandmarker alloc] initWithOptions:options error:nil];
कॉन्फ़िगरेशन विकल्प
इस टास्क में, iOS ऐप्लिकेशन के लिए कॉन्फ़िगरेशन के ये विकल्प शामिल हैं:
विकल्प का नाम | ब्यौरा | वैल्यू रेंज | डिफ़ॉल्ट मान |
---|---|---|---|
running_mode |
टास्क के लिए, रनिंग मोड सेट करता है. इसके तीन मोड होते हैं: इमेज: सिंगल इमेज इनपुट के लिए मोड. वीडियो: वीडियो के डिकोड किए गए फ़्रेम का मोड. LIVE_STREAM: इनपुट डेटा की लाइव स्ट्रीम का मोड, जैसे कि कैमरे से स्ट्रीम किया जाने वाला मोड. इस मोड में, रिज़ल्ट पहचानकर्ता को लिसनर को सेट अप करने के लिए कॉल किया जाना चाहिए, ताकि वह एसिंक्रोनस तरीके से नतीजे पा सके. इस मोड में, handLandmarkerLiveStreamDelegate
को ऐसी क्लास के इंस्टेंस पर सेट किया जाना चाहिए जो हैंड लैंडमार्क
की पहचान करने वाले नतीजों को एसिंक्रोनस तरीके से पाने के लिए, HandLandmarkerLiveStreamDelegate को लागू करता है.
|
{RunningMode.image, RunningMode.video, RunningMode.liveStream } |
RunningMode.image |
numHands |
हैंड लैंडमार्क डिटेक्टर की मदद से, ज़्यादा से ज़्यादा कितने हाथ पहचाने गए हैं. | Any integer > 0 |
1 |
minHandDetectionConfidence |
हाथ की पहचान करने वाली सुविधा के लिए, पाम डिटेक्शन मॉडल में सबसे कम कॉन्फ़िडेंस स्कोर. | 0.0 - 1.0 |
0.5 |
minHandPresenceConfidence |
हैंड लैंडमार्क डिटेक्शन मॉडल में हाथ की मौजूदगी के स्कोर के लिए कम से कम कॉन्फ़िडेंस स्कोर. वीडियो मोड और लाइव स्ट्रीम मोड में, अगर हैंड लैंडमार्क मॉडल के हाथ की मौजूदगी का कॉन्फ़िडेंस स्कोर इस थ्रेशोल्ड से कम है, तो हैंड लैंडमार्कर, हथेली की पहचान करने वाले मॉडल को ट्रिगर करता है. ऐसा न होने पर, लाइटवेट हैंड ट्रैकिंग एल्गोरिदम, लैंडमार्क की बाद में पहचान करने के लिए हाथों की जगह का पता लगाता है. | 0.0 - 1.0 |
0.5 |
minTrackingConfidence |
हैंड ट्रैकिंग के लिए सबसे कम कॉन्फ़िडेंस स्कोर, जिसे कामयाब माना जाएगा. यह मौजूदा फ़्रेम और आखिरी फ़्रेम में मौजूद हाथों के बीच का बाउंडिंग बॉक्स IoU थ्रेशोल्ड है. अगर हैंड लैंडमार्कर के वीडियो मोड और स्ट्रीम मोड में ट्रैकिंग काम नहीं करती है, तो हैंड लैंडमार्कर हाथ की पहचान करने की सुविधा को ट्रिगर कर देता है. ऐसा न होने पर, हाथ की पहचान करने वाली सुविधा को छोड़ दें. | 0.0 - 1.0 |
0.5 |
result_listener |
जब हैंड लैंडमार्कर लाइव स्ट्रीम मोड में होता है, तब नतीजे लिसनर को सेट करता है, ताकि इसे एसिंक्रोनस तरीके से, खोज के नतीजे पाए जा सकें.
सिर्फ़ तब लागू होता है, जब रनिंग मोड को LIVE_STREAM पर सेट किया गया हो |
लागू नहीं | लागू नहीं |
जब रनिंग मोड को लाइव स्ट्रीम के लिए सेट किया जाता है, तब हैंड लैंडमार्कर को अतिरिक्त handLandmarkerLiveStreamDelegate
कॉन्फ़िगरेशन की ज़रूरत होती है. इससे हैंड लैंडमार्कर, लैंडमार्क की पहचान करने वाले नतीजों को एसिंक्रोनस तरीके से डिलीवर कर पाता है. प्रतिनिधि को
handLandmarker(_:didFinishDetection:timestampInMilliseconds:error:)
तरीका लागू करना होगा, जिसे हैंड लैंडमार्कर कॉल करता है. यह तरीका हैंड लैंडमार्क का पता लगाने की सुविधा को प्रोसेस करने के बाद, हर फ़्रेम के लिए मिलने वाले नतीजों को प्रोसेस करता है.
विकल्प का नाम | ब्यौरा | वैल्यू रेंज | डिफ़ॉल्ट मान |
---|---|---|---|
handLandmarkerLiveStreamDelegate |
हैंड लैंडमार्कर की सुविधा चालू करता है, ताकि लाइव स्ट्रीम मोड में एसिंक्रोनस तरीके से हाथ लैंडमार्क की पहचान करने वाले नतीजे पाए जा सकें. जिस क्लास
का इंस्टेंस इस प्रॉपर्टी पर सेट किया गया है उसे
handLandmarker(_: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 डेवलपर दस्तावेज़ देखें.
CVPixelBuffer
CVPixelBuffer
फ़ॉर्मैट, उन ऐप्लिकेशन के लिए बेहद कारगर है जो फ़्रेम जनरेट करते हैं. साथ ही, प्रोसेस करने के लिए iOS CoreImage फ़्रेमवर्क का इस्तेमाल करते हैं.
CVPixelBuffer
फ़ॉर्मैट इन रनिंग मोड के लिए बहुत काम का है:
इमेज: iOS के
CoreImage
फ़्रेमवर्क का इस्तेमाल करके कुछ प्रोसेस के बादCVPixelBuffer
इमेज जनरेट करने वाले ऐप्लिकेशन, इमेज रनिंग मोड में हैंड लैंडमार्कर पर भेजे जा सकते हैं.वीडियो: वीडियो फ़्रेम को प्रोसेस करने के लिए,
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
AVCaptureVideoDataOutput पर, CMSampleBuffer
फ़ॉर्मैट में एसिंक्रोनस तरीके से डिलीवर किए जाते हैं.
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:)
Swift
Image
let result = try handLandmarker.detect(image: image)
वीडियो
let result = try handLandmarker.detect( videoFrame: image, timestampInMilliseconds: timestamp)
लाइव स्ट्रीम
try handLandmarker.detectAsync( image: image, timestampInMilliseconds: timestamp)
Objective-C
Image
MPPHandLandmarkerResult *result = [handLandmarker detectInImage:image error:nil];
वीडियो
MPPHandLandmarkerResult *result = [handLandmarker detectInVideoFrame:image timestampInMilliseconds:timestamp error:nil];
लाइव स्ट्रीम
BOOL success = [handLandmarker detectAsyncInImage:image timestampInMilliseconds:timestamp error:nil];
हैंड लैंडमार्क कोड के उदाहरण में, इनमें से हर मोड को लागू करने के बारे में ज़्यादा जानकारी दी गई है. उदाहरण कोड, उपयोगकर्ता को प्रोसेसिंग मोड के बीच स्विच करने की अनुमति देता है, जो हो सकता है कि आपके इस्तेमाल के उदाहरण के लिए ज़रूरी न हो.
निम्न पर ध्यान दें:
वीडियो मोड या लाइव स्ट्रीम मोड में विज्ञापन चलाते समय, आपको 'हैंड लैंडमार्कर टास्क' को इनपुट फ़्रेम का टाइमस्टैंप भी देना होगा.
इमेज या वीडियो मोड में चलते समय, 'हैंड लैंडमार्कर टास्क' मौजूदा थ्रेड को तब तक ब्लॉक करता है, जब तक कि वह इनपुट इमेज या फ़्रेम की प्रोसेसिंग पूरी नहीं कर लेता. मौजूदा थ्रेड को ब्लॉक करने से बचने के लिए, iOS Dispatch या NSOperation फ़्रेमवर्क का इस्तेमाल करके, बैकग्राउंड में प्रोसेस करें.
लाइव स्ट्रीम मोड में चलते समय, 'हैंड लैंडमार्कर टास्क' तुरंत वापस आ जाता है और मौजूदा थ्रेड को ब्लॉक नहीं करता. यह हर इनपुट फ़्रेम को प्रोसेस करने के बाद, हैंड लैंडमार्कर नतीजे से
handLandmarker(_:didFinishDetection:timestampInMilliseconds:error:)
तरीके को शुरू करता है. हैंड लैंडमार्कर, दिए गए सीरियल डिस्पैच सूची पर इस तरीके को एसिंक्रोनस तरीके से शुरू करता है. यूज़र इंटरफ़ेस पर नतीजे दिखाने के लिए, नतीजों को प्रोसेस करने के बाद, उन्हें मुख्य सूची में भेजें. अगर हैंड लैंडमार्कर टास्क से किसी दूसरे फ़्रेम को प्रोसेस करने में व्यस्त होने परdetectAsync
फ़ंक्शन कॉल किया जाता है, तो हैंड लैंडमार्कर नए इनपुट फ़्रेम को अनदेखा कर देता है.
नतीजे मैनेज करें और दिखाएं
अनुमान लगाने पर, हैंड लैंडमार्क टास्क एक HandLandmarkerResult
दिखाता है जिसमें
इस टास्क के आउटपुट डेटा का एक उदाहरण यहां दिया गया है:
HandLandmarkerResult
आउटपुट में तीन कॉम्पोनेंट होते हैं. हर कॉम्पोनेंट एक कलेक्शन है. इसमें किसी एक हाथ की पहचान करने वाले हर एलिमेंट के लिए ये नतीजे शामिल होते हैं:
हाथ का इस्तेमाल
हाथ का इस्तेमाल यह बताता है कि पहचाने गए हाथ बाएं हाथ हैं या दाएं.
लैंडमार्क
यहां 21 हैंड लैंडमार्क हैं, जिनमें से हर एक में
x
,y
, औरz
निर्देशांक हैं.x
औरy
कोऑर्डिनेट को इमेज की चौड़ाई और ऊंचाई के हिसाब से [0.0, 1.0] नॉर्मलाइज़ किया जाता है.z
निर्देशांक, लैंडमार्क की गहराई दिखाता है. इसमें, कलाई पर मौजूद गहराई का मतलब, शुरुआत की जगह होता है. वैल्यू जितनी छोटी होगी, लैंडमार्क कैमरे के उतना ही करीब होगा.z
की तीव्रताx
के बराबर तीव्रता का इस्तेमाल करती है.विश्व भू-स्थल
दुनिया के निर्देशांकों में भी इन 21 हाथ की मशहूर जगहों को दिखाया गया है. हर लैंडमार्क
x
,y
, औरz
से मिलकर बना है. यह असल दुनिया के 3D निर्देशांक को मीटर में दिखाता है और इन निर्देशांकों को हाथ के ज्यामितीय केंद्र में रखा गया है.
HandLandmarkerResult:
Handedness:
Categories #0:
index : 0
score : 0.98396
categoryName : Left
Landmarks:
Landmark #0:
x : 0.638852
y : 0.671197
z : -3.41E-7
Landmark #1:
x : 0.634599
y : 0.536441
z : -0.06984
... (21 landmarks for a hand)
WorldLandmarks:
Landmark #0:
x : 0.067485
y : 0.031084
z : 0.055223
Landmark #1:
x : 0.063209
y : -0.00382
z : 0.020920
... (21 world landmarks for a hand)
इस इमेज में, टास्क के आउटपुट का विज़ुअलाइज़ेशन दिखाया गया है: