提取Insight-MVT_Annotation_Train 数据集标签xml文件中的信息
来源:互联网 发布:linux python27 pyqt5 编辑:程序博客网 时间:2024/05/16 12:30
Insight-MVT_Annotation_Train 数据集标签xml文件中的信息
从xml文件中解析出所要的信息 type height width top left 写成Pascal的txt文本格式
Pascal voc 的信息是left top right bottom
对应TFrecord的 xmin ymin xmax yman
对应 left top top+height left+width
代码:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from xml.dom.minidom import parse
import xml.dom.minidom
from xml.dom.minidom import Document
import os
import matplotlib.image as mpimg
#使用minidom解析器打开XML 文
if __name__=='__main__':
DOMTree = xml.dom.minidom.parse('MVI_20033.xml')
collection = DOMTree.documentElement
path='F:\DETRAC-Train-Annotations-XML\Labels\Labels'
frames = collection.getElementsByTagName("frame")
id=0
for frame in frames:
print("*****MVT*****")
if frame.hasAttribute("num"):
print("num: %s" % frame.getAttribute("num"))
density = frame.getAttribute("density")
ne = frame.getElementsByTagName("target_list")
targets = ne[0].getElementsByTagName("target")
txtname=str(id).zfill(6)
print(txtname)
id=id+1
filepath=os.path.join(path,txtname+'.txt')
f=open(filepath,'w')
for target in targets:
print("id: %s" % target.getAttribute("id"))
box = target.getElementsByTagName("box")
attribute = target.getElementsByTagName("attribute")
type = attribute[0].getAttribute("vehicle_type")
print("type: %s" % type)
left = box[0].getAttribute("left")
top = box[0].getAttribute("top")
width = box[0].getAttribute("width")
height = box[0].getAttribute("height")
xmin = left
ymin = top
xmax = str(round(float(xmin) + float(height), 1))
ymax = str(round(float(ymin) + float(width), 1))
type = 'car'
text = type + ' ' + xmin + ' ' + ymin + ' ' + xmax + ' ' + ymax
print("left: %s" % text)
f.write(text+'\n')
f.close()
- 提取Insight-MVT_Annotation_Train 数据集标签xml文件中的信息
- 提取xml文件中的数据
- Python libtorrent提取种子文件中的信息
- 提取PDF文件中的文本信息
- iOS开发:提取MP3文件中的信息
- 从服务器下载mp3文件,保存到MediaStore,提取数据mp3中的信息
- VOC数据提取自己需要的类生成XML标签
- C#使用正则表达式提取网页中的信息数据
- 02.1#excel中数据中的信息提取(函数)
- 用id3lib提取mp3文件中的图片信息的实例
- 使用pdfbox提取pdf文件中的字符信息
- struts2 02 struts.xml文件中的标签
- 布局xml文件中的include标签
- MyBatis中的xml文件部分标签使用
- xml提取数据
- 查询XML文件中的数据
- 导出短信.xml,提取信息
- 使用python 提取html文件中的特定数据
- 13改变HTML样式
- 解决react vr加载js模型失败的问题
- java ajax实现异步同步请求全面详解
- Android之ViewPager+Fragment实现懒加载
- c++实现工厂方法模式对八大排序的统一管理
- 提取Insight-MVT_Annotation_Train 数据集标签xml文件中的信息
- 希尔排序
- 微信的JS接口安全域名设置+tomcat服务器
- Android版本提示更新下载
- 学习笔记之JavaScript——知识点(4)
- 常见类---Scanner类
- 计算机字符编码详解二
- Codeforces Round #426 (Div. 2)
- 最长公共子序列