zip*_*per 4 python metadata photo libraw
我正在编写 python 脚本,我需要从原始照片文件(例如 .CR2)中获取 exif 信息。
我发现 Python Rawkit提供了这样做的能力。
with Raw(filename=image_path) as raw:
print raw.metadata
Metadata(aperture=-1.2095638073643314e+38, timestamp=4273602232L,
shutter=-1.1962713245823862e+38, flash=True,
focal_length=-1.2228562901462766e+38, height=3753,
iso=-1.182978841800441e+38,
make='Canon', model='EOS 5D Mark II',
orientation=0, width=5634)
Run Code Online (Sandbox Code Playgroud)
但我有点困惑,如何读取这些值?。例如,我期待像100/200/400这样的iso值,但什么是-1.182978841800441e+38?
我的问题不是针对iso的,也针对快门、光圈……
我检查了libraw和 rawkit doc,但无法找到如何读取/转换这种值。
文档中的这部分不是很详细:
float iso_speed;
ISO sensitivity.
float shutter;
Shutter speed.
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我理解如何阅读这些值吗?
谢谢
[更新]
正如neo所建议的,我将使用ExifRead。事实上,这是一个更好的选择,我正在编写一个 python 脚本。使用 ExifRead 不需要额外的 C 库依赖项。
我能够打开佳能原始文件并解析 Exif,但不幸的是遇到了错误的光圈值:
EXIF ApertureValue (Ratio): 3
# My photo was taken in 2.8 (maybe a rounded value on this flag ?)
Run Code Online (Sandbox Code Playgroud)
快速回答:使用 Fnumber 标志
EXIF FNumber (Ratio): 14/5
14/5 is in fact 2.8 (do the math)
Run Code Online (Sandbox Code Playgroud)
长答案(我是如何发现/调试的):
阅读此 exelent 链接了解佳能 RAW.CR2文件中存储的内容、方式和原因(http://lclevy.free.fr/cr2/)我决定自己解码并了解发生了什么。
这个链接让我在 graal 上解码一个原始文件cr2_poster.pdf 从中我认为最好的值似乎是在我的佳能特定的 MakerNote 部分中的 FNumber 值。(所有值描述都在这里canon_tags)
Tag Id : 3 (In fact 0x0003 that you write 0x3)
Name : FNumber
Run Code Online (Sandbox Code Playgroud)
我用 Hexa 编辑器 (hexedit) 打开了我的文件……我完全迷路了。
关键事项:
C8 05在文件中应该被读取05C8。偏移量示例,地址为0x5C8有了这个发现 MakeNote 部分很容易。
快速的方法是直接搜索0x927c MarkerNote(在文件中7C 92)包含 MakerNote 部分地址的标志。如果您无法找到,请浏览该IFD部分以找到EXIF subsection. 然后在该小节中,您将找到 MakerNote 部分
Tag Type Count Value
7C 92 07 00 B8 A0 00 00 84 03 00 00
Run Code Online (Sandbox Code Playgroud)
偏移量:84 03 00 00-> 00 00 03 84(0x384地址)
转到此地址并在 MakerNote 部分中搜索 FNumber 0x3
Tag Type Count Value
03 00 03 00 04 00 00 00 C8 05 00 00
Run Code Online (Sandbox Code Playgroud)
转到偏移量0x5C8以找到我们的值(计数 4 x 类型 3 ushort,16 位)
0x0x5C8 : 00 00 00 00 00 00 00 00
Run Code Online (Sandbox Code Playgroud)
而且……失败了,事实上我的经典没有填写这个部分。
阅读http://www.exiv2.org/tags.html FNumber 可以在 EXIF 小节中找到。
做同样的过程找到EXIF小节和标签“ 0x829d Exif.Image.FNumbertype 5 Rational” Rational类型由64位(分子和分母ulongs)组成Rational_data_type
Tag Type Count Value
9D 82 05 00 01 00 00 00 34 03 00 00
Run Code Online (Sandbox Code Playgroud)
然后读取0x334偏移量
1C 00 00 00 0A 00 00 00
Run Code Online (Sandbox Code Playgroud)
正如我们在六阅读:0x1C/0XA
十进制,做数学题:28/10= 14/5=2.8
验证我在 ExifRead 中有这个值
EXIF.py 100EOS5D/IMG_8813.CR2 -vv | grep -i 14/5
EXIF FNumber (Ratio): 14/5
Run Code Online (Sandbox Code Playgroud)
瞧!
我正在寻找2.8浮点数,该值以分数格式存储。所以图书馆不做数学运算,只是简化了分数。
这就是为什么我们有14/5而不是2.8预期的。