Python EXIF无法找到日期信息,但在通过Windows属性查看器时存在 [英] Python EXIF can't find date taken information, but exists when viewer through windows properties

查看:320
本文介绍了Python EXIF无法找到日期信息,但在通过Windows属性查看器时存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要按拍摄日期提取和整理照片. Windows 10,Python 2.7.我一直在做

I need to extract and organize photos by date taken. Windows 10, Python 2.7. I had been doing this

from PIL import Image
def get_date_taken(path):
    return Image.open(path)._getexif()[36867]

以下:

获取日期和使用PIL从EXIF数据拍摄照片的时间

对于某些照片来说效果很好.

and that works great for some photos.

太好了.现在,在获取另一组图像(新相机)后,属性看起来相似.

Great. Now grabbing a different set of images, new camera, the properties look similar.

但是字典完全不同

Image.open(image)._getexif()[36867]
Traceback (most recent call last):
  Debug Probe, prompt 369, line 1
KeyError: 36867
Image.open(image)._getexif()
{36864: '0220', 37121: '\x01\x02\x03\x00', 40962: 2048, 40963: 1536, 40960: '0100', 40961: 1, 296: 2, 34665: 90, 34855: 1600, 531: 2, 282: (72, 1), 283: (72, 1), 37500: '\x01\xf1\x03\x00\x03\x00\x00\x00\x11 ....

我也尝试过exifread

I tried exifread too

a=exifread.process_file(open(image,'rb'))
a.keys()
['EXIF MakerNote', 'Image ExifOffset', 'EXIF ExposureTime', 'EXIF ComponentsConfiguration', 'Image YCbCrPositioning', 'Image XResolution', 'EXIF FlashPixVersion', 'EXIF ISOSpeedRatings', 'Image YResolution', 'EXIF ColorSpace', 'EXIF ExifImageLength', 'EXIF ExifVersion', 'Image ResolutionUnit', 'EXIF ExifImageWidth']

但没有日期. Windows在读什么不是python的东西?关于其他尝试的任何建议,我是否需要担心跨平台?与此处相同的问题:

but no date taken. What is windows reading that python isn't? Any suggestions on what else to try, do I need to worry cross platform? Same question as here:

" ;日期:在Windows资源管理器中的文件详细信息(文件属性)中显示时,没有出现在Image PropertyItems中

但在python中.这个友好的在线元数据查看器

but in python. This friendly online metadata viewer

http://exif.regex.info/exif.cgi

建议两个图像在exif中都有创建日期的标签.还有什么办法访问它们?

suggests both images have date created tags in exif. How else to access them?

有问题的示例图片是此处

推荐答案

我是使用exifread库完成的.这是我的python代码的片段.

I did it using the exifread library. Here is a snippet of my python code.

import exifread
for filename in os.listdir(directoryInput):
    if filename.endswith('.JPG'):
        with open("%s/%s" % (directoryInput, filename), 'rb') as image: # file path and name
            exif = exifread.process_file(image)
            dt = str(exif['EXIF DateTimeOriginal'])  # might be different
            # segment string dt into date and time
            day, dtime = dt.split(" ", 1)
            # segment time into hour, minute, second
            hour, minute, second = dtime.split(":", 2)

这篇关于Python EXIF无法找到日期信息,但在通过Windows属性查看器时存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆