Android SDK (Kotlin/Java) पर उपयोगकर्ता के एनवायरमेंट को समझना

अपने ऐप्लिकेशन में Scene Semantics API इस्तेमाल करने का तरीका जानें.

सीन सिमैंटिक एपीआई की मदद से डेवलपर, उपयोगकर्ता के आस-पास मौजूद सीन को समझ पाते हैं. इसके लिए, उन्हें मशीन लर्निंग मॉडल पर आधारित रीयल-टाइम सिमैंटिक जानकारी दी जाती है. आउटडोर सीन की इमेज को देखते हुए, एपीआई काम के सिमैंटिक क्लास के सेट में हर पिक्सल के लिए एक लेबल दिखाता है. जैसे, आसमान, इमारत, पेड़, सड़क, फ़ुटपाथ, वाहन, व्यक्ति वगैरह. Pixel लेबल के साथ-साथ, सीन सेमैंटिक एपीआई की मदद से हर पिक्सल लेबल के लिए कॉन्फ़िडेंस वैल्यू की सुविधा मिलती है. साथ ही, इसकी मदद से किसी आउटडोर सीन में दिए गए लेबल के बारे में क्वेरी आसानी से की जा सकती है.

बाईं से दाईं ओर, इनपुट इमेज के उदाहरण, पिक्सल लेबल की सिमैंटिक इमेज, और उससे जुड़ी कॉन्फ़िडेंस इमेज:

इनपुट इमेज, सिमैंटिक इमेज, और सिमैंटिक कॉन्फ़िडेंस इमेज का उदाहरण.

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

पक्का करें कि आपको एआर के बुनियादी सिद्धांतों के बारे में पता हो साथ ही, आगे बढ़ने से पहले ARCore सेशन को कॉन्फ़िगर करने का तरीका जानें.

सीन सिमैंटिक चालू करें

नए ARCore सेशन में, देखें कि उपयोगकर्ता के डिवाइस पर Scroll Semantics API काम करता है या नहीं. प्रोसेसिंग पावर की कमी की वजह से, सभी ARCore के साथ काम करने वाले डिवाइस, सीन सिमैंटिक एपीआई के साथ काम नहीं करते हैं.

संसाधन सेव करने के लिए, ARCore पर सीन सिमैंटिक की सुविधा डिफ़ॉल्ट रूप से बंद रहती है. अपने ऐप्लिकेशन में सीन सिमैंटिक एपीआई का इस्तेमाल करने के लिए, सिमैंटिक मोड चालू करें.

Java

Config config = session.getConfig();

// Check whether the user's device supports the Scene Semantics API.
boolean isSceneSemanticsSupported =
    session.isSemanticModeSupported(Config.SemanticMode.ENABLED);
if (isSceneSemanticsSupported) {
  config.setSemanticMode(Config.SemanticMode.ENABLED);
}
session.configure(config);

Kotlin

val config = session.config

// Check whether the user's device supports the Scene Semantics API.
val isSceneSemanticsSupported = session.isSemanticModeSupported(Config.SemanticMode.ENABLED)
if (isSceneSemanticsSupported) {
  config.semanticMode = Config.SemanticMode.ENABLED
}
session.configure(config)

सिमैंटिक इमेज पाएं

सीन सिमैंटिक की सुविधा चालू होने के बाद, सिमैंटिक इमेज वापस पाई जा सकती है. सिमैंटिक इमेज एक ImageFormat.Y8 इमेज होती है, जिसमें हर पिक्सल SemanticLabel की ओर से तय किए गए सिमैंटिक लेबल से मेल खाता है.

सिमैंटिक इमेज पाने के लिए, Frame.acquireSemanticImage() का इस्तेमाल करें:

Java

// Retrieve the semantic image for the current frame, if available.
try (Image semanticImage = frame.acquireSemanticImage()) {
  // Use the semantic image here.
} catch (NotYetAvailableException e) {
  // No semantic image retrieved for this frame.
  // The output image may be missing for the first couple frames before the model has had a
  // chance to run yet.
}

Kotlin

// Retrieve the semantic image for the current frame, if available.
try {
  frame.acquireSemanticImage().use { semanticImage ->
    // Use the semantic image here.
  }
} catch (e: NotYetAvailableException) {
  // No semantic image retrieved for this frame.
}

डिवाइस के आधार पर, आउटपुट सिमैंटिक इमेज, सेशन की शुरुआत से करीब एक से तीन फ़्रेम के बाद उपलब्ध होनी चाहिए.

कॉन्फ़िडेंस इमेज की वैल्यू पाएं

हर पिक्सल के लिए एक लेबल देने वाली सिमैंटिक इमेज के अलावा, यह एपीआई हर पिक्सल के लिए कॉन्फ़िडेंस वैल्यू की कॉन्फ़िडेंस इमेज भी उपलब्ध कराता है. कॉन्फ़िडेंस इमेज एक ImageFormat.Y8 इमेज होती है. इसमें हर पिक्सल, [0, 255] रेंज की वैल्यू से जुड़ा होता है. यह हर पिक्सल के लिए सिमैंटिक लेबल से जुड़ी प्रॉबबिलिटी से जुड़ा होता है.

सिमैंटिक कॉन्फ़िडेंस इमेज पाने के लिए, Frame.acquireSemanticConfidenceImage() का इस्तेमाल करें:

Java

// Retrieve the semantic confidence image for the current frame, if available.
try (Image semanticImage = frame.acquireSemanticConfidenceImage()) {
  // Use the semantic confidence image here.
} catch (NotYetAvailableException e) {
  // No semantic confidence image retrieved for this frame.
  // The output image may be missing for the first couple frames before the model has had a
  // chance to run yet.
}

Kotlin

// Retrieve the semantic confidence image for the current frame, if available.
try {
  frame.acquireSemanticConfidenceImage().use { semanticConfidenceImage ->
    // Use the semantic confidence image here.
  }
} catch (e: NotYetAvailableException) {
  // No semantic confidence image retrieved for this frame.
}

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

सिमैंटिक लेबल के लिए पिक्सल के अंश की क्वेरी करें

मौजूदा फ़्रेम में पिक्सल के उस अंश के लिए भी क्वेरी की जा सकती है जो किसी खास क्लास से जुड़ी हो, जैसे कि आसमान. यह क्वेरी सिमैंटिक इमेज लौटाने और किसी खास लेबल के लिए पिक्सल के हिसाब से खोज करने से ज़्यादा बेहतर है. दिया गया अंश [0.0, 1.0] श्रेणी में एक फ़्लोट मान है.

किसी दिए गए लेबल का फ़्रैक्शन पाने के लिए, Frame.getSemanticLabelFraction() का इस्तेमाल करें:

Java

// Retrieve the fraction of pixels for the semantic label sky in the current frame.
try {
  float outFraction = frame.getSemanticLabelFraction(SemanticLabel.SKY);
  // Use the semantic label fraction here.
} catch (NotYetAvailableException e) {
  // No fraction of semantic labels was retrieved for this frame.
}

Kotlin

// Retrieve the fraction of pixels for the semantic label sky in the current frame.
try {
  val fraction = frame.getSemanticLabelFraction(SemanticLabel.SKY)
  // Use the semantic label fraction here.
} catch (e: NotYetAvailableException) {
  // No fraction of semantic labels was retrieved for this frame.
}