我有 .txt 文件(每个图像一个),其格式如下所示。我不知道如何提取我感兴趣的信息,没有空格。
ExifTool Version Number : 10.20
File Name : R0010023.tiff
Directory : C:/gtag/wf1313
File Size : 46 MB
File Modification Date/Time : 2016:07:07 20:57:38+01:00
File Access Date/Time : 2016:07:07 20:57:38+01:00
File Creation Date/Time : 2016:07:04 21:18:17+01:00
File Permissions : rw-rw-rw-
File Type : TIFF
File Type Extension : tif
MIME Type : image/tiff
Exif Byte Order : Little-endian (Intel, II)
Image Width : 4928
Image Height : 3264
Bits Per Sample : 8 8 8
Compression : PackBits
Photometric Interpretation : RGB
Image Description :
Make : RICOH IMAGING COMPANY, LTD.
Camera Model Name : GR II
Strip Offsets : (Binary data 558 bytes, use -b option to extract)
Orientation : Horizontal (normal)
Samples Per Pixel : 3
Rows Per Strip : 51
Strip Byte Counts : (Binary data 447 bytes, use -b option to extract)
X Resolution : 72
Y Resolution : 72
Planar Configuration : Chunky
Resolution Unit : inches
Software : GR Firmware Ver 01.02
Modify Date : 2016:06:21 13:09:52
XMP Toolkit : Image::ExifTool 10.20
Compressed Bits Per Pixel : 3.2
Flash Fired : False
Flash Function : False
Flash Red Eye Mode : False
Flash Return : No return detection
Interoperability Index : R98 - DCF basic file (sRGB)
Y Cb Cr Positioning : Centered
Y Cb Cr Sub Sampling : YCbCr4:2:0 (2 2)
Copyright :
Exposure Time : 1/1250
F Number : 6.3
ISO : 100
Sensitivity Type : Standard Output Sensitivity
Exif Version : 0230
Date/Time Original : 2016:06:21 13:09:52
Create Date : 2016:06:21 13:09:52
Components Configuration : Y, Cb, Cr, -
Aperture Value : 6.3
Brightness Value : 8.6
Exposure Compensation : 0
Max Aperture Value : 2.8
Metering Mode : Multi-segment
Light Source : Shade
Maker Note Type : Rdc
Firmware Version : 1.02
Recording Format : JPEG
Exposure Program : Manual
Drive Mode : Single-frame
White Balance : Shade
White Balance Fine Tune : 0 0
Focus Mode : Manual
Auto Bracketing : Off
Macro Mode : Off
Flash Mode : Off
Flash Exposure Comp : 0
Manual Flash Output : Full
Full Press Snap : Off
Dynamic Range Expansion : Off
Noise Reduction : Weak
Image Effects : Standard
Vignetting : Off
Toning Effect : Off
Hue Adjust : Off
Focal Length : 18.3 mm
AF Area X Position 1 : 632
AF Area Y Position 1 : 418
AF Area X Position : 2435
AF Area Y Position : 1610
AF Status : In Focus
AF Area Mode : Auto
Sensor Width : 4928
Sensor Height : 3264
Cropped Image Width : 4928
Cropped Image Height : 3264
Wide Adapter : Not Attached
Color Temp Kelvin : 0
Crop Mode 35mm : Off
ND Filter : Off
WB Bracket Shot Number : 0
User Comment :
Flashpix Version : 0100
Color Space : sRGB
Exif Image Width : 4928
Exif Image Height : 3264
Exposure Mode : Manual
Focal Length In 35mm Format : 28 mm
Scene Capture Type : Standard
Contrast : Normal
Saturation : Normal
Sharpness : Normal
Owner Name :
Serial Number : (00000000)14100511
Lens Info : 18.3mm f/2.8
Lens Make : RICOH IMAGING COMPANY, LTD.
Lens Model : GR LENS
GPS Version ID : 2.3.0.0
GPS Latitude Ref : xxxx
GPS Longitude Ref : xxxx
GPS Altitude Ref : Above Sea Level
GPS Time Stamp : 12:09:52
GPS Img Direction Ref : True North
GPS Img Direction : 228.21
GPS Date Stamp : 2016:06:21
GPS Pitch : 0.79
GPS Roll : 0.41
PrintIM Version : 0300
Aperture : 6.3
Flash : Off, Did not fire
GPS Altitude : 91.7 m Above Sea Level
GPS Date/Time : 2016:06:21 12:09:52Z
GPS Latitude : xx deg xx' x.xx" N
GPS Longitude : x deg x' xx.xx" W
GPS Position : xx deg xx' x.xx" N, x deg x' xx.xx" W
Image Size : 4928x3264
Megapixels : 16.1
Scale Factor To 35 mm Equivalent: 1.5
Shutter Speed : 1/1250
Circle Of Confusion : 0.020 mm
Field Of View : 65.5 deg
Focal Length : 18.3 mm (35 mm equivalent: 28.0 mm)
Hyperfocal Distance : 2.71 m
Light Value : 15.6
我有以下代码,
import glob
file_list = glob.glob("*.txt")
for file_ in file_list:
saved_lines = []
sfile = open(file_, "r")
lines = sfile.readlines() #array of all lines
for line in lines:
for text in ['File Name', 'GPS Longitude', 'GPS Latitude', 'GPS Altitude', 'GPS Img Direction', 'GPS Pitch', 'GPS Roll']:
if text in line:
saved_lines.append(line)
parsed = "".join(saved_lines) #reassemble the file
with open("parsed.txt", "a") as ofile: #write your output
ofile.write(parsed)
dict={}
sfile = open("R001.txt", "r")
list = sfile.readlines()
for i in list:
dict[i.split(':')[0]] = ''.join(i.split(':')[1:])
我面临的挑战是我需要将数据格式化为以下格式(以便能够将其导入我想使用的程序中),
"#image latitude longitude altitude yaw pitch roll"
"R001.JPG xx.xxxx x.xxxx xxx.xx 319.9 8.2 -2.1"
"R002.JPG xx.xxxx x.xxxx xxx.xx 319.4 10.1 3.6"
因此,每张图像一行,上面的数据。
如上所述创建字典是一个很好的第一步(我认为)。但是,字典很难调用,因为字典的每个成员在成员名称后都有不同数量的空格。也就是说,文件名-----------------------:...等等。
有没有办法查找成员,不包括空格?我已经尝试了该命令strip()
,但由于:
.