from lxml import etree
import cv2
# 读取 xml 文件信息,并返回字典形式
def parse_xml_to_dict(xml):
if len(xml) == 0: # 遍历到底层,直接返回 tag对应的信息
return {xml.tag: xml.text}
result = {}
for child in xml:
child_result = parse_xml_to_dict(child) # 递归遍历标签信息
if child.tag != 'object':
result[child.tag] = child_result[child.tag]
else:
if child.tag not in result: # 因为object可能有多个,所以需要放入列表里
result[child.tag] = []
result[child.tag].append(child_result[child.tag])
return {xml.tag: result}
# xml 标注文件的可视化
def xmlShow(img, xml, save=True):
image = cv2.imread(img)
with open(xml, encoding='gb18030', errors='ignore') as fid: # 防止出现非法字符报错
xml_str = fid.read()
xml = etree.fromstring(xml_str)
data = parse_xml_to_dict(xml)["annotation"] # 读取 xml文件信息
ob = [] # 存放目标信息
for i in data['object']: # 提取检测框
name = str(i['name']) # 检测的目标类别
bbox = i['bndbox']
xmin = int(bbox['xmin'])
ymin = int(bbox['ymin'])
xmax = int(bbox['xmax'])
ymax = int(bbox['ymax'])
tmp = [name, xmin, ymin, xmax, ymax] # 单个检测框
ob.append(tmp)
# 绘制检测框
for name, x1, y1, x2, y2 in ob:
cv2.rectangle(image, (x1, y1), (x2, y2), color=(255, 0, 0), thickness=2) # 绘制矩形框
cv2.putText(image, name, (x1, y1 - 10), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
fontScale=0.5, thickness=1, color=(0, 0, 255))
# 保存图像
if save:
cv2.imwrite('result.png', image)
# # 展示图像
# cv2.imshow('test', image)
# cv2.waitKey()
# cv2.destroyAllWindows()
if __name__ == "__main__":
import os
import random
img_path = './data/images/' # 传入图片
image = [os.path.join(img_path, i) for i in os.listdir(img_path)]
r = random.randint(0, len(image) - 1) # 生成随机索引
image_path = image[r]
labels_path = image_path.replace('images', 'labels') # 自动获取对应的 xml 标注文件
labels_path = labels_path.replace('.jpg', '.xml')
xmlShow(img=image_path, xml=labels_path, save=True)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
项目包含:印度马路道路缺陷检测数据(VOC标注格式的xml文件,已经做了训练集和测试集划分),数据保存按照文件夹保存,经测试,可直接用作目标检测数据集,无需额外处理。 图像分辨率为720*720的RGB图片,数据集印度的马路数据集,对道路上的缺陷进行检测 【数据集介绍】路面缺陷图像数据,纵向裂纹、横向裂纹、坑洞、不规则裂缝等等 【数据总大小】400 MB 【数据集详情】data目录下分为两个目录,images为训练数据、labels为标签。共有7706张数据和7706个xml解释性标签文件 【json文件】10类别的json字典文件 为了方便查看数据,提供了可视化py文件,随机传入一张图片即可绘制边界框,并且保存在当前目录。脚本无需更改,可以直接运行!
资源推荐
资源详情
资源评论
收起资源包目录
目标检测数据集:印度马路道路缺陷检测数据(VOC标注格式的xml文件,已经做了训练集和测试集划分) (2000个子文件)
show.py 2KB
India_006433.xml 2KB
India_006977.xml 2KB
India_004028.xml 2KB
India_009226.xml 2KB
India_004701.xml 2KB
India_007766.xml 2KB
India_004256.xml 2KB
India_003013.xml 2KB
India_002404.xml 2KB
India_001038.xml 2KB
India_003365.xml 2KB
India_000043.xml 2KB
India_007998.xml 2KB
India_000914.xml 2KB
India_007749.xml 2KB
India_007637.xml 2KB
India_003741.xml 2KB
India_004208.xml 2KB
India_007974.xml 2KB
India_005219.xml 2KB
India_008639.xml 2KB
India_004959.xml 2KB
India_009434.xml 2KB
India_006524.xml 2KB
India_000862.xml 2KB
India_003284.xml 2KB
India_000652.xml 2KB
India_005245.xml 2KB
India_009817.xml 1KB
India_000963.xml 1KB
India_004003.xml 1KB
India_006768.xml 1KB
India_001251.xml 1KB
India_006967.xml 1KB
India_006401.xml 1KB
India_006699.xml 1KB
India_008183.xml 1KB
India_006767.xml 1KB
India_007000.xml 1KB
India_002646.xml 1KB
India_003975.xml 1KB
India_008576.xml 1KB
India_004066.xml 1KB
India_005022.xml 1KB
India_006627.xml 1KB
India_003512.xml 1KB
India_008772.xml 1KB
India_005496.xml 1KB
India_005882.xml 1KB
India_000855.xml 1KB
India_006239.xml 1KB
India_007915.xml 1KB
India_000517.xml 1KB
India_008620.xml 1KB
India_007713.xml 1KB
India_008224.xml 1KB
India_008105.xml 1KB
India_007785.xml 1KB
India_006212.xml 1KB
India_006640.xml 1KB
India_006114.xml 1KB
India_006197.xml 1KB
India_009433.xml 1KB
India_009177.xml 1KB
India_004449.xml 1KB
India_000586.xml 1KB
India_008927.xml 1KB
India_006238.xml 1KB
India_003359.xml 1KB
India_004880.xml 1KB
India_007034.xml 1KB
India_008704.xml 1KB
India_004920.xml 1KB
India_008420.xml 1KB
India_000665.xml 1KB
India_006295.xml 1KB
India_006293.xml 1KB
India_006187.xml 1KB
India_001181.xml 1KB
India_008209.xml 1KB
India_009612.xml 1KB
India_000092.xml 1KB
India_009317.xml 1KB
India_001295.xml 1KB
India_003886.xml 1KB
India_004914.xml 1KB
India_006498.xml 1KB
India_008128.xml 1KB
India_005016.xml 1KB
India_007514.xml 1KB
India_002503.xml 1KB
India_005519.xml 1KB
India_001779.xml 1KB
India_002608.xml 1KB
India_008703.xml 1KB
India_005717.xml 1KB
India_001266.xml 1KB
India_004343.xml 1KB
India_005472.xml 1KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
听风吹等浪起
- 粉丝: 1w+
- 资源: 1288
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功