大约6年前的“使用Python从目录中的所有图像获取exif数据”中的原始代码。
# Select the directory which the image files are in
dircont = input()
# Get the list of image files in the directory that exifread supports
directory = os.listdir(dircont)
for files in directory:
if files.endswith ('.JPG'):
file_path = os.path.join(dircont, files)
print (file_path)
#Exifread magic
f = open(file_path, 'rb')
tags = exifread.process_file(f)
for tag in tags.keys():
if tag not in ('JPEGThumbnail', 'TIFFThumbnail', 'Filename', 'EXIF MakerNote'):
print ("Key: %s, value %s" % (tag, tags[tag]))
输出:
C:\Users\evansg\Desktop\PYTEST
Key: Image Make, value RECONYX
Key: Image Model, value HF2 PRO COVERT
Key: Image XResolution, value 72
Key: Image YResolution, value 72
Key: Image ResolutionUnit, value Pixels/Inch
Key: Image DateTime, value 2020:06:17 15:47:17
Key: Image YCbCrPositioning, value Co-sited
Key: Image ExifOffset, value 300
Key: EXIF ExposureTime, value 1/800
Key: EXIF ISOSpeedRatings, value 100
Key: EXIF ExifVersion, value 0220
Key: EXIF DateTimeOriginal, value 2020:06:17 15:47:17
Key: EXIF DateTimeDigitized, value 2020:06:17 15:47:17
Key: EXIF Tag 0x882A, value 0
Key: EXIF ComponentsConfiguration, value YCbCr
Key: EXIF Flash, value Flash did not fire, auto mode
Key: EXIF FlashPixVersion, value 0100
Key: EXIF ColorSpace, value sRGB
Key: EXIF ExifImageWidth, value 2048
Key: EXIF ExifImageLength, value 1440
Key: EXIF ExposureMode, value Auto Exposure
Key: EXIF WhiteBalance, value Manual
Key: EXIF SceneCaptureType, value Standard
但是,我将exif数据添加到图像中。如果我从Exifpro导出,则会得到以下信息: PestMonitoring_PYTEST_20200318_RCNX0005; 18/03/2020 3:31:37 PM; 1/148;-;-;-;-;-;未发射,自动模式;-;-; 100;-; 2048 x 1440; 929 KB; E :\ BTT024 \ 100RECNX \ PestMonitoring_PYTEST_20200318_RCNX0005.jpg; a)人类
但是我需要获取重命名的图像文件(PestMonitoring_PYTEST_20200318_RCNX0005.jpg)和图像'tag'(a)Human)。