1

我一直在使用 pyexiv2 从 python 中的 JPEG 文件中读取 exif 信息,并注意到 exiv2 报告的一个标签 - ExposureTime - 与另一个 exif 库 libexif 不同。

我尝试过的任何基于 exiv2 的实用程序都会将曝光时间标签简化为“有理数”,例如 0/1、0 或类似值。基于 libexif 的实用程序(特别是工具“exif”)将报告更详细的“1/-21474836 秒”。对于同一个标签,在同一个图像中。

首先我想了解:什么可以解释这种差异?我假设两者中的后者是正确的。

其次,假设libexif报告的更详细的标签是正确的,我希望能够在Python中获得这个值,据我所知,使用我遇到的任何EXIF工具都是不可能的(例如 pyexiv2)。有没有我没有考虑的工具或方法?

如先前回答的问题中所述,我偶然发现了一种潜在的解决方案,即在python中使用带有ctypes的libexif C库-尽管我找不到如何做到这一点的示例。

任何帮助是极大的赞赏。谢谢!

4

1 回答 1

-1

如果这有帮助,这里有一些我最近做的设置丢失的镜头/F 值,.. 信息,因为我使用手动镜头加上我计算了实际绝对 EV 以供以后的 HDR 处理工具 (HDR Luminace) 自动检索。为了安全起见,我在下面注释掉了“写入”操作。应该是不言自明的。

顶部文件部分列出了当前文件夹中要处理的文件(此处为所有 *.ARW(Sony 原始文件))。根据需要调整图案和路径。

#!/usr/bin/env python
import os
import time
import array
import math

# make file list (take all *.ARW files in current folder)
files = [f for f in os.listdir(".") if f.endswith(".ARW")]
files.sort()   # just to be nice

# have a dict. of tags to work with in particular
tags = {'Aperture':10., 'Exposure Time ':1./1250, 'Shutter Speed':1./1250, 'ISO':200., 'Stops Above Base ISO':0., 'Exposure Compensation':0. }

# arbitrary chosen base EV to get final EV compensation numbers into +/-10 range
EVref = math.log (math.pow(tags['Aperture'],2.0)/tags['Shutter Speed'], 2.0) - 4
print ('EVref=', EVref)

for f in files:
    print (f)
    meta=os.popen("exiftool "+f).readlines()
    for tag in meta:
        set = str(tag).rstrip("\n").split(":")
        for t,x in tags.items():
            if str(set[0]).strip(" ") == t:
                tags[t] = float ( str(os.popen("calc -- "+set[1]).readlines()).strip("[]'~\\t\\n"))
                print (t, tags[t], set[1])

    ev = math.log (math.pow(tags['Aperture'],2.0)/tags['Shutter Speed'], 2.0)
    EV = EVref - ev + tags['Stops Above Base ISO']
    print ('EV=', EV)
#  uncomment/edit to update EXIF in place:
#    os.system('exiftool -ExposureCompensation='+str(EV)+' '+f)
#    os.system('exiftool -FNumber=10 '+f)
#    os.system('exiftool -FocalLength=1000.0 '+f)
#    os.system('exiftool -FocalLengthIn35mmFormat=1000.0 '+f)
于 2017-08-26T20:12:35.643 回答