TXT文件转Pascal voc数据集XML格式标注文件
TXT的文件格式为 wmin,hmin,wmax,hmax
最终转换出来的效果为
代码:
from xml.dom import minidomimport cv2txt_dirtory=r'F:\9.txt'jpg_dirtory=r'F:\9.jpg'img_name=jpg_dirtory.split('\\')[-1]floder=jpg_dirtory.split('\\')[-2]im = cv2.imread(jpg_dirtory)w = im.shape[1]h = im.shape[0]d = im.shape[2]# print w,h,ddoc = minidom.Document() #创建DOM树对象annotation = doc.createElement('annotation') #创建子节点doc.appendChild(annotation) #annotation作为doc树的子节点folder = doc.createElement('folder') folder.appendChild(doc.createTextNode(floder)) #文本节点作为floder的子节点annotation.appendChild(folder) #folder作为annotation的子节点filename = doc.createElement('filename')filename.appendChild(doc.createTextNode(img_name))annotation.appendChild(filename)filename = doc.createElement('path')filename.appendChild(doc.createTextNode(jpg_dirtory))annotation.appendChild(filename)source = doc.createElement('source')database = doc.createElement('database')database.appendChild(doc.createTextNode("Unknown"))source.appendChild(database)# annotation2 = doc.createElement('annotation')# annotation2.appendChild(doc.createTextNode("ICDAR POD2017"))# source.appendChild(annotation2)# image = doc.createElement('image')# image.appendChild(doc.createTextNode("image"))# source.appendChild(image)# flickrid = doc.createElement('flickrid')# flickrid.appendChild(doc.createTextNode("NULL"))# source.appendChild(flickrid)annotation.appendChild(source)# owner = doc.createElement('owner')# flickrid = doc.createElement('flickrid')# flickrid.appendChild(doc.createTextNode("NULL"))# owner.appendChild(flickrid)# na = doc.createElement('name')# na.appendChild(doc.createTextNode("cxm"))# owner.appendChild(na)# annotation.appendChild(owner)size = doc.createElement('size')width = doc.createElement('width')width.appendChild(doc.createTextNode("%d" % w))size.appendChild(width)height = doc.createElement('height')height.appendChild(doc.createTextNode("%d" % h))size.appendChild(height)depth = doc.createElement('depth')depth.appendChild(doc.createTextNode("%d" % d))size.appendChild(depth)annotation.appendChild(size)segmented = doc.createElement('segmented')segmented.appendChild(doc.createTextNode("0"))annotation.appendChild(segmented)txtLabel = open(txt_dirtory, 'r')boxes = [txtLabel.readline()]for box in boxes:# print(box)box = box.split(' ')# print(box)object = doc.createElement('object')nm = doc.createElement('name')nm.appendChild(doc.createTextNode('0'))object.appendChild(nm)pose = doc.createElement('pose')pose.appendChild(doc.createTextNode("Unspecified"))object.appendChild(pose)truncated = doc.createElement('truncated')truncated.appendChild(doc.createTextNode("1"))object.appendChild(truncated)difficult = doc.createElement('difficult')difficult.appendChild(doc.createTextNode("0"))object.appendChild(difficult)bndbox = doc.createElement('bndbox')xmin = doc.createElement('xmin')xmin.appendChild(doc.createTextNode(box[0]))bndbox.appendChild(xmin)ymin = doc.createElement('ymin')ymin.appendChild(doc.createTextNode(box[1]))bndbox.appendChild(ymin)xmax = doc.createElement('xmax')xmax.appendChild(doc.createTextNode(box[2]))bndbox.appendChild(xmax)ymax = doc.createElement('ymax')ymax.appendChild(doc.createTextNode(box[3]))bndbox.appendChild(ymax)object.appendChild(bndbox)annotation.appendChild(object)savefile = open(r'F:\9.xml', 'w')savefile.write(doc.toprettyxml())savefile.close()
参考内容:
txt版本的标签转换成PASCAL VOC2007 格式的XML标签
Python minidom模块(DOM写入和解析XML)
TXT文件转Pascal voc数据集XML格式标注文件相关推荐
- xml格式标注文件转csv格式
将xml格式的标注文件转为csv格式 方便后续转为tfrecord格式供tensorflow使用 注意,该代码仅使用矩形框标注方法 import os import glob import panda ...
- RCNN系列实验的PASCAL VOC数据集格式设置
我们在做RCNN系列的实验时,往往需要把数据集的格式设置为和PASCAL VOC数据集一样的格式,其实当然也可以修改读取数据的代码,只是这样更为麻烦,自己的数据格式变了又得修改. 首先以VOC200 ...
- PASCAL VOC 数据集的标注格式
PASCAL VOC 数据集的标注格式 PASCAL VOC 挑战赛 ( **The PASCAL Visual Object Classes )是一个世界级的计算机视觉挑战赛. PASCAL的全称是 ...
- VOC数据集 XML 和 txt标注文本的理解
VOC数据集 XML 和 txt标注文本的理解 以VOC数据集中VOC2007中的000001.jpg图片为例,分析下其对应的Annotations文件夹下的000001.xml文件和labels文件 ...
- Ubuntu上用caffe的SSD方法训练Pascal VOC数据集
实验目的 继caffe和ssd搭建完成,demo也演示完毕,了解一些基本知识后,现在开始训练自己的数据集,在给自己的训练集处理之前,先跟着官方的示例将Pascal VOC数据集训练走一遍,把可能会踩坑 ...
- Pascal VOC转COCO格式亲测有效
Pascal VOC转COCO格式亲测有效 Pascal VOC数据集下载 检查VOC数据集并转换为COCO格式 检验COCO格式是否正确 Pascal VOC数据集下载 1.这三个网址就是数据集的下 ...
- Pascal VOC 数据集介绍(tensorflow model zoo)
Pascal VOC 数据集的下载 # 下载2007年的训练数据 wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06- ...
- PASCAL VOC数据集分析(分类部分)
PASCAL VOC数据集分析 PASCAL VOC为图像识别和分类提供了一整套标准化的优秀的数据集,从2005年到2012年每年都会举行一场图像识别challenge. 每一年都有自己的数据集.pa ...
- PASCAL VOC数据集
一.简介 PASCAL: pattern analysis, statistical modelling and computational learning VOC: visual object c ...
最新文章
- 什么才是真正的程序员?
- [Android Pro] linux下查看一个文件的属性(ls,lsattr,file,stat)
- C# web实现word 转Html、office转Html、pdf转图片 在线预览文件
- Codeforces Round #470 (rated, Div. 2 C. Producing Snow(思维)
- python上下键不能用_python退格、方向键无法正常使用解决方法
- java爬虫代码示例_那些让你代码思维和能力有较大的提升Java源码
- saltstack 任务管理和集群(三)
- Spark.2.2源码阅读: SPARK SUBMIT任务提交
- Python多分支实现四则运算器
- Unicode和UTF编码转换
- qpsk调制matlab仿真,QPSK调制解调仿真
- 自适应控制——仿真实验一 用李雅普诺夫稳定性理论设计自适应规律
- 30种已验证有效的WordPress博客网上赚钱方法
- secureCRT免密码登陆Linux
- js 判断 服务器连接状态,原生JS判断网站服务器是否开启问题及解决方案
- Compose for Desktop (Kolin跨平台编写Mac微信应用)
- 爆款“小黄鸭”之后,实在RPA助力电商人双11提销量
- TJA1043 CanTrcv
- MMDet踩坑与使用体会
- 设计模式读书笔记汇总
热门文章
- 文字图片滚动scrollbox插件
- oracle的form开发,Oracle Form开发之调用Form
- 基于php的婚纱影楼管理系统
- 线路板入行必读:PCB电路板小常识
- 译:WebRTC视频通信浅析
- 【独家】同程艺龙作恶记(二):屡教不改或成公司基因,再看更深的买机票套路...
- 偏振器件传输矩阵matlab编程,偏振器件的琼斯矩阵
- 关于租车问题的java视频_Java第二季-答答租车系统(不合理的地方,请大家拍砖)...
- 电脑全盘搜索软件 Everything 强烈推荐
- 周末苦逼码代码,为css3的强大所颤抖了