#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 文件名:txt_to_xml.pyfrom xml.dom.minidom import Document
import os
import relist = os.listdir("Annotations")
os.chdir('Annotations')#os.system('pause')#raw_input(unicode('按回车键退出...','utf-8').encode('gbk'))for oldfilename in list:if str(".txt") not in oldfilename:continueprint oldfilename#raw_input(unicode('按回车键退出...','utf-8').encode('gbk'))fileindex = re.findall('\d+', oldfilename)print fileindex#raw_input(unicode('按回车键退出...','utf-8').encode('gbk'))print str(int(fileindex[0]))#raw_input(unicode('按回车键退出...','utf-8').encode('gbk'))newfilename = "00" + str(int(fileindex[0])) + ".xml"#print newfilename#raw_input(unicode('按回车键退出...','utf-8').encode('gbk'))f = open(oldfilename, "r")print 'processing:' + f.namedoc = Document()annotation = doc.createElement('annotation')doc.appendChild(annotation)folder = doc.createElement('folder')folder.appendChild(doc.createTextNode('VOC2007'))annotation.appendChild(folder)filename = doc.createElement('filename')filename.appendChild(doc.createTextNode("00" + str(int(fileindex[0])) + ".jpg"))annotation.appendChild(filename)source = doc.createElement('source')annotation.appendChild(source)database = doc.createElement('database')database.appendChild(doc.createTextNode('PASperson Database'))source.appendChild(database)annotation1 = doc.createElement('annotation')annotation1.appendChild(doc.createTextNode('PASperson'))source.appendChild(annotation1)fr = f.readlines()  # 调用文件的 readline()方法一次读取for line in fr:if str(line).__contains__("size"):sizes = []sizes = re.findall('\d+', line)size = doc.createElement('size')annotation.appendChild(size)width = doc.createElement('width')width.appendChild(doc.createTextNode(sizes[0]))size.appendChild(width)height = doc.createElement('height')height.appendChild(doc.createTextNode(sizes[1]))size.appendChild(height)depth = doc.createElement('depth')depth.appendChild(doc.createTextNode(sizes[2]))size.appendChild(depth)segmented = doc.createElement('segmented')segmented.appendChild(doc.createTextNode('0'))annotation.appendChild(segmented)if (str(line).__contains__('Objects')):nums = re.findall('\d+', line)breakfor index in range(1, int(nums[0])+1):for line in fr:if str(line).__contains__("Bounding box for object " + str(index)):coordinate = re.findall('\d+', line)object = doc.createElement('object')annotation.appendChild(object)name = doc.createElement('name')name.appendChild(doc.createTextNode('person'))object.appendChild(name)pose = doc.createElement('pose')pose.appendChild(doc.createTextNode('Unspecified'))object.appendChild(pose)truncated = doc.createElement('truncated')truncated.appendChild(doc.createTextNode('0'))object.appendChild(truncated)difficult = doc.createElement('difficult')difficult.appendChild(doc.createTextNode('0'))object.appendChild(difficult)bndbox = doc.createElement('bndbox')object.appendChild(bndbox)#数字中包含序号,下标应从1开始xmin = doc.createElement('xmin')xmin.appendChild(doc.createTextNode(coordinate[1]))bndbox.appendChild(xmin)ymin = doc.createElement('ymin')ymin.appendChild(doc.createTextNode(coordinate[2]))bndbox.appendChild(ymin)xmax = doc.createElement('xmax')xmax.appendChild(doc.createTextNode(coordinate[3]))bndbox.appendChild(xmax)ymax = doc.createElement('ymax')ymax.appendChild(doc.createTextNode(coordinate[4]))bndbox.appendChild(ymax)f.close()f = open(newfilename, 'w')f.write(doc.toprettyxml(indent=""))f.close()print str(fileindex) + " compelete"print 'process compelete'

读取INRIA 说明文件 生成 voc xml python 版本相关推荐

  1. python读xml文件生成头文件_python如何读取生成voc xml格式标注信息

    python生成voc xml文件 from lxml import etree class GEN_Annotations: def __init__(self, filename): self.r ...

  2. Py自动化办公—Word文档替换、Excel表格读取、Pdf文件生成和Email自动邮件发送实战案例...

    点击上方"Python爬虫与数据挖掘",进行关注 回复"书籍"即可获赠Python从入门到进阶共10本电子书 今 日 鸡 汤 平阳歌舞新承宠,帘外春寒赐锦袍. ...

  3. 利用poi读取word模板文件生成新的word文档

    利用poi读取word模板文件生成新的word文档 利用poi读取word模板文件,并回填逻辑数据,生成并导出需要的word文档源码.解决模板读取异常问题,提供wordUtils工具类(各种功能实现) ...

  4. java word模板poi生成文件_利用poi读取word模板文件生成新的word文档

    利用poi读取word模板文件生成新的word文档 利用poi读取word模板文件,并回填逻辑数据,生成并导出需要的word文档源码.解决模板读取异常问题,提供wordUtils工具类(各种功能实现) ...

  5. python读取多个文件夹_在python中如何从不同的文件夹读取多个文件

    我在不同的文件夹中有年度数据文件.每个文件包含从1月1日到12月31日的每日数据.数据文件名类似于AS060419.67,其中最后四位代表年份,即1967年,0604是文件夹名.在 我试图使用下面的代 ...

  6. linux将所有文件生成lst_10行Python代码自动清理电脑内重复文件,解放双手!

    作者:陈熹 来源:早起Python 大家好,又到了Python办公自动化系列. 今天分享一个系统层面的自动化案例: 「给定一个文件夹,使用Python检查给定文件夹下有无文件重复,若存在重复则删除」 ...

  7. 使用python读取txt坐标文件生成挖空矿山_探矿批量

    # -*-coding:utf-8-*- import arcpy import fileinput import os # 探矿权坐标格式举例 # 111.0846,31.1530 # 111.10 ...

  8. python读取坐标文本文件_使用python读取txt坐标文件生成挖空矿山_探矿批量

    # -*-coding:utf-8-*- import arcpy import fileinput import os # 探矿权坐标格式举例 # 111.0846,31.1530 # 111.10 ...

  9. python 读取sqlite存入文件_如何通过python读取sqlite数据文件

    sqlite简介:sqlite是一个进程内的库,实现了自给自足的.无服务器的.零配置的.事务性的 SQL 数据库引擎.它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它(如安卓系统),它占 ...

最新文章

  1. PHP文件打包类和实例
  2. DL:深度学习算法(神经网络模型集合)概览之《THE NEURAL NETWORK ZOO》的中文解释和感悟(二)
  3. Spark记录-Scala记录(基础程序例子)
  4. 等额本息excel模板下载_格格技能——巧用EXCEL函数,算清各种收益利率
  5. 如何浅显得理解风控模型中的特征筛选|附实操细节(全)
  6. bookstore项目学到的对象
  7. php中is_writable函数
  8. 参观云栖小镇体会_40个绝美小镇
  9. 最全的微信小程序源代码
  10. 交互式电子杂志_快速的创建交互式演示和翻转电子书工具-XFlip Enterprise(电子杂志相册制作器) V2.0.5.0 中文版 - 未来软件园...
  11. 一分钟了解“Matlab画三维空间中的点plot3”
  12. http 503 service
  13. Halcon椭圆测量
  14. keil5 c语言函数库,C语言中KeilC51库函数大全.doc
  15. 在Dreamweaver 中应用模板
  16. android app连接打印机程序,Android App新增打印机支持 手机打印就是爽
  17. oracle mysql 卸载_Oracle完全卸载详解
  18. 白嫖 IObit 系列软件例如 IObit Uninstaller
  19. Revit二次开发——Ribbon菜单的创建以及各种不同的button(按钮)的代码总结
  20. matlab 神经元系统,应用Matlab设计人工神经元网络控制系统

热门文章

  1. [渝粤教育] 西南科技大学 信息法律法规 在线考试复习资料2021版(1)
  2. Prototype(1.5 rc2)使用指南
  3. C语言实现二进制与十进制的互转(带小数)
  4. js对当前表格各列数据的求和
  5. there's not enought memory to perform the requrested operation.解决方法
  6. 修改视频文件“ 日期”(不是创建日期、修改日期、访问日期)
  7. 磁共振t1t2信号记忆顺口溜_10分钟记住脑出血核磁表现:T1、T2篇
  8. 关于Lazyload加载图片几种方法的介绍
  9. VMware虚拟化客户机安装vmtools软件提示需要安装补丁KB2919335
  10. 韩国中央大学计算机专业,2020年韩国中央大学专业设置