附一些制作标签的工具:https://github.com/tzutalin/labelImg
记下代码,方便我自己以后用,修改部分内容即可,比如文件夹名字,迭代的次数和索引等。。。
function manageImages%%=====================by chenzhi 2016.9.8==========================%%%%============将一个文件夹里所有图片保存到指定文件夹并且以.jpg格式保存==%%clc;%%=====================添加不同文件夹下的文件,并指定添加的数量=======%%% Files = dir(strcat('E:\chenzhi\SubCNN-master\fast-rcnn\data\KITTI\data_object_image_2\training\image_2\','*.png'));% LengthFiles = length(Files);% %%for i = 1:LengthFiles;% j = 1;% for i = 1:7:LengthFiles;% Img = imread(strcat('E:\chenzhi\SubCNN-master\fast-rcnn\data\KITTI\data_object_image_2\training\image_2\',Files(i).name));% path = 'D:\chenzhi\data_annotate\Kitti\train_img\';% %name = sprintf('2012_%06d_00%s',j,'.jpg');% name = sprintf('%06d%s',j+1462,'.jpg');% filename=[path name];% imwrite(Img,filename);% j = j+1;% end% Files = dir(strcat('E:\dataset\bike\','*.jpg'));% LengthFiles = length(Files);% %%for i = 1:LengthFiles;% for i = 1:204;% Img = imread(strcat('E:\dataset\bike\',Files(i).name));% path = 'E:\chenzhi\faster_rcnn-master_cz\faster_rcnn-master\datasets\custom\VOC2012\JPEGImages\'% name = sprintf('%s%06d%s','2012_',1544+i,'_00.jpg')%%之前文件夹里已经有1390个文件了% filename=[path name];% imwrite(Img,filename);% % end% Files = dir(strcat('E:\dataset\person\','*.bmp'));% LengthFiles = length(Files);% %%for i = 1:LengthFiles;% for i = 1:310;% Img = imread(strcat('E:\dataset\person\',Files(i).name));% path = 'E:\chenzhi\faster_rcnn-master_cz\faster_rcnn-master\datasets\custom\VOC2012\JPEGImages\'% name = sprintf('%s%06d%s','2012_',1748+i,'_00.jpg')%%之前文件夹里已经有1390个文件了% filename=[path name];% imwrite(Img,filename);% % end%%================写trainval.txt 和test.txt================%%% fid1=['E:\py-R-FCN-master\data\VOCdevkit0712\VOC0712\ImageSets\Main\','trainval.txt']; %创建新的txt文件% c=fopen(fid1,'wt'); %打开txt文件% fid2=['E:\py-R-FCN-master\data\VOCdevkit0712\VOC0712\ImageSets\Main\','test.txt']; %创建新的txt文件% c2=fopen(fid2,'wt'); %打开txt文件% Files = dir(strcat('E:\py-R-FCN-master\data\VOCdevkit0712\VOC0712\JPEGImages\','*.jpg'));% LengthFiles = length(Files);% for i = 1:LengthFiles;% str = Files(i).name;% str = str(1:end-4) ;% % if mod(i,3) == 0% fprintf(c2,'%s\n',str); % else% fprintf(c,'%s\n',str); %按行写入txt文件,%s为数据形式,str为写入数据。。。% end% end% % fclose(c); %关闭txt文件% fclose(c2); %关闭txt文件%%================将一个文件夹下面的文件(txt)移动到另外一个文件夹% Files = dir(strcat('E:\chenzhi\SubCNN-master\fast-rcnn\data\KITTI\data_object_image_2\training\label_2\','*.txt'));% LengthFiles = length(Files);% %for i = 1:LengthFiles;% j = 1;% for i = 1:7:LengthFiles;% txtname = strcat('E:\chenzhi\SubCNN-master\fast-rcnn\data\KITTI\data_object_image_2\training\label_2\',Files(i).name);% path = 'D:\chenzhi\data_annotate\Kitti\train_label\';% name = sprintf('%06d%s',j+1462,'.txt');% filename=[path name];% copyfile(txtname,path);% j = j+1;% end%%================修改文件名字格式================%%% Files = dir(strcat('D:\chenzhi\data_annotate\dataImage\all\','*.jpg'));% LengthFiles = length(Files);% %%for i = 1:LengthFiles;% for i = 1:LengthFiles; % Img = imread(strcat('D:\chenzhi\data_annotate\dataImage\all\',Files(i).name));% path = 'D:\chenzhi\data_annotate\VOC2012\new\';% name = sprintf('%s%06d%s','2012_',i,'_00.jpg');% filename=[path name];% imwrite(Img,filename);% % endFiles = dir(strcat('D:\chenzhi\data_annotate\Kitti\train_label\','*.txt'));LengthFiles = length(Files);path1 = 'D:\chenzhi\data_annotate\Kitti\train_label\';path2 = 'D:\chenzhi\data_annotate\Kitti\train_label2\';for i = 1:LengthFiles; filename = Files(i).name; newname = sprintf('%06d%s',i+1462,'.txt'); file_name = [path1 filename]; new_name = [path2 newname]; movefile(file_name,new_name);endend