VOC2007数据集下载
官方下载地址: https://pjreddie.com/projects/pascal-voc-dataset-mirror/
classes = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
beta v1.0
仅能显示单目标XML
*.jpg *.xml 必须是数字的名字
读取的XML如:
<Annotation>
<filename>1</filename>
<size>
<width>416</width>
<height>416</height>
<depth>3</depth>
</size>
<object>
<name>OKKK</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>83</xmin>
<ymin>71</ymin>
<xmax>95</xmax>
<ymax>396</ymax>
</bndbox>
</object>
</Annotation>
CODE
import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
import cv2
def xyxyFromXML(path):
# "./voc/1.xml"
tree = ET.parse(path)
# 文档根元素
root = tree.getroot()
for element in root.findall('object'):
label = element.find('name').text # 访问Element文本
# print(name)
for xywh in element.findall('bndbox'):
xmin = xywh.find('xmin').text
ymin = xywh.find('ymin').text
xmax = xywh.find('xmax').text
ymax = xywh.find('ymax').text
# print(xmin, ymin, xmax, ymax)
return [xmin, ymin, xmax, ymax], label
def drawImg(img, xyxy):
xmin = int(xyxy[0])
ymin =