资源简介
压缩文件中对的代码UA-DETRAC数据集中的xml进行了转换,转换成标准的voc中xml格式。代码运行无误

代码片段和文件信息
import xml.etree.ElementTree as ET
from xml.dom.minidom import Document
import os
import cv2
import time
def ConvertVOCxml(file_path=““ file_name=““):
tree = ET.parse(file_name)
root = tree.getroot()
# print(root.tag)
num = 0 # 计数
# 读xml操作
frame_lists = []
output_file_name = ““
for child in root:
if (child.tag == “frame“):
# 创建dom文档
doc = Document()
# 创建根节点
annotation = doc.createElement(‘annotation‘)
# 根节点插入dom树
doc.appendChild(annotation)
# print(child.tag child.attrib[“num“])
pic_id = child.attrib[“num“].zfill(5)
# print(pic_id)
output_file_name = root.attrib[“name“] + “__img“ + pic_id + “.xml“
# print(output_file_name)
folder = doc.createElement(“folder“)
folder.appendChild(doc.createTextNode(“VOC2007“))
annotation.appendChild(folder)
filename = doc.createElement(“filename“)
pic_name = “img“ + pic_id + “.jpg“
filename.appendChild(doc.createTextNode(pic_name))
annotation.appendChild(filename)
sizeimage = doc.createElement(“size“)
imagewidth = doc.createElement(“width“)
imageheight = doc.createElement(“height“)
imagedepth = doc.createElement(“depth“)
imagewidth.appendChild(doc.createTextNode(“960“))
imageheight.appendChild(doc.createTextNode(“540“))
imagedepth.appendChild(doc.createTextNode(“3“))
sizeimage.appendChild(imagedepth)
sizeimage.appendChild(imagewidth)
sizeimage.appendChild(imageheight)
annotation.appendChild(sizeimage)
target_list = child.getchildren()[0] # 获取target_list
# print(target_list.tag)
object = None
for target in target_list:
if (target.tag == “target“):
# print(target.tag)
object = doc.createElement(‘object‘)
bndbox = doc.createElement(“bndbox“)
for target_child in target:
if (target_child.tag == “box“):
xmin = doc.createElement(“xmin“)
ymin = doc.createElement(“ymin“)
xmax = doc.createElement(“xmax“)
ymax = doc.createElement(“ymax“)
xmin_value = int(float(target_child.attrib[“left“]))
ymin_value = int(float(target_child.attrib[“top“]))
box_width_value = int(float(target_child.attrib[“width“]))
box_height_value = int(float(target_child.attrib[“height“]))
xmin.appendChild(doc.createTextNode(str(xmin_value)))
ym
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 930 2019-11-08 10:05 voc_data_migrate.py
文件 8732 2019-11-09 11:51 covert.py
- 上一篇:Packet tracer 设计 校园网
- 下一篇:由大断面计算水位流量关系.zip
相关资源
- J2EE 配置文件
-
开源tinyxm
l - 常用编码(UnicodeUTF-8GBK)转换工具
-
图片和xm
l格式互换 -
xm
l多个文件合并(delphi) -
xm
l课件及例题(xm l) -
《xm
l编程原理与实例教程》电子教 -
将数据库的表生成xm
l文件 -
简单的xm
l投票系统 -
notepad++包含xm
l tools等插件 -
Volley获取json和xm
l数据解析显示 -
李刚疯狂xm
l讲义第2版完整源码 -
maven settings.xm
l 直接使用 - Unity3D 实战视频教程 保卫萝卜 2D 游戏
-
Notepad++的xm
l格式化工具xm ltools_2 -
Notepad++的xm
l Tools插件格式化xm l文 -
map/list集合转化成xm
l字符串 xm l字 -
libxm
l2-2.9.4-rc2.tar.gz - antisamy策略文件
- 在线教学系统微信小程序
-
Tinyxm
l库文件 -
优秀xm
l程序设计(学生信息管理) - protobuf-2.4.1.zip
-
svnmaven xm
l Schema等程序员必备.7z -
xm
l基础教程-耿祥义 清华出版社 -
xm
l基础教程 第二版 PDF -
一个xm
l项目源代码 - 订单管理系统SSH框架
-
xm
l基础教程与实验指导课件PPT+源代 -
xm
l基础教程第2版教学课件
评论
共有 条评论