我正在尝试解码一些图片的IrradianceList标签,这是我的代码(注意我只是用它来尝试一些东西)..
import sys
import os
import glob
import exiftool
import base64
import struct
irradiance_list_tag = 'XMP:IrradianceList'
irradiance_calibration_measurement_golden_tag = 'XMP:IrradianceCalibrationMeasurementGolden'
irradiance_calibration_measurement_tag = 'XMP:IrradianceCalibrationMeasurement'
tags = [ irradiance_list_tag, irradiance_calibration_measurement_tag ]
directory = '/home/stagiaire/Bureau/DATA/'
channels = [ 'RED', 'NIR' ]
index = 0
for channel in channels:
files = glob.glob(os.path.join(directory, '*' + channel + '*'))
with exiftool.ExifTool() as et:
metadata = et.get_tags_batch(tags, files)
for file_metadata in metadata:
irradiance_list = file_metadata[irradiance_list_tag]
irradiance_calibration_measurement = file_metadata[irradiance_calibration_measurement_tag]
irradiance_list_bytes = base64.b64decode(irradiance_list)
print(files[index])
index += 1
for irradiance_data in struct.iter_unpack("qHHHHfff", irradiance_list_bytes):
print(irradiance_data)
错误与此类似
irradiance_list = file_metadata[irradiance_list_tag]
这是错误..
KeyError: 'XMP:IrradianceList'
我相信问题在于在Python中安装XMP工具吗?
答案 0 :(得分:0)
"""
Code in Python to decode the IrradianceList tag which is an array of the following structure:
uint64_t timestamp (us)
uint16_t CH0 (count)
uint16_t CH1 (count)
uint16_t gain index
uint16_t integration time (ms)
float yaw
float pitch
float roll
"""
import sys
import os
import glob
import exiftool
import base64
import struct
irradiance_list_tag = 'XMP:IrradianceList'
irradiance_calibration_measurement_golden_tag = 'XMP:IrradianceCalibrationMeasurementGolden'
irradiance_calibration_measurement_tag = 'XMP:IrradianceCalibrationMeasurement'
tags = [ irradiance_list_tag, irradiance_calibration_measurement_tag ]
directory = 'test'
channels = [ 'RED' ]
index = 0
for channel in channels:
files = glob.glob(os.path.join(directory, '*' + channel + '*'))
with exiftool.ExifTool() as et:
metadata = et.get_tags_batch(tags, files)
for file_metadata in metadata:
irradiance_list = file_metadata[irradiance_list_tag]
irradiance_calibration_measurement = file_metadata[irradiance_calibration_measurement_tag]
irradiance_list_bytes = base64.b64decode(irradiance_list)
print(files[index])
index += 1
# for irradiance_data in struct.unpack("qHHHHfff", irradiance_list_bytes):
# print(irradiance_data)
for i in range(0,len(irradiance_list_bytes),28):
print struct.unpack("qHHHHfff",irradiance_list_bytes[i:i+28])