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.encode('utf8'))
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文件),数据保存按照文件夹保存,经测试,可直接用作目标检测数据集,无需额外处理。 图像分辨率为300-800的RGB图片,为10类别的海上帆船数据集 【数据集介绍】海上帆船图像数据,类别:fanchuan、person等十个类别 【数据总大小】11 MB 【数据集详情】data目录下分为两个目录。images存放数据图片,labels目录存放标注文件。共932张图像和932个xml标注文件 【json文件】类别的json文件 为了方便查看数据,提供了可视化py文件,随机传入一张图片即可绘制边界框,并且保存在当前目录。脚本无需更改,可以直接运行!
资源推荐
资源详情
资源评论
收起资源包目录
目标检测数据集:海上帆船图像目标检测数据集(VOC标注格式的xml文件) (1867个子文件)
1(3).jpg 95KB
1(2).jpg 77KB
1(784).jpg 36KB
1(742).jpg 35KB
1(263).jpg 33KB
1(725).jpg 33KB
1(576).jpg 30KB
1(400).jpg 28KB
1(514).jpg 26KB
1(951).jpg 26KB
1(953).jpg 24KB
1(667).jpg 24KB
1(952).jpg 24KB
1(1).jpg 23KB
1(794).jpg 21KB
1(80).jpg 20KB
1(881).jpg 20KB
1(509).jpg 19KB
1(200).jpg 19KB
1(411).jpg 19KB
1(61).jpg 19KB
1(452).jpg 19KB
1(122).jpg 18KB
1(770).jpg 18KB
1(791).jpg 18KB
1(95).jpg 18KB
1(340).jpg 17KB
1(315).jpg 17KB
1(306).jpg 17KB
1(611).jpg 17KB
1(808).jpg 17KB
1(74).jpg 17KB
1(835).jpg 17KB
1(53).jpg 17KB
1(247).jpg 17KB
1(385).jpg 17KB
1(465).jpg 17KB
1(597).jpg 17KB
1(799).jpg 16KB
1(441).jpg 16KB
1(277).jpg 16KB
1(395).jpg 16KB
1(262).jpg 16KB
1(735).jpg 16KB
1(845).jpg 16KB
1(833).jpg 16KB
1(729).jpg 16KB
1(347).jpg 16KB
1(201).jpg 16KB
1(205).jpg 16KB
1(877).jpg 16KB
1(197).jpg 16KB
1(439).jpg 15KB
1(191).jpg 15KB
1(15).jpg 15KB
1(673).jpg 15KB
1(901).jpg 15KB
1(223).jpg 15KB
1(790).jpg 15KB
1(21).jpg 15KB
1(822).jpg 15KB
1(697).jpg 15KB
1(628).jpg 15KB
1(537).jpg 15KB
1(302).jpg 15KB
1(864).jpg 15KB
1(745).jpg 15KB
1(579).jpg 15KB
1(766).jpg 15KB
1(9).jpg 15KB
1(941).jpg 15KB
1(647).jpg 15KB
1(473).jpg 15KB
1(496).jpg 15KB
1(506).jpg 15KB
1(440).jpg 15KB
1(803).jpg 15KB
1(642).jpg 15KB
1(782).jpg 15KB
1(216).jpg 15KB
1(812).jpg 15KB
1(756).jpg 15KB
1(188).jpg 15KB
1(761).jpg 14KB
1(158).jpg 14KB
1(535).jpg 14KB
1(425).jpg 14KB
1(106).jpg 14KB
1(810).jpg 14KB
1(738).jpg 14KB
1(776).jpg 14KB
1(199).jpg 14KB
1(743).jpg 14KB
1(177).jpg 14KB
1(613).jpg 14KB
1(48).jpg 14KB
1(252).jpg 14KB
1(396).jpg 14KB
1(884).jpg 14KB
1(26).jpg 14KB
共 1867 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19
资源评论
听风吹等浪起
- 粉丝: 1w+
- 资源: 1357
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (完整)数据库课程设计餐厅点餐说明书-21ab6d3c8beb172ded630b1c59eef8c75ebf952c.doc
- 2023-04-06-项目笔记 - 第一百五十四阶段 - 4.4.2.152全局变量的作用域-152 -2024.06.04
- 松哥解协议松哥解协议松哥解协议松哥解协议松哥解协议
- 618节日618节日618节日
- tensorflow-gpu-2.9.1-cp37-cp37m-win-amd64.whl
- tensorflow-gpu-2.9.0-cp37-cp37m-win-amd64.whl
- tensorflow-gpu-2.9.0-cp39-cp39-win-amd64.whl
- lcd daimalcd daima
- 电影领域-推荐算法-个性化内容-观影决策-电影推荐小程序.zip
- 电气控制PLC考试题库
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功