מטא-נתונים של תמונת מצלמה

ב-ARCore אפשר להשתמש ב-ImageMetadata כדי לגשת לערכי מפתח של מטא-נתונים מהתוצאה של צילום התמונה במצלמה. סוגים נפוצים של מטא-נתונים של תמונות מצלמה שאולי תרצו לגשת אליהם: נתוני רוחק מוקד, חותמת זמן של תמונה או נתוני תאורה.

המודול של Camera של Android יכול לתעד 160 פרמטרים או יותר לגבי התמונה בכל פריים, בהתאם ליכולות המכשיר. לרשימה של כל מפתחות המטא-נתונים האפשריים, ראו ImageMetadata.

קבלת הערך של מפתח מטא-נתונים ספציפי

קבלת ערך ספציפי של מפתח מטא-נתונים באמצעות getImageMetadata(), ואם הוא לא זמין, תוכלו להשתמש ב-MetadataNotFoundException. בדוגמה הבאה אפשר לקבל את הערך של מפתח המטא-נתונים SENSOR_EXPOSURE_TIME.

Java

// Obtain the SENSOR_EXPOSURE_TIME metadata value from the frame.
Long getSensorExposureTime(Frame frame) {
  try {
    // Can throw NotYetAvailableException when sensors data is not yet available.
    ImageMetadata metadata = frame.getImageMetadata();

    // Get the exposure time metadata. Throws MetadataNotFoundException if it's not available.
    return metadata.getLong(ImageMetadata.SENSOR_EXPOSURE_TIME);
  } catch (MetadataNotFoundException | NotYetAvailableException exception) {
    return null;
  }
}

Kotlin

// Obtain the SENSOR_EXPOSURE_TIME metadata value from the frame.
fun getSensorExposureTime(frame: Frame): Long? {
  return runCatching {
      // Can throw NotYetAvailableException when sensors data is not yet available.
      val metadata = frame.imageMetadata

      // Get the exposure time metadata. Throws MetadataNotFoundException if it's not available.
      return metadata.getLong(ImageMetadata.SENSOR_EXPOSURE_TIME)
    }
    .getOrNull()
}