VisDrone2019-DET数据集的处理

# coding=gbk

import os
import cv2
import time
from xml.dom import minidom

#类别的名称
name_dict = {'0': 'ignored regions', '1': 'pedestrian', '2': 'people',
             '3': 'bicycle', '4': 'car', '5': 'van', '6': 'truck',
             '7': 'tricycle', '8': 'awning-tricycle', '9': 'bus',
             '10': 'motor', '11': 'others'}


def transfer_to_xml(pic, txt, file_name):
    xml_save_path = 'xml'  # 生成的xml文件存储的文件夹
    if not os.path.exists(xml_save_path):
        os.mkdir(xml_save_path)

    img = cv2.imread(pic)
    img_w = img.shape[1]
    img_h = img.shape[0]
    img_d = img.shape[2]
    doc = minidom.Document()

    annotation = doc.createElement("annotation")
    doc.appendChild(annotation)
    folder = doc.createElement('folder')
    folder.appendChild(doc.createTextNode('visdrone'))
    annotation.appendChild(folder)

    filename = doc.createElement('filename')
    filename.appendChild(doc.createTextNode(file_name))
    annotation.appendChild(filename)

    source = doc.createElement('source')
    database = doc.createElement('database')
    database.appendChild(doc.createTextNode("Unknown"))
    source.appendChild(database)

    annotation.appendChild(source)

    size = doc.createElement('size')
    width = doc.createElement('width')
    width.appendChild(doc.createTextNode(str(img_w)))
    size.appendChild(width)
    height = doc.createElement('height')
    height.appendChild(doc.createTextNode(str(img_h)))
    size.appendChild(height)
    depth = doc.createElement('depth')
    depth.appendChild(doc.createTextNode(str(img_d)))
    size.appendChild(depth)
    annotation.appendChild(size)

    segmented = doc.createElement('segmented')
    segmented.appendChild(doc.createTextNode("0"))
    annotation.appendChild(segmented)

    with open(txt, 'r') as f:
        lines = [f.readlines()]
        for line in lines:
            for boxes in line:
                box = boxes.strip('\n')
                box = box.split(',')
                x_min = box[0]
                y_min = box[1]
                x_max = int(box[0]) + int(box[2])
                y_max = int(box[1]) + int(box[3])
                object_name = name_dict[box[5]]
# 选择跳过一类
                if box[5] == '0':
                    continue
                elif box[5] == '11':
                    continue

                object = doc.createElement('object')
                nm = doc.createElement('name')
                nm.appendChild(doc.createTextNode(object_name))
                object.appendChild(nm)
                pose = doc.createElement('pose')
                pose.appendChild(doc.createTextNode("Unspecified"))
                object.appendChild(pose)
                truncated = doc.createElement('truncated')
                truncated.appendChild(doc.createTextNode("1"))
                object.appendChild(truncated)
                difficult = doc.createElement('difficult')
                difficult.appendChild(doc.createTextNode("0"))
                object.appendChild(difficult)
                bndbox = doc.createElement('bndbox')
                xmin = doc.createElement('xmin')
                xmin.appendChild(doc.createTextNode(x_min))
                bndbox.appendChild(xmin)
                ymin = doc.createElement('ymin')
                ymin.appendChild(doc.createTextNode(y_min))
                bndbox.appendChild(ymin)
                xmax = doc.createElement('xmax')
                xmax.appendChild(doc.createTextNode(str(x_max)))
                bndbox.appendChild(xmax)
                ymax = doc.createElement('ymax')
                ymax.appendChild(doc.createTextNode(str(y_max)))
                bndbox.appendChild(ymax)
                object.appendChild(bndbox)
                annotation.appendChild(object)
                with open(os.path.join(xml_save_path, file_name + '.xml'), 'w') as x:
                    x.write(doc.toprettyxml())
                x.close()
    f.close()


if __name__ == '__main__':
    t = time.time()
    print('Transfer .txt to .xml...ing....')
    txt_folder = 'annotations'  # visdrone txt标签文件夹
    txt_file = os.listdir(txt_folder)
    img_folder = 'images'  # visdrone 照片所在文件夹

    for txt in txt_file:
        txt_full_path = os.path.join(txt_folder, txt)
        img_full_path = os.path.join(img_folder, txt.split('.')[0] + '.jpg')

        try:
            transfer_to_xml(img_full_path, txt_full_path, txt.split('.')[0])
        except Exception as e:
            print(e)

    print("Transfer .txt to .XML sucessed. costed: {:.3f}s...".format(time.time() - t))

### 回答1: VisDrone2019-Det数据集是一个用于目标检测数据集,包含来自无人机和地面监控摄像头的视频序列,用于人、车和其他物体的检测和识别。该数据集包含230,000个图像,其中包含827,000个物体实例,这些物体在尺寸、姿态、遮挡和密度方面具有多样性。对于每个图像,数据集都提供了一个XML注释文件和一个JPEG图像文件。 XML注释文件包含了对象的位置、类别、形状和尺寸信息。它由根元素和一系列对象节点组成。根元素包含图像的大小和名称信息,对象节点包含每个检测到的物体的信息。每个对象节点包含一个类别节点和一个边界框节点。类别节点表示该物体的类别,边界框节点描述了该物体在图像中的位置和大小。 JPEG图像文件是以RGB格式保存的,包含所检测到的目标物体的图像信息。它们被存储在单独的文件夹中,文件夹名称对应于注释文件的名称。 VisDrone2019-Det数据集的格式是符合POD(Portable Object Description)规范的,这使得它可以在不同的目标检测框架中使用,并且可以轻松添加和删除对象类别和其他属性。这种数据集格式的好处是提供了标准化的注释格式,使得数据集的使用更加方便和灵活。 ### 回答2: visdrone2019-det数据集格式是一个文本文件,其中包含了所有检测目标的信息。它是通过对无人机拍摄的视频进行标注来生成的。每个文本文件中包含了一张图片中所有检测目标的信息,每个目标的信息由若干行构成,每一行表示一个目标的一个属性。该数据集包括了以下属性: 1. 目标类别:表示该目标所属的类别,如行人、自行车、汽车等。 2. 目标位置:表示目标框的左上角坐标与右下角坐标,分别用x1,y1,x2,y2表示,单位是像素。 3. 目标遮挡度:表示目标被遮挡的程度,范围是0-4,其中0表示完全可见,4表示完全遮挡。 4. 目标检测得分:表示算法检测到该目标的置信度得分。 5. 其他属性:可能还包括目标方向、目标速度等信息。 一般来说,对于一个检测目标,在文本文件中会按照上述顺序依次写入其属性信息。由于visdrone2019-det数据集是基于文本格式存储,因此需要借助特定的算法或工具对其进行解析之后才能进行数据处理和训练模型等操作。 ### 回答3: VisDrone2019-Det数据集是一个目标检测数据集,收集了来自中国不同城市的高空视频图像,共包括6,471张图像和932,235个物体实例。该数据集的格式如下: 1.数据集的文件组织结构 数据集文件夹包含三个子文件夹annotations、images、ImageSets,其中: annotations文件夹包含若干个JSON格式的标注文件,每个标注文件对应一张图像的目标检测标注信息。 images文件夹包含所有的原始图像。 ImageSets文件夹包含若干个txt格式的文件,用于制作训练集、验证集和测试集。 2.标注文件的格式 每个标注文件包含该图像中所有目标的信息,每个目标都包括以下信息: 目标类别:如行人、车辆、非机动车等。 目标边界框:左上角坐标(x_min,y_min)和右下角坐标(x_max,y_max)。 目标难易程度:分为1、2、3三个等级,分别代表难、中、易。 目标可见性:分为1、2、3、4四个等级,表示该目标在图像中的可见度。 3.训练集、验证集和测试集的制作 使用ImageSets文件夹中的txt格式的文件,可以很方便地划分训练集、验证集和测试集。每个文件包含图像的名称,以及该图像被用于训练、验证或测试。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值