forest_train训练文件的生成代码

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%forest_train pos
main_path = 'D:\\workspace\\xx\\机器学习训练框架\\hough_forests_db\\tougue\\';
main_path_1 = 'D:\\workspace\\xx\\机器学习训练框架\\hough_forests_db\\';
train_path = [main_path_1, 'train_pos.txt'];
fid=fopen(train_path,'w');
fclose(fid);
dat = dir( main_path );
icount = 0;
for j = 1 : length( dat )
    % If maindir(i) is not a dir, skip
    if( isequal( dat( j ).name, '.' )||...
        isequal( dat( j ).name, '..'))
        continue;
    end
    icount = icount + 1;
end
fid=fopen(train_path,'a+');
fprintf(fid,'%d 1\n',icount);
fclose(fid);
for j = 1 : length( dat )
    % If maindir(i) is not a dir, skip
    if( isequal( dat( j ).name, '.' )||...
        isequal( dat( j ).name, '..'))
        continue;
    end
    datapath = fullfile( main_path, dat( j ).name, '');
    ss = size(strfind(datapath, 'Thumbs.db', 'ForceCellOutput',false));
    if(ss(1) == 0)
        datapath = fullfile( main_path, dat( j ).name, '');
        if(1)
            img=imread(datapath);
            tt = (size(img));
            %tt(1) = 96;
            %tt(2) = 160;
            %img1 = imresize(img, [tt(1) tt(2)]);
        end
        %clear img;
        %imwrite(img1, datapath);
        fid=fopen(train_path,'a+');
        fprintf(fid,'%s 0 0 %d %d %d %d\n',dat( j ).name, tt(2), tt(1), floor(tt(1)/2), floor(tt(2)/2));
        fclose(fid);
    end
end
%neg
main_path = 'D:\\workspace\\xx\\机器学习训练框架\\hough_forests_db\\other\\';
train_path = [main_path_1, 'train_neg.txt'];
fid=fopen(train_path,'w');
fclose(fid);
dat = dir( main_path );
icount = 0;
for j = 1 : length( dat )
    % If maindir(i) is not a dir, skip
    if( isequal( dat( j ).name, '.' )||...
        isequal( dat( j ).name, '..'))
        continue;
    end
    icount = icount + 1;
end
fid=fopen(train_path,'a+');
fprintf(fid,'%d 1\n',icount);
fclose(fid);
for j = 1 : length( dat )
    % If maindir(i) is not a dir, skip
    if( isequal( dat( j ).name, '.' )||...
        isequal( dat( j ).name, '..'))
        continue;
    end
    datapath = fullfile( main_path, dat( j ).name, '');
    ss = size(strfind(datapath, 'Thumbs.db', 'ForceCellOutput',false));
    if(ss(1) == 0)
        datapath = fullfile( main_path, dat( j ).name, '');
        img=imread(datapath);
        tt = (size(img));
        fid=fopen(train_path,'a+');
        fprintf(fid,'%s 0 0 %d %d\n',dat( j ).name, tt(2), tt(1));
        fclose(fid);
    end
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值