博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BITVehicle_Dataset数据集转换
阅读量:3973 次
发布时间:2019-05-24

本文共 4203 字,大约阅读时间需要 14 分钟。

最近需要用到BITVehicle_Dataset数据集但是,他的标注结果是mat形式,在matlab中先将mat格式的标注数据转为voc格式,然后再用python从xml中提取标注框的信息,生成最终的训练数据。BITVehicle_Dataset数据集是{‘Bus’, ‘Truck’, ‘SUV’, ‘Microbus’, ‘Sedan’, ‘Minivan’}这几种车型,这样后面需要用到BITVehicle_Dataset数据集时更加方便。

下面是原博主matlab提取BITVehicle_Dataset标注信息,转成xml的代码。

data=load('./BITVehicle_Dataset/VehicleInfo.mat')cars=data.VehicleInfo;for n=1:length(cars)    n;    car=cars(n);    %%    %每一辆车新建一个xml文件存储车的信息    carName=car.name;    %图片的高度    carHeight=car.height;    %图片的宽度    carWidth=car.width;    %新建xml文件    annotation = com.mathworks.xml.XMLUtils.createDocument('annotation');    annotationRoot = annotation.getDocumentElement;      %定义子节点,xml的存储路径    folder=annotation.createElement('folder');    folder.appendChild(annotation.createTextNode(sprintf('%s','H:\车辆目标检测项目\数据集\BITVehicle_xml')));%这里为xml存放的目录    annotationRoot.appendChild(folder);    %图片的名称,不包含后缀名    jpgName=annotation.createElement('filename');    jpgName.appendChild(annotation.createTextNode(sprintf('%s',carName(1:end-4))));    annotationRoot.appendChild(jpgName);    %source就不添加了    %添加图片的size    jpgSize=annotation.createElement('size');    annotationRoot.appendChild(jpgSize);    %定义size的子节点        %图片宽度        width=annotation.createElement('width');        width.appendChild(annotation.createTextNode(sprintf('%i',carWidth)));        jpgSize.appendChild(width);                %图片高度        height=annotation.createElement('height');        height.appendChild(annotation.createTextNode(sprintf('%i',carHeight)));        jpgSize.appendChild(height);                %图片深度,彩色图片3        depth=annotation.createElement('depth');        depth.appendChild(annotation.createTextNode(sprintf('%i',3)));        jpgSize.appendChild(depth);                segmented=annotation.createElement('segmented');        segmented.appendChild(annotation.createTextNode(sprintf('%i',0)));%表示已经标注过了        annotationRoot.appendChild(segmented);        %接下来是每一辆车的标注信息            %%        carVehicles=car.vehicles;    L=length(carVehicles);    if L>1        carName        L    end    for nn=1:length(carVehicles)        vehicle=carVehicles(nn);        %标注框的最左侧坐标        vLeft=vehicle.left;        %标注框的最上边坐标        vTop=vehicle.top;        %标注框的最右侧坐标        vRight=vehicle.right;        %标注框最下面坐标        vBottom=vehicle.bottom;        %车的类别        vCategory=vehicle.category;        %图片中有多少个标注对象        carNvehicles=car.nVehicles;        %在这里生成每一符图片的txt文件,用于        %%注意一张图片中可能会有多个对象        %%matlab直接生成xml对象???        %将这一辆车的信息注入xml中        object=annotation.createElement('object');        annotationRoot.appendChild(object);        %标注框类别名称        categoryName=annotation.createElement('name');        categoryName.appendChild(annotation.createTextNode(sprintf('%s',vCategory)));        object.appendChild(categoryName);                pose=annotation.createElement('pose');        pose.appendChild(annotation.createTextNode(sprintf('%s','Unspecified')));        object.appendChild(pose);                truncated=annotation.createElement('truncated');        truncated.appendChild(annotation.createTextNode(sprintf('%i',0)));        object.appendChild(truncated);                Difficult=annotation.createElement('Difficult');        Difficult.appendChild(annotation.createTextNode(sprintf('%i',0)));        object.appendChild(Difficult);                bndbox=annotation.createElement('bndbox');        object.appendChild(bndbox);                xmin=annotation.createElement('xmin');        xmin.appendChild(annotation.createTextNode(sprintf('%i',vLeft)));        bndbox.appendChild(xmin);                ymin=annotation.createElement('ymin');        ymin.appendChild(annotation.createTextNode(sprintf('%i',vTop)));        bndbox.appendChild(ymin);                xmax=annotation.createElement('xmax');        xmax.appendChild(annotation.createTextNode(sprintf('%i',vRight)));        bndbox.appendChild(xmax);                ymax=annotation.createElement('ymax');        ymax.appendChild(annotation.createTextNode(sprintf('%i',vBottom)));        bndbox.appendChild(ymax);            end     %存储xml    savePath=['H:\车辆目标检测项目\数据集\BITVehicle_xml\',carName(1:end-3),'xml'];    xmlwrite(savePath,annotation);      end

亲测有效!!!感谢UP主!!!

原文链接:

转载地址:http://mhtki.baihongyu.com/

你可能感兴趣的文章
操作系统:进程/线程同步的方式和…
查看>>
操作系统:进程/线程同步的方式和…
查看>>
Makefile的编写
查看>>
Makefile的编写
查看>>
C语言常用算法
查看>>
Linux设备驱动调试技术 2
查看>>
Linux设备驱动调试技术 3
查看>>
系统处理 IRQ_EINT0 IRQ_EIN…
查看>>
系统处理 IRQ_EINT0 IRQ_EIN…
查看>>
misc_register和register_ch…
查看>>
misc_register和register_ch…
查看>>
misc_register和register_ch…
查看>>
misc_register和register_ch…
查看>>
platform设备添加流程(转载)
查看>>
platform设备添加流程(转载)
查看>>
GCC编译关键字“__attribute_…
查看>>
GCC编译关键字“__attribute_…
查看>>
Linux对I/O端口资源的管理( …
查看>>
Linux对I/O端口资源的管理( …
查看>>
[转载]Linux内核中的platfor…
查看>>