bat与python脚本联合解析JPG的meta信息

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')

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值