【DL】读取VOC下的JPG&XML并显示

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 = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值