VOC数据集中Main中的txt存图片名,为了还原整体名字(加个.jpg)
matlab程序:
fid=fopen('C:\Users\Administrator\Desktop\20191121\VOC2012/testjpg.txt','wt'); %存放测试图片的文件
fid2=fopen('C:\Users\Administrator\Desktop\20191121\VOC2012/testxml.txt','wt'); %存放测试xml的文件
phns=['C:\Users\Administrator\Desktop\20191121\VOC2012\ImageSets\Main/test.txt']; %存有图片名字的txt
fpn=fopen(phns,'rt'); %打开文档
while feof(fpn) ~=1 %用于判断文件指针p在其所指的文件中的位置,如果到文件末,函数返回1,否则返回0
file=fgetl(fpn); %获取文档第一行
new_str=[file '.jpg']; %在读取的内容后面加.jpg
new_str2=[file '.xml']; %在读取的内容后面加.xml
fprintf(fid,'%s\n',new_str); %新的字符串写入当新建的txt文档中
fprintf(fid2,'%s\n',new_str2);
end
fclose(fid);
fclose(fid2);