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/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标注格式,包含训练集和验证集、类别json文件以及可视化脚本】 ,数据保存按照文件夹保存,经测试,可直接用作目标检测数据集,无需额外处理。 【数据集介绍】2类别:dog、cat 【数据集详情】data目录下分为两个目录,训练数据和验证数据。训练集共2949张图片和2949个xml解释文件。验证集共737张图片和737个xml解释文件 【json文件】2 类别的json字典文件 为了方便查看数据,提供了可视化py文件,随机传入一张图片即可绘制边界框,并且保存在当前目录。脚本无需更改,可以直接运行得到标注后的图像 关于yolo实战检测教程:https://blog.csdn.net/qq_44886601/category_12281263.html yolov5的改进实战:https://blog.csdn.net/qq_44886601/category_12605353.html
资源推荐
资源详情
资源评论
收起资源包目录
目标检测数据集:猫狗检测【VOC标注格式,包含训练集和验证集、类别json文件以及可视化脚本】 (2000个子文件)
show.py 2KB
Bengal_105.xml 695B
staffordshire_bull_terrier_198.xml 512B
staffordshire_bull_terrier_156.xml 512B
staffordshire_bull_terrier_124.xml 512B
staffordshire_bull_terrier_171.xml 512B
staffordshire_bull_terrier_183.xml 512B
staffordshire_bull_terrier_177.xml 512B
staffordshire_bull_terrier_181.xml 511B
staffordshire_bull_terrier_176.xml 511B
staffordshire_bull_terrier_139.xml 511B
staffordshire_bull_terrier_14.xml 511B
staffordshire_bull_terrier_165.xml 511B
staffordshire_bull_terrier_102.xml 511B
staffordshire_bull_terrier_144.xml 511B
staffordshire_bull_terrier_138.xml 511B
staffordshire_bull_terrier_115.xml 511B
staffordshire_bull_terrier_118.xml 511B
staffordshire_bull_terrier_152.xml 511B
staffordshire_bull_terrier_180.xml 511B
staffordshire_bull_terrier_122.xml 511B
staffordshire_bull_terrier_172.xml 511B
staffordshire_bull_terrier_121.xml 511B
staffordshire_bull_terrier_163.xml 511B
staffordshire_bull_terrier_197.xml 511B
staffordshire_bull_terrier_123.xml 511B
staffordshire_bull_terrier_162.xml 511B
staffordshire_bull_terrier_125.xml 511B
staffordshire_bull_terrier_116.xml 511B
staffordshire_bull_terrier_15.xml 511B
staffordshire_bull_terrier_191.xml 510B
staffordshire_bull_terrier_192.xml 510B
staffordshire_bull_terrier_12.xml 510B
staffordshire_bull_terrier_189.xml 510B
american_pit_bull_terrier_140.xml 510B
staffordshire_bull_terrier_184.xml 510B
american_pit_bull_terrier_172.xml 510B
american_pit_bull_terrier_142.xml 510B
american_pit_bull_terrier_146.xml 510B
american_pit_bull_terrier_116.xml 510B
staffordshire_bull_terrier_109.xml 510B
american_pit_bull_terrier_168.xml 510B
staffordshire_bull_terrier_104.xml 510B
staffordshire_bull_terrier_147.xml 510B
american_pit_bull_terrier_171.xml 510B
staffordshire_bull_terrier_160.xml 510B
american_pit_bull_terrier_138.xml 510B
staffordshire_bull_terrier_105.xml 510B
american_pit_bull_terrier_178.xml 510B
staffordshire_bull_terrier_143.xml 510B
staffordshire_bull_terrier_159.xml 510B
american_pit_bull_terrier_102.xml 510B
american_pit_bull_terrier_151.xml 510B
american_pit_bull_terrier_104.xml 510B
staffordshire_bull_terrier_145.xml 510B
staffordshire_bull_terrier_110.xml 510B
american_pit_bull_terrier_108.xml 510B
american_pit_bull_terrier_188.xml 510B
staffordshire_bull_terrier_131.xml 510B
american_pit_bull_terrier_136.xml 510B
american_pit_bull_terrier_137.xml 510B
american_pit_bull_terrier_174.xml 509B
american_pit_bull_terrier_112.xml 509B
staffordshire_bull_terrier_113.xml 509B
american_pit_bull_terrier_175.xml 509B
american_pit_bull_terrier_127.xml 509B
american_pit_bull_terrier_166.xml 509B
american_pit_bull_terrier_128.xml 509B
american_pit_bull_terrier_164.xml 509B
staffordshire_bull_terrier_13.xml 509B
staffordshire_bull_terrier_18.xml 509B
american_pit_bull_terrier_109.xml 509B
american_pit_bull_terrier_16.xml 509B
american_pit_bull_terrier_14.xml 509B
american_pit_bull_terrier_107.xml 509B
american_pit_bull_terrier_11.xml 509B
american_pit_bull_terrier_160.xml 509B
american_pit_bull_terrier_121.xml 509B
american_pit_bull_terrier_173.xml 509B
staffordshire_bull_terrier_10.xml 509B
american_pit_bull_terrier_114.xml 509B
staffordshire_bull_terrier_186.xml 509B
staffordshire_bull_terrier_195.xml 509B
american_pit_bull_terrier_106.xml 509B
american_pit_bull_terrier_161.xml 509B
american_pit_bull_terrier_170.xml 509B
american_pit_bull_terrier_177.xml 509B
american_pit_bull_terrier_110.xml 509B
american_pit_bull_terrier_120.xml 509B
american_pit_bull_terrier_124.xml 509B
american_pit_bull_terrier_167.xml 509B
american_pit_bull_terrier_184.xml 509B
american_pit_bull_terrier_131.xml 509B
american_pit_bull_terrier_176.xml 509B
staffordshire_bull_terrier_179.xml 509B
american_pit_bull_terrier_144.xml 509B
american_pit_bull_terrier_10.xml 509B
american_pit_bull_terrier_111.xml 509B
american_pit_bull_terrier_157.xml 509B
english_cocker_spaniel_137.xml 508B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
Ai医学图像分割
- 粉丝: 2w+
- 资源: 2128
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 微信自动抢红包APP.zip毕业设计参考学习资料
- 为 Wireshark 能使用纯真网络 IP 数据库(QQwry)而提供的格式转换工具.zip
- 音频格式转换工具.zip学习资料程序资源
- 自用固件,合并openwrt和immortalwrt编译AX6(刷机有风险).zip
- 最新GeoLite2-City.mmdb,GeoLite2-Country.mmdb打包下载
- 基于BootStrap + Springboot + FISCO-BCOS的二手物品交易市场系统.zip
- 使用Java语言编写的九格拼游戏,找寻下曾经小时候的记忆.zip
- gakataka课堂管理系统
- 一个简单ssh(spring springMVC hibernate)游戏网站,在网上找的html模板,没有自己写UI,重点放在java后端上.zip
- 一个采用MVC架构设计、Java实现的泡泡堂游戏.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功