[置顶] 制作VOC2007 数据 (matlab版) + 抠图工具
2017-04-03 10:19
204 查看
抠图工具见链接:http://download.csdn.net/detail/yeyang911/9802496
下面主要有两方面组成
1、由扣取的图像转换成txt , 存成格式如下:
%000002.jpg dog 44 28 132 121
%000002.jpg car 50 27 140 110
将扣的图像放入自己对应的文件夹如下:left,right 为两类
data文件夹内的内容如下:
matlab 代码
2、由图像转变成xml 文件
下面主要有两方面组成
1、由扣取的图像转换成txt , 存成格式如下:
%000002.jpg dog 44 28 132 121
%000002.jpg car 50 27 140 110
将扣的图像放入自己对应的文件夹如下:left,right 为两类
data文件夹内的内容如下:
matlab 代码
fildall = fopen('output1.txt','wt');%要存的数据txt fileName = 'data\';%数据文件夹 matt = []; filenames = dir(fileName); filenames = filenames(3:end); for i = 1:size(filenames,1); file = dir([fileName filenames(i).name]); file = file(3:end); for j = 1:size(file,1) name = file(j).name; name = strrep(name,'.png',''); splitName = strsplit(name,'_'); SN = cell2mat(splitName(1)); matt = [matt; str2num(SN)]; end end [a b] = sort(matt);%排序 count = 1; for i = 1:size(filenames,1); file = dir([fileName filenames(i).name]); file = file(3:end); for j = 1:size(file,1) name = file(j).name; name = strrep(name,'.png',''); splitName = strsplit(name,'_'); N1 = str2num(cell2mat(splitName(3))); N2 = str2num(cell2mat(splitName(4))); N3 = str2num(cell2mat(splitName(5))); N4 = str2num(cell2mat(splitName(6))); SN = cell2mat(splitName(1)); outPutName = [SN '.png ' filenames(i).name ' ' num2str(N1) ' ' num2str(N2) ' ' num2str(N3) ' ' num2str(N4)]; outPut(count).line = outPutName; count = count + 1; end end outPut = outPut(b); for i = 1:size(outPut,2) fprintf(fildall, outPut(i).line); fprintf(fildall, '\n'); end fclose(fildall);
2、由图像转变成xml 文件
%% %该代码可以做voc2007数据集中的xml文件, %% clc; clear; %注意修改下面五个变量 imgpath='E:\video\all\';%图像存放文件夹 txtpath='output1.txt';%txt文件 xmlpath_new='Annotations/';%修改后的xml保存文件夹 foldername='VOC2007';%xml的folder字段名 file_suffix = '.png'; %% 注意修改后缀名 fidin=fopen(txtpath,'r'); lastname='begin'; while ~feof(fidin) tline=fgetl(fidin); str = regexp(tline, ' ','split'); filepath=[imgpath,str{1}]; img=imread(filepath); [h,w,d]=size(img); imshow(img); rectangle('Position',[str2double(str{3}),str2double(str{4}),str2double(str{5}),str2double(str{6})],'LineWidth',4,'EdgeColor','r'); pause(0.1); if strcmp(str{1},lastname)%如果文件名相等,只需增加object object_node=Createnode.createElement('object'); Root.appendChild(object_node); node=Createnode.createElement('name'); node.appendChild(Createnode.createTextNode(sprintf('%s',str{2}))); object_node.appendChild(node); node=Createnode.createElement('pose'); node.appendChild(Createnode.createTextNode(sprintf('%s','Unspecified'))); object_node.appendChild(node); node=Createnode.createElement('truncated'); node.appendChild(Createnode.createTextNode(sprintf('%s','0'))); object_node.appendChild(node); node=Createnode.createElement('difficult'); node.appendChild(Createnode.createTextNode(sprintf('%s','0'))); object_node.appendChild(node); bndbox_node=Createnode.createElement('bndbox'); object_node.appendChild(bndbox_node); node=Createnode.createElement('xmin'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(str{3})))); bndbox_node.appendChild(node); node=Createnode.createElement('ymin'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(str{4})))); bndbox_node.appendChild(node); node=Createnode.createElement('xmax'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(str2num(str{5})+str2num(str{3}))))); bndbox_node.appendChild(node); node=Createnode.createElement('ymax'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(str2num(str{6})+str2num(str{4}))))); bndbox_node.appendChild(node); else %如果文件名不等,则需要新建xml copyfile(filepath, 'JPEGImages'); %先保存上一次的xml if exist('Createnode','var') tempname=lastname; tempname=strrep(tempname,file_suffix,'.xml'); xmlwrite(tempname,Createnode); end Createnode=com.mathworks.xml.XMLUtils.createDocument('annotation'); Root=Createnode.getDocumentElement;%根节点 node=Createnode.createElement('folder'); node.appendChild(Createnode.createTextNode(sprintf('%s',foldername))); Root.appendChild(node); node=Createnode.createElement('filename'); node.appendChild(Createnode.createTextNode(sprintf('%s',str{1}))); Root.appendChild(node); source_node=Createnode.createElement('source'); Root.appendChild(source_node); node=Createnode.createElement('database'); node.appendChild(Createnode.createTextNode(sprintf('My Database'))); source_node.appendChild(node); node=Createnode.createElement('annotation'); node.appendChild(Createnode.createTextNode(sprintf('VOC2007'))); source_node.appendChild(node); node=Createnode.createElement('image'); node.appendChild(Createnode.createTextNode(sprintf('flickr'))); source_node.appendChild(node); node=Createnode.createElement('flickrid'); node.appendChild(Createnode.createTextNode(sprintf('NULL'))); source_node.appendChild(node); owner_node=Createnode.createElement('owner'); Root.appendChild(owner_node); node=Createnode.createElement('flickrid'); node.appendChild(Createnode.createTextNode(sprintf('NULL'))); owner_node.appendChild(node); node=Createnode.createElement('name'); node.appendChild(Createnode.createTextNode(sprintf('yy'))); owner_node.appendChild(node); size_node=Createnode.createElement('size'); Root.appendChild(size_node); node=Createnode.createElement('width'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(w)))); size_node.appendChild(node); node=Createnode.createElement('height'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(h)))); size_node.appendChild(node); node=Createnode.createElement('depth'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(d)))); size_node.appendChild(node); node=Createnode.createElement('segmented'); node.appendChild(Createnode.createTextNode(sprintf('%s','0'))); Root.appendChild(node); object_node=Createnode.createElement('object'); Root.appendChild(object_node); node=Createnode.createElement('name'); node.appendChild(Createnode.createTextNode(sprintf('%s',str{2}))); object_node.appendChild(node); node=Createnode.createElement('pose'); node.appendChild(Createnode.createTextNode(sprintf('%s','Unspecified'))); object_node.appendChild(node); node=Createnode.createElement('truncated'); node.appendChild(Createnode.createTextNode(sprintf('%s','0'))); object_node.appendChild(node); node=Createnode.createElement('difficult'); node.appendChild(Createnode.createTextNode(sprintf('%s','0'))); object_node.appendChild(node); bndbox_node=Createnode.createElement('bndbox'); object_node.appendChild(bndbox_node); node=Createnode.createElement('xmin'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(str{3})))); bndbox_node.appendChild(node); node=Createnode.createElement('ymin'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(str{4})))); bndbox_node.appendChild(node); node=Createnode.createElement('xmax'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(str2num(str{5})+str2num(str{3}))))); bndbox_node.appendChild(node); node=Createnode.createElement('ymax'); node.appendChild(Createnode.createTextNode(sprintf('%s',num2str(str2num(str{6})+str2num(str{4}))))); bndbox_node.appendChild(node); lastname=str{1}; end %处理最后一行 if feof(fidin) tempname=lastname; tempname=strrep(tempname,file_suffix,'.xml'); xmlwrite(tempname,Createnode); end end fclose(fidin); file=dir(pwd); for i=1:length(file) if length(file(i).name)>=4 && strcmp(file(i).name(end-3:end),'.xml') fold=fopen(file(i).name,'r'); fnew=fopen([xmlpath_new file(i).name],'w'); line=1; while ~feof(fold) tline=fgetl(fold); if line==1 line=2; continue; end expression = ' '; replace=char(9); newStr=regexprep(tline,expression,replace); fprintf(fnew,'%s\n',newStr); end fprintf('已处理%s\n',file(i).name); fclose(fold); fclose(fnew); delete(file(i).name); end end
相关文章推荐
- 都市行V1.2正式版及数据制作工具发布(免费的基于J2ME手机公交查询软件) [转]
- (SQL)制作测试数据的小工具
- [置顶] 如何在c++ / opencv 中调用matlab 的图像数据
- 利用matlab将自己的数据制作为标准VOC数据集格式
- matlab 工具函数 —— normalize(归一化数据)
- 使用matlab工具研究神经网络的简单过程(网络和数据下载)
- 【matlab】【数据转换工具】以列、行、矩阵形式导出dat数据文件
- MATLAB数据拟合工具在数学建模中的运用
- Python制作数据导入导出工具
- SYD8801批量烧录说明【缩写词解析】【烧录原理】【硬件支持】【工具】【第一部分:提取文件】【第二部分:制作批量烧录工具】【保存当前设置为默认设置】【 预计烧录时间】【带24KFLASH数据的批量】
- 推荐制作精良的笔记软件Wire Note 应用键盘钩子技术获取即时数据 资料查阅的好工具 建立代码片段数据库
- fmri的图像数据在matlab中显示,利用imagesc工具进行显示,自带数据集-by 西南大学xulei教授
- [置顶] 我的Android进阶之旅------>介绍一款集录制与剪辑为一体的屏幕GIF 动画制作工具 GifCam
- [置顶] Faster-RCNN+ZF用自己的数据集训练模型(Matlab版本)
- 用Matlab制作图像块颜色提取工具(三)
- Vs2005之简单日志工具的制作--5.数据结构检查
- Java 报表工具技巧--如何在Style Report中制作数据分组
- 【原创】用Matlab制作图像块颜色提取工具(一)
- [置顶] Matlab中save实现保存数据到mat文件的正确使用
- [置顶] 【hadoop Sqoop】数据迁移工具 sqoop 入门