Siêu dữ liệu hình ảnh của máy ảnh

ARCore cho phép bạn sử dụng ImageMetadata để truy cập vào các giá trị khoá siêu dữ liệu từ kết quả chụp ảnh trong máy ảnh. Một số loại siêu dữ liệu hình ảnh máy ảnh phổ biến mà bạn có thể muốn truy cập là tiêu cự, dữ liệu dấu thời gian của hình ảnh hoặc thông tin về ánh sáng.

Mô-đun Camera của Android có thể ghi lại 160 thông số trở lên về hình ảnh cho mỗi khung hình đã chụp, tuỳ thuộc vào khả năng của thiết bị. Để biết danh sách tất cả các khoá siêu dữ liệu dùng được, hãy xem ImageMetadata.

Nhận giá trị của một khoá siêu dữ liệu riêng lẻ

Sử dụng getImageMetadata() để lấy giá trị khoá siêu dữ liệu cụ thể và nắm bắt MetadataNotFoundException nếu không có giá trị đó. Ví dụ sau đây minh hoạ cách lấy giá trị khoá siêu dữ liệu 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()
}