文章目录

  • .mat后缀文件 转化为 .xml后缀文件
    • 使用工具
    • 代码如下

.mat后缀文件 转化为 .xml后缀文件

针对BIT-vehicle数据集建立的转化程序,根据数据集给出的标签.mat转为训练需要的.xml文件

使用工具

MATLAB R2019a

代码如下

.mat文件移动到同目录下

data=load('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','D:\matlab\bin\Document\vehicle\')));%这里为xml存放的目录annotationRoot.appendChild(folder);%图片的名称,包含后缀名                                           把-4删掉显示,jpgjpgName=annotation.createElement('filename');jpgName.appendChild(annotation.createTextNode(sprintf('%s',carName(1:end))));annotationRoot.appendChild(jpgName);%source就不添加了%添加图片的sizejpgSize=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);%图片深度,彩色图片3depth=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>1carNameLendfor 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%存储xmlsavePath=['D:\matlab\bin\Document\vehicle\',carName(1:end-3),'xml'];xmlwrite(savePath,annotation);
end

【文件类型转换】.mat后缀文件 转化为 .xml后缀文件相关推荐

  1. EXCEL表格转化为XML格式文件

    EXCEL表格转化为XML格式文件 这里给出一个例子: 将get_1.csv文件转化为xml格式文件. 同时将里面的正文部分用jieba进行切词,使得正文每一个词都带有id和词性: from xml. ...

  2. python写xml文件 数据量特别大_python处理xml大文件[xml.sax]

    博客已迁移, 新地址 ===================== 今天遇到大文件处理,使用dom占用资源太多,改用sax处理 dom和sax区别可以自己google下 需求:读取xml数据文件,文件较 ...

  3. 利用TinyXML读取VOC2012数据集的XML标注文件裁剪出所有人体目标保存为文件

    转载自:利用TinyXML读取VOC2012数据集的XML标注文件裁剪出所有人体目标保存为文件 - Why So Serious? - 博客频道 - CSDN.NET  http://blog.csd ...

  4. android XMl 解析神奇xstream 六: 把集合list 转化为 XML文档

    前言:对xstream不理解的请看: android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 android XMl 解析神奇xs ...

  5. 后缀为labels的文件_txt标注文档转换为labelmg VOC格式的xml标注文件

    清理库存8~ #! /usr/bin/python # -*- coding:UTF-8 -*- import os, sys import glob from PIL import Image ## ...

  6. 将.ai文件矢量图转化为.xml文件并在Android项目中使用

    写在前面的话 笔者最近在做一个安卓的小项目,在开发的过程中,发现经常需要使用图标类的矢量图.下面我将详细叙述如何将从网络上下载的ai文件内的图标转化为xml文件并在Android项目中使用该图标. 使 ...

  7. LayoutInflater将layout的xml布局文件实例化为View对象

    LayoutInflater作用是将layout的xml布局文件实例化为View类对象. 获取LayoutInflater的方法有如下三种: LayoutInflater inflater=(Layo ...

  8. XML/YAML文件的输入输出

    本文主要阐述XML/YAML文件在OpenCV3中如何实现输入输出操作.     <1>: XML/YAML文件,顾名思义指的是文件的格式,即以.XML为后缀的文件和以.YAML为后缀的文 ...

  9. voc数据集格式转换为coco数据集格式+修改xml格式文件

    voc数据集格式转换为coco格式+修改xml格式文件中部分内容 voc数据集格式→coco数据集格式 修改xml格式文件中部分内容 voc数据集格式→coco数据集格式 下面这份代码只需修改文件所在 ...

  10. gazebo仿真 - .stl模型文件转化为.dae模型文件

    gazebo仿真 一.`.stl`模型文件转化为`.dae`模型文件 1.`.stl`文件生成 2.`.stl`转化为`.dae` 3.打开已经建立的`.world`文件 二.官方模型库导入gazeb ...

最新文章

  1. python 3.7.732位安装步骤_python安装教程(Windows系统,python3.7为例)
  2. mysql 分页测试,
  3. 操作系统编写之引导扇区
  4. 数据结构—什么是基数排序?
  5. 使用mybatis-generator-core实现自动创建项目
  6. C++ 移动和获取文件读写指针
  7. PowerBuilder10.5 调用 dll 时声明函数方法以及调用
  8. java web外文文献_JAVAWeb外文文献毕业设计.doc
  9. 一图读懂敏捷开发参与者及基本流程
  10. BUPT-CSAPP 2019 Fall 3.58 3.60 3.63
  11. 编程之美 笔记之——24点游戏
  12. gogs搭建git服务教程
  13. `Algorithm-Solution` `AcWing` 378. 骑士放置
  14. 2018 (天津)新能源汽车三电系统技术发展交流大会暨汽车轻量化技术开发与材料应用论坛
  15. LiveUpdate出错SEP无法更新的解决方法
  16. httpcancry抓包教程_HttpCanary抓包工具app下载
  17. Linux 安装 MySQL 8.0.26 超详细图文步骤
  18. 隐式等待,显示等待,强制等待
  19. 人脸眨眼检测:Real-Time Eye Blink Detection using Facial Landmarks
  20. UESTC 758-P酱的冒险旅途【BFS】

热门文章

  1. Ubuntu 16.04 配置 TITAN xp, CUDA 及 cuDNN
  2. AR涂涂乐项目之识别图制作制作地球仪线框一
  3. QQ截图时窗口自动识别的原理
  4. POJ 1616 Harmonic Periods 笔记
  5. Sails基础之Models层的config/datastores配置
  6. 2021-04-29:给定一个数组 arr,代表一排有分数的气球。每打爆一个气球都能获得分数,假设打爆气 球 的分数为 X,获得分数的规则如下: 1)如果被打爆气球的左边有没被打爆的气球,找到离被打爆
  7. Java8 装逼for循环写法
  8. C# Winform Socket即时通讯
  9. 树莓派制作内网dns服务器,树莓派使用dnsmasq搭建DNS服务器
  10. 微信小程序聊天功能 WebSocket 实现发送文字,图片,语音以及WebSocket 常见问题解决方案