我使用pyexifinfo
库从图片中提取标题信息。我得到的代码如下:
import pyexifinfo as Z
import json
f = open('header_infdo.txt','w')
data = p.get_json("img.jpg")
formatted_data =(( json.dumps(data, sort_keys=True,indent=4, separators=(',', ':')) ))
print(formatted_data)
s = str(formatted_data)
f.write(s)
f.close
我已将print
函数放入验证我正在提取数据(成功发生),但是当我打开文件时它是空的。
提取的数据如下:
[
{
"Composite:ImageSize":"4096x2304",
"Composite:Megapixels":9.4,
"ExifTool:ExifToolVersion":10.1,
"File:BitsPerSample":8,
"File:ColorComponents":3,
"File:Comment":"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<image time=\"15:27:56.763207\" date=\"2016.02.03\" acq_index=\"3692\">\n\t<acquisition>\n\t\t<exposure>10000</exposure>\n\t\t<sensor_digital_gain>4</sensor_digital_gain>\n\t\t<aperture>4</aperture>\n\t\t<focus>68</focus>\n\t\t<digital_gain>1</digital_gain>\n\t\t<name>Photo_pose</name>\n\t\t<camera_session_name>EXI-55-retest-3</camera_session_name>\n\t</acquisition>\n\t<errors>\n\t\t<error>\n\t\t\t<name>ntp_status_check</name>\n\t\t\t<subsystem>NTP</subsystem>\n\t\t\t<message>NTP is not synced or offset is too long</message>\n\t\t\t<extra>Offset: 0ms threshold: 5msWhen: 0ms threshold: 5ms</extra>\n\t\t\t<timestamp>2016-Feb-03 15:27:47.830965</timestamp>\n\t\t\t<alert>false</alert>\n\t\t\t<clearable>false</clearable>\n\t\t</error>\n\t</errors>\n</image>\n",
"File:Directory":"C:/Users/richie/Desktop/work",
"File:EncodingProcess":"Baseline DCT, Huffman coding",
"File:FileAccessDate":"2016:02:10 18:31:14+00:00",
"File:FileCreateDate":"2016:02:10 18:31:14+00:00",
"File:FileModifyDate":"2016:02:08 18:42:47+00:00",
"File:FileName":"img.jpg",
"File:FilePermissions":"rw-rw-rw-",
"File:FileSize":"1422 kB",
"File:FileType":"JPEG",
"File:FileTypeExtension":"jpg",
"File:ImageHeight":2304,
"File:ImageWidth":4096,
"File:MIMEType":"image/jpeg",
"File:YCbCrSubSampling":"YCbCr4:2:0 (2 2)",
"JFIF:JFIFVersion":1.02,
"JFIF:ResolutionUnit":"None",
"JFIF:XResolution":1,
"JFIF:YResolution":1,
"SourceFile":"C:/Users/richie/Desktop/work/img.jpg"
非常感谢任何帮助。
答案 0 :(得分:0)
I need to stop answering my own questions :)
include the parentheses in rownum = 1