1.首先编写bat脚本调用高通工具解析当前目录下所有JPG图片并生成meta文件:
上代码:
文件名:CreateMetaFile.bat
@echo off
echo "analyze JPG to meta file!"
for /r . %%i in (*.jpg) do (
echo %%i
C:\Qualcomm\Chromatix7\7.3.1.18\Simulator\Spectra580\QualcommSpectraSim580.exe -metaparse %%i
)
pause
2.遍历第1步生成的所有meta文件并提取meta XML文件中的关键信息以左对齐的方式写入txt文件中方便拷贝:
上代码:
文件名:MetaFileAnalyzeWriteFileT1.py
#!/usr/bin/python
from xml.dom.minidom import parse
import xml.dom.minidom
import os
path = "."
files = os.listdir(path)
tFile = open("test.txt", "w")
tFile.write(format("CCT", "<20"))
tFile.write(format("LuxIdx", "<20"))
tFile.write(format("GainR", "<20"))
tFile.write(format("GainG", "<20"))
tFile.write(format("GainB", "<20"))
tFile.write('\n')
for file in files:
print(file)
if 0 < file.find("meta.xml"):
dom = xml.dom.minidom.parse(file);
root = dom.documentElement
cct = root.getElementsByTagName('CCT')
cct0 = cct[0];
print(cct0.nodeName + " = " + cct0.firstChild.data)
tFile.write(format(cct0.firstChild.data, "<20"))
lux = root.getElementsByTagName('LuxIdx')
lux0 = lux[0]
print(lux0.nodeName + " = " + lux0.firstChild.data)
tFile.write(format(lux0.firstChild.data, "<20"))
gain_r = root.getElementsByTagName('gain_r')
gain_r0 = gain_r[0]
print(gain_r0.nodeName + " = " + gain_r0.firstChild.data)
tFile.write(format(gain_r0.firstChild.data, "<20"))
gain_g = root.getElementsByTagName('gain_g')
gain_g0 = gain_g[0]
print(gain_g0.nodeName + " = " + gain_g0.firstChild.data)
tFile.write(format(gain_g0.firstChild.data, "<20"))
gain_b = root.getElementsByTagName('gain_b')
gain_b0 = gain_b[0]
print(gain_b0.nodeName + " = " + gain_b0.firstChild.data)
tFile.write(format(gain_b0.firstChild.data, "<20"))
tFile.write('\n')
tFile.close()
3.修改第一步的bat脚本文件,合并1,2两步:
上代码:
文件名:CreateMetaFile.bat
@echo off
echo "analyze JPG to meta file!"
for /r . %%i in (*.jpg) do (
echo %%i
C:\Qualcomm\Chromatix7\7.3.1.18\Simulator\Spectra580\QualcommSpectraSim580.exe -metaparse %%i
)
MetaFileAnalyzeWriteFileT1.py
pause
4.把xml文件中的关键信息写入到Excel表格里:
上代码:
文件名:XmlToExcelTest1.py
#!/usr/bin/python
from xml.dom.minidom import parse
import os
import xlwt
import xml.dom.minidom
path = "."
files = os.listdir(path)
workbook = xlwt.Workbook(encoding = 'utf-8')
worksheet = workbook.add_sheet('XmlToExcel')
worksheet.write(0, 0, label = 'CCT')
worksheet.write(0, 2, label = 'LuxIdx')
worksheet.write(0, 4, label = 'GainR')
worksheet.write(0, 6, label = 'GainG')
worksheet.write(0, 8, label = 'GainB')
line = 0
for file in files:
print(file)
if 0 < file.find("meta.xml"):
dom = xml.dom.minidom.parse(file);
root = dom.documentElement
cct = root.getElementsByTagName('CCT')
cct0 = cct[0];
print(cct0.nodeName + " = " + cct0.firstChild.data)
worksheet.write(line + 1, 0, label = cct0.firstChild.data)
lux = root.getElementsByTagName('LuxIdx')
lux0 = lux[0]
print(lux0.nodeName + " = " + lux0.firstChild.data)
worksheet.write(line + 1, 2, label = lux0.firstChild.data)
gain_r = root.getElementsByTagName('gain_r')
gain_r0 = gain_r[0]
print(gain_r0.nodeName + " = " + gain_r0.firstChild.data)
worksheet.write(line + 1, 4, label = gain_r0.firstChild.data)
gain_g = root.getElementsByTagName('gain_g')
gain_g0 = gain_g[0]
print(gain_g0.nodeName + " = " + gain_g0.firstChild.data)
worksheet.write(line + 1, 6, label = gain_g0.firstChild.data)
gain_b = root.getElementsByTagName('gain_b')
gain_b0 = gain_b[0]
print(gain_b0.nodeName + " = " + gain_b0.firstChild.data)
worksheet.write(line + 1, 8, label = gain_b0.firstChild.data)
line += 1
workbook.save('XmlToExcel.xls')