Python EXIF可以';无法找到拍摄日期信息,但在通过windows属性查看时存在
我需要按拍摄日期提取和整理照片。Windows10,Python2.7。我一直在这样做Python EXIF可以';无法找到拍摄日期信息,但在通过windows属性查看时存在,python,python-imaging-library,exif,Python,Python Imaging Library,Exif,我需要按拍摄日期提取和整理照片。Windows10,Python2.7。我一直在这样做 from PIL import Image def get_date_taken(path): return Image.open(path)._getexif()[36867] 以下: 这对一些照片来说非常有用 太好了。现在抓取一组不同的图像,新相机,属性看起来很相似 但格言是完全不同的 Image.open(image)._getexif()[36867] Traceback (most
from PIL import Image
def get_date_taken(path):
return Image.open(path)._getexif()[36867]
以下:
这对一些照片来说非常有用
太好了。现在抓取一组不同的图像,新相机,属性看起来很相似
但格言是完全不同的
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
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不是?还有什么建议可以尝试,我需要担心跨平台吗?问题与此相同:
但是在python中。这个友好的在线元数据查看器
建议两幅图像在exif中都有日期创建标记。还有什么方法可以访问它们
一个有问题的示例图像是我使用Exifrad库完成的。下面是我的python代码片段
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)
使用您的测试文件和exifrad,我得到
'EXIF DateTimeOriginal':(0x9003)ASCII=2012:08:19 16:44:38@368
作为返回的标记之一。py3.5和Exifrad-2.1.2。有趣,相同的Exifrad版本,不同的python版本。将进行测试。您可能应该使用os.path.join
而不是%s/%s
,python的datetime
标准库模块可以为您解析日期。