深度学习python之制作VOC数据集中的xml文件(Annotations文件夹内)
来源:互联网 发布:佛山各区签约大数据 编辑:程序博客网 时间:2024/05/06 18:32
深度学习python之制作VOC数据集中的xml文件(Annotations文件夹内)
from lxml.etree import Element, SubElement, tostringfrom xml.dom.minidom import parseStringdef make_xml(xmin_tuple, ymin_tuple, xmax_tuple, ymax_tuple, image_name): node_root = Element('annotation') node_folder = SubElement(node_root, 'folder') node_folder.text = 'VOC' node_filename = SubElement(node_root, 'filename') node_filename.text = image_name + '.jpg' node_object_num = SubElement(node_root, 'object_num') node_object_num.text = str(len(xmin_tuple)) node_size = SubElement(node_root, 'size') node_width = SubElement(node_size, 'width') node_width.text = '512' node_height = SubElement(node_size, 'height') node_height.text = '384' node_depth = SubElement(node_size, 'depth') node_depth.text = '3' for i in xrange(len(xmin_tuple)): node_object = SubElement(node_root, 'object') node_name = SubElement(node_object, 'name') node_name.text = 'ship' node_difficult = SubElement(node_object, 'difficult') node_difficult.text = '0' node_bndbox = SubElement(node_object, 'bndbox') node_xmin = SubElement(node_bndbox, 'xmin') node_xmin.text = str(xmin_tuple[i]) node_ymin = SubElement(node_bndbox, 'ymin') node_ymin.text = str(ymin_tuple[i]) node_xmax = SubElement(node_bndbox, 'xmax') node_xmax.text = str(xmax_tuple[i]) node_ymax = SubElement(node_bndbox, 'ymax') node_ymax.text = str(ymax_tuple[i]) xml = tostring(node_root, pretty_print = True) dom = parseString(xml) #print xml 打印查看结果 return dom
调用格式
dom = make_xml(xmin_tuple, ymin_tuple, xmax_tuple, ymax_tuple, image_name) xml_name = os.path.join(save_xml_path, image_name + '.xml') with open(xml_name, 'w') as f: f.write(dom.toprettyxml(indent='\t', encoding='utf-8'))
其中
image_name 没有扩展名,比如 ‘000001’
xmin_tuple = []
xmin_tuple.append(xmin) # xmin 为坐标值,有多少物体,len(xmin_tuple)就是多少
某一打印结果为:
<annotation> <folder>VOC</folder> <filename>000077.jpg</filename> <object_num>3</object_num> <size> <width>512</width> <height>384</height> <depth>3</depth> </size> <object> <name>ship</name> <difficult>0</difficult> <bndbox> <xmin>20</xmin> <ymin>1</ymin> <xmax>50</xmax> <ymax>67</ymax> </bndbox> </object> <object> <name>ship</name> <difficult>0</difficult> <bndbox> <xmin>1</xmin> <ymin>119</ymin> <xmax>27</xmax> <ymax>201</ymax> </bndbox> </object> <object> <name>ship</name> <difficult>0</difficult> <bndbox> <xmin>290</xmin> <ymin>1</ymin> <xmax>409</xmax> <ymax>365</ymax> </bndbox> </object></annotation>
阅读全文
0 0
- 深度学习python之制作VOC数据集中的xml文件(Annotations文件夹内)
- python 数据转 voc xml
- python 处理pascal voc数据 读取xml文件
- Python生成PASCAL VOC格式的xml标注文件
- Python生成PASCAL VOC格式的xml标注文件
- Python生成PASCAL VOC格式的xml标注文件
- YOLO模型训练自己数据-VOC格式数据集制作-ubuntu c++文件夹内图片批量读取与重命名
- 深度学习数据整理——Python读写xml文件
- VOC数据集制作
- VOC-xml标注文件制作及其交互使用(修改,预览,存储)的MATLAB实现
- 深度学习数据集MNIST ImageNet COCO PASCAL VOC介绍
- 读取INRIA 说明文件 生成 voc xml python 版本
- YOLOv2训练:制作VOC格式的数据集
- Python之学习笔记(内建模块html,xml)
- C++ 读取VOC XML文件
- VOC数据提取自己需要的类生成XML标签
- DPM(voc-release5) Matlab模型文件 Mat转XML
- Faster-rcnn voc数据集制作
- 判断文件是否存在的众多方法
- GreenDao使用错误Cannot update entity without key
- Spring Boot教程二
- JSF+primefaces开发总结
- Java 时间和日期类型的 Hibernate 映射
- 深度学习python之制作VOC数据集中的xml文件(Annotations文件夹内)
- maven 添加自己下载的jar包到本地仓库
- LeetCode第2题
- Docker CE 镜像源站
- Springboot教程三——常用注释
- yolo 搭建安装过程
- 利用Collections将非线程安全的Map转换成线程安全的Map
- RecyclerView 条目点击事件 XRecyclerView刷新加载
- 数据库索引优化