python3中来自tiff文件的暴露时间

时间:2019-03-20 08:03:11

标签: python-3.x metadata python-imaging-library tiff

我想知道是否有办法使用python3从tiff文件获取曝光时间。我知道有一些答案,如何从tiff中获取元数据,但是它们对我没有用。 我尝试过:

import exifread

f = open('file.tif')
tags = exifread.process_file(f)

for tag in tags.keys():
    if tag not in ('JPEGThumbnail', 'TIFFThumbnail', 'Filename', 'EXIF MakerNote'):
        print("Key: {}, value {}".format(tag, tags[tag]))

f.close()

from PIL import Image
from PIL.TiffTags import TAGS

def get_meta(picture):
    with Image.open(picture) as img:
        meta_dict = {TAGS[key] : img.tag[key] for key in img.tag.iterkeys()}

    return meta_dict

from PIL import Image
from PIL.ExifTags import TAGS

def get_exif(fn):
    ret = {}
    i = Image.open(fn)
    info = i._getexif()
    for tag, value in info.items():
        decoded = TAGS.get(tag, tag)
        ret[decoded] = value

    return ret

但这些方法都不起作用...有人知道如何从我的file.tif中获取元数据吗?

感谢和问候!

1 个答案:

答案 0 :(得分:0)

我假设您指的是曝光的持续时间,而不是曝光的日期/时间。恕我直言,该信息不在文件中:

tiffutil -dump Aufnahme-114802-0078.tif 

输出

Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
Directory 0: offset 8 (0x8) next 0 (0)
SubFileType (254) LONG (4) 1<2>
ImageWidth (256) LONG (4) 1<1300>
ImageLength (257) LONG (4) 1<1030>
BitsPerSample (258) SHORT (3) 3<8 8 8>
Compression (259) SHORT (3) 1<1>
Photometric (262) SHORT (3) 1<2>
Model (272) ASCII (2) 10<AxioCamHR\0>
StripOffsets (273) LONG (4) 65<822 63222 125622 188022 250422 312822 375222 437622 500022 562422 624822 687222 749622 812022 874422 936822 999222 1061622 1124022 1186422 1248822 1311222 1373622 1436022 ...>
Orientation (274) SHORT (3) 1<1>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) LONG (4) 1<16>
StripByteCounts (279) LONG (4) 65<62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 62400 ...>
XResolution (282) RATIONAL (5) 1<150>
YResolution (283) RATIONAL (5) 1<150>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
PageNumber (297) SHORT (3) 2<0 0>
DateTime (306) ASCII (2) 20<2019:03:20 11:48:02\0>
HostComputer (316) ASCII (2) 7<BOT160\0>

当然,曝光的日期和时间在那里:

DateTime (306) ASCII (2) 20<2019:03:20 11:48:02\0>

或者:

tiffutil -verboseinfo Aufnahme-114802-0078.tif 

输出

Directory at 0x8
  Subfile Type: multi-page document (2 = 0x2)
  Image Width: 1300 Image Length: 1030
  Resolution: 150, 150
  Resolution Unit: pixels/inch
  Bits/Sample: 8
  Compression Scheme: none
  Photometric Interpretation: RGB color
  Date & Time: "2019:03:20 11:48:02"
  Host Computer: "BOT160"
  Model: "AxioCamHR"
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Rows/Strip: 16
  Number of Strips: 65
  Strips (Offset, ByteCount):
     822, 62400
     63222, 62400
     125622, 62400
     188022, 62400
     250422, 62400
     312822, 62400
     375222, 62400
     437622, 62400
     500022, 62400
     562422, 62400
     624822, 62400
     687222, 62400
     749622, 62400
     812022, 62400
     874422, 62400
     936822, 62400
     999222, 62400
     1061622, 62400
     1124022, 62400
     1186422, 62400
     1248822, 62400
     1311222, 62400
     1373622, 62400
     1436022, 62400
     1498422, 62400
     1560822, 62400
     1623222, 62400
     1685622, 62400
     1748022, 62400
     1810422, 62400
     1872822, 62400
     1935222, 62400
     1997622, 62400
     2060022, 62400
     2122422, 62400
     2184822, 62400
     2247222, 62400
     2309622, 62400
     2372022, 62400
     2434422, 62400
     2496822, 62400
     2559222, 62400
     2621622, 62400
     2684022, 62400
     2746422, 62400
     2808822, 62400
     2871222, 62400
     2933622, 62400
     2996022, 62400
     3058422, 62400
     3120822, 62400
     3183222, 62400
     3245622, 62400
     3308022, 62400
     3370422, 62400
     3432822, 62400
     3495222, 62400
     3557622, 62400
     3620022, 62400
     3682422, 62400
     3744822, 62400
     3807222, 62400
     3869622, 62400
     3932022, 62400
     3994422, 23400
  Planar Configuration: Not planar
  Page Number: 0-0