from lxml import etree
import cv2
# https://blog.csdn.net/qq_44886601/article/details/135400117
# 读取 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/train/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文件,已经做了训练集和测试集划分),数据保存按照文件夹保存,经测试,可直接用作目标检测数据集,无需额外处理。 图像分辨率为320-240的RGB图片,包含赛道上常见的交通指示牌和道路信息,用于智能小车的自动驾驶竞赛 【数据集介绍】智能小车竞赛自动驾驶图像数据,9类别:限速标志、红灯、直行线、左转标志等等9类别 【数据总大小】91MB 【数据集详情】data目录下分为两个目录,train为训练数据、test为测试数据,每个目录下各有两个子文件夹。images存放数据图片,labels目录存放标注文件。训练集共2725张jpg图片和2725个xml解释文件。训练集共681张jpg图片和681个xml解释文件 【json文件】9类别的json字典文件 为了方便查看数据,提供了可视化py文件,随机传入一张图片即可绘制边界框,并且保存在当前目录。脚本无需更改,可以直接运行!
资源推荐
资源详情
资源评论
收起资源包目录
目标检测数据集:智能小车竞赛自动驾驶目标检测数据集(VOC标注格式的xml文件,已经做了训练集和测试集划分) (2000个子文件)
show.py 2KB
2434.xml 763B
2753.xml 563B
2585.xml 563B
2675.xml 563B
2699.xml 563B
2455.xml 563B
2748.xml 563B
2790.xml 563B
2551.xml 563B
2763.xml 563B
2829.xml 563B
2661.xml 563B
2515.xml 563B
2405.xml 563B
2701.xml 563B
2538.xml 563B
2866.xml 563B
2618.xml 563B
2769.xml 563B
2510.xml 563B
2810.xml 563B
2453.xml 563B
2722.xml 563B
2422.xml 563B
2418.xml 562B
2588.xml 562B
2789.xml 562B
2735.xml 562B
2826.xml 562B
2819.xml 562B
2400.xml 562B
2524.xml 562B
2525.xml 562B
2731.xml 562B
2484.xml 562B
2496.xml 562B
2407.xml 562B
2846.xml 562B
2733.xml 562B
2526.xml 562B
2542.xml 562B
2546.xml 562B
2688.xml 562B
2764.xml 562B
2860.xml 562B
2759.xml 562B
2512.xml 562B
2439.xml 562B
2873.xml 562B
2507.xml 562B
2552.xml 562B
2658.xml 562B
2466.xml 562B
2817.xml 562B
2568.xml 562B
2628.xml 562B
2867.xml 562B
2721.xml 562B
2651.xml 562B
2644.xml 562B
2707.xml 562B
2698.xml 562B
2471.xml 562B
2853.xml 562B
2440.xml 562B
2650.xml 562B
2715.xml 562B
2519.xml 562B
2787.xml 562B
2520.xml 562B
2467.xml 562B
2495.xml 562B
2665.xml 562B
2555.xml 562B
2775.xml 562B
2604.xml 562B
2827.xml 562B
2862.xml 562B
2771.xml 562B
2530.xml 562B
2499.xml 562B
2438.xml 561B
2669.xml 561B
2924.xml 561B
3360.xml 561B
2572.xml 561B
2952.xml 561B
3138.xml 561B
2802.xml 561B
2558.xml 561B
2834.xml 561B
3166.xml 561B
2910.xml 561B
2773.xml 561B
2534.xml 561B
2667.xml 561B
2564.xml 561B
2554.xml 561B
2900.xml 561B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
听风吹等浪起
- 粉丝: 1w+
- 资源: 1231
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 关于数据分析工具的问题 (Excel、PowerBI-Tableau、R-Python)-教程案例分享.zip
- jqueryUI管理后台+WeiXinApp微信小程序+uni例子内容 参数例子,学习用
- 基于聚类分析分批训练的BP神经网络回归分析
- 计算机大类学生课程实验心得、案例-基于Python 的图像处理实验.zip
- CocosDashboard-v2.1.3-win-042311.exe
- vue3-admin-master-后台管理平台模板.zip
- 基于yolov5和deepsort算法的车辆检测项目源码+数据集(高分项目).zip
- 使用Python的requests库和BeautifulSoup库进行网页爬取的示例案例
- 蓝色个人主页接单HTML源码.zip
- 基于YOLOv5+Deepsort实现车辆行人追踪和计数(完整源码+说明文档+数据).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功