MATLAB 生成 HOG+SVM训练所需的txt文件

来源:互联网 发布:c语言大小写转换a变a 编辑:程序博客网 时间:2024/05/17 04:41

MATLAB 生成 HOG+SVM训练所需的txt文件

前言
很简单的一段代码,用于生成HOG+SVM训练所需的数据的文件列表和标签, txt内容就是一行文件路径和一行标签.
本文是为另一篇博文A服务,A还没写好。

代码

% 将正负样本的文件路径和类别按行存放.% 0表示negative样本;1表示positive样本.% pathPos是正样本路径,pathNeg1和pathNeg2是负样本路径pathPos =  'D:\xm\NumDetec\Positive_Origin_Resized_WhiteFill\';pathNeg1 = 'D:\xm\NumDetec2\negative0\negativeTotal\';% pathNeg2 = 'D:\xm\NumDetec\negative2\negativeTotal\';% 获得样本的文件列表PosImages = dir(fullfile(pathPos,'*.jpg'));NegImages1 = dir(fullfile(pathNeg1,'*.jpg'));% NegImages2 = dir(fullfile(pathNeg2,'*.jpg'));% strcat(NegImages(1).folder,'\', NegImages(1).name);%% IOtxtPath = 'SVM_DATA.txt';% 输出文件% 正样本路径txtFile = fopen(txtPath,  'a');for indexPos = 1:size(PosImages,1)    absPath = strcat(PosImages(indexPos).folder,'\', PosImages(indexPos).name);    fprintf(txtFile, '%s', absPath);    fprintf(txtFile,'\r\n'); %换行    fprintf(txtFile, '%d', 1);    fprintf(txtFile,'\r\n'); %换行   end% 负样本路径1for indexNeg = 1:size(NegImages1,1)    absPath = strcat(NegImages1(indexNeg).folder,'\', NegImages1(indexNeg).name);    fprintf(txtFile, '%s', absPath);    fprintf(txtFile,'\r\n'); %换行    fprintf(txtFile, '%d', 0);    fprintf(txtFile,'\r\n'); %换行   end% % 负样本路径2% for indexNeg = 1:size(NegImages2,1)%     absPath = strcat(NegImages2(indexNeg).folder,'\', NegImages2(indexNeg).name);%     fprintf(txtFile, '%s', absPath);%     fprintf(txtFile,'\r\n'); %换行% %     fprintf(txtFile, '%d', 0);% %     fprintf(txtFile,'\r\n'); %换行   % endif 0==fclose(txtFile)    disp('文件关闭成功');end% function ioFlag = pathWrite(PosImages, NegImages, desTxt)% end

输出文件部分内容格式如下图:
SVD_DATA.txt文件内容

完.

原创粉丝点击