2017-04-14 81 views
0

我想解碼一些圖片的IrradianceList標籤,這裏是我的代碼(它是注意我的,我只是用它來嘗試一些東西)。在Python(Ubuntu)中使用Exiftool和XMPtool爲一些圖片解碼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

>這是我的筆記我只是用它來試一下 是的,這是關鍵。您嘗試播放腳本小子,並讓其他人 完成您的工作,現在當它失敗時,您嘗試在 Stack Overflow上爲您做工作。拿出XMP標準並找出爲什麼它 不起作用。 – mcepl

+0

我不會讓別人做這項工作!我一直在尋找爲Python安裝Exiftool和XMP工具包,我成功地使用了Exiftool,但不是用於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])