ARCore ti consente di utilizzare ImageMetadata
per accedere alle coppie chiave-valore dei metadati dal
risultato dell'acquisizione di immagini della fotocamera. Alcuni tipi comuni di metadati dell'immagine della fotocamera a cui potresti voler accedere sono la lunghezza focale, i dati dei timestamp dell'immagine o le informazioni sull'illuminazione.
Il modulo Camera
di Android può registrare 160 o più parametri sull'immagine per ogni frame acquisito, a seconda delle funzionalità del dispositivo. Per un elenco di tutte le possibili chiavi di metadati, consulta ImageMetadata
.
Ottenere il valore di una singola chiave di metadati
Utilizza getImageMetadata()
per ottenere una coppia chiave-valore specifica dei metadati e individua MetadataNotFoundException
se non è disponibile. L'esempio seguente mostra il recupero del valore della chiave dei metadati 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() }