Python libexi中的EXIF信息

2024-09-28 03:20:25 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

首先我想了解一下:是什么原因造成了这种差异?我认为后一种说法是正确的。在

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

我偶然发现了一个潜在的解决方案,它使用python中的libexif C库,ctypes为noted in this previously answered question-尽管我找不到如何做到这一点的示例。在

非常感谢任何帮助。谢谢!在


Tags: 文件工具标记图像实用程序信息报告jpeg
1条回答
网友
1楼 · 发布于 2024-09-28 03:20:25

如果这有帮助,这里有一些我最近做的黑客设置丢失的镜头/F-Number,。。当我使用手动镜头加上我计算的actaul绝对值EV,以便以后的HDR处理工具(HDR亮度)自动检索。我在下面评论了“写”安全措施。应该是不言自明的。在

top files部分列出了当前文件夹中要处理的文件(这里是所有*.ARW(Sony raw files))。根据需要调整图案和路径。在

#!/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)

相关问题 更多 >

    热门问题