%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 可调参数 test_path='';
neighbour_pixels_affect=;
target_digit=;
% forestTrain()参数设置
% .M - [] number of trees to train
% .H - [max(hs)] number of classes
% .N1 - [*N/M] number of data points for training each tree
% .F1 - [sqrt(F)] number features to sample for each node split
% .split - ['gini'] options include 'gini', 'entropy' and 'twoing'
% .minCount - [] minimum number of data points to allow split
% .minChild - [] minimum number of data points allowed at child nodes
% .maxDepth - [] maximum depth of tree
% .dWts - [] weights used for sampling and weighing each data point
% .fWts - [] weights used for sampling features
% .discretize - [] optional function mapping structured to class labels
% format: [hsClass,hBest] = discretize(hsStructured,H);
varargin.M=;
%varargin.H=; % forestApply()的输入设置
% data - [NxF] N length F feature vectors
% forest - learned forest classification model
% maxDepth - [] maximum depth of tree
% minCount - [] minimum number of data points to allow split
% best - [] if true use single best prediction per tree % forestApply()输出结果及对比的阀值
% hs - [Nx1] predicted output labels
% ps - [NxH] predicted output label probabilities
ps_val_more_than0_3=0.2; %滑窗检测,窗口尺度,步长
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% data=[];
label=[];
temp_r1=;
temp_c1=; for i_digit=:
% if(i_digit==target_digit) %%%%%%%%%%%%%%%%%%%%%%
% this_image_label=;
% end
%数字转字符
str=num2str(i); %%数据是不是不平衡
path_temp=strcat('C:\Users\cong\Desktop\研一实战\项目\图像中时间数字识别\trainingSample\num',str,'\');
file=dir(path_temp);
for i=:length(file)
path= strcat(path_temp,file(i).name); %%%%%%%%%%%%%%%%%%%%%%%%%%
% 加载图片
%%%%%%%%%%%%%%%%%%%%%%%%%%
I=imread(path);
%I=imread('E:/WeChat.jpg');
%%%%%%%%%%%%%%%%%%%%%%%%%%
% 提取channel features
%%%%%%%%%%%%%%%%%%%%%%%%%%
[all_channel_difference_features,temp_r1,temp_c1]=extract_features(I,);
data=[data,all_channel_difference_features];
label=[label;i_digit+]; % if(i> && this_image_label~=) %%这里只取了前100帧,实际上可以随意抽取一百张
% break;
% end
end % for i=:length(file) end % for i_digit=: %%%%%%%%%%%%%%%%%%%%%%%%%%
% 扔进分类器中,训练
%%%%%%%%%%%%%%%%%%%%%%%%%% forest = forestTrain( data, label, varargin ); %%%%%%%%%%%%%%%%%%%%%%%%%%
% 检测,测试
test_image=imread(test_path);
%滑窗检测,窗口尺度,步长
[test_r,test_c,test_z]=size(test_image);
for i_test=:test_r
%model %resize
test_image=imresize(model,temp_r1,temp_c1);
test_data=extract_features(test_image,);
[hs,ps] = forestApply( test_data, forest, [], [], [] );%尺度问题
if(ps>ps_val_more_than0_3)
%画框 end
end %%%%%%%%%%%%%%%%%%%%%%%%%%
 function [ all_channel_difference_features,,r1,c1 ] = extract_features( I,shrink_or_not )
%EXTRACT_FEATURES 此处显示有关此函数的摘要
% 此处显示详细说明
%%%%%%%%%%%%%%%%%%%%%%%%%%
% 提取channel features
%%%%%%%%%%%%%%%%%%%%%%%%%%
% 参数设置
if(shrink_or_not==)
pChns.shrink=;
end pChns.pColor.enabled=;
pChns.pColor.smooth=;
pChns.pColor.colorSpace='luv'; pChns.pGradMag.enabled=;
pChns.pGradMag.colorChn=;
pChns.pGradMag.normRad=;
pChns.pGradMag.normConst=.;
pChns.pGradMag.full=; pChns.pGradHist.enabled=;
%pChns.pGradHist.binSize=
pChns.pGradHist.nOrients=;
pChns.pGradHist.softBin=;
pChns.pGradHist.useHog=;
pChns.pGradHist.clipHog=.; %pChns.pCustom.** %pChns.complete= % 提取channel features
chns = chnsCompute( I, pChns );
% 将各个通道放在矩阵中
[r1,c1,ch1]=size(chns.data{});
[r2,c2,ch2]=size(chns.data{});
[r3,c3,ch3]=size(chns.data{});
ch=ch1+ch2+ch3;
all_channel=zeros(r1,c1,ch);
all_channel(:,:,:ch1)=chns.data{};
all_channel(:,:,ch1+:ch1+ch2)=chns.data{};
all_channel(:,:,ch1+ch2+:ch)=chns.data{};
%%%%%%%%%%%%%%%%%%%%%%%%%%
% pooling
%%%%%%%%%%%%%%%%%%%%%%%%%%
for ii=:ch
%向下采样
all_pooling(:,:,ii)=imresize(all_channel(:,:,ii),0.2);
end %%%%%%%%%%%%%%%%%%%%%%%%%%
% 再次做相减特征
%%%%%%%%%%%%%%%%%%%%%%%%%%
all_channel_difference_features=[];
for ij=:ch
temp=difference_features( all_pooling(:,:,ij),neighbour_pixels_affect );
all_channel_difference_features = [all_channel_difference_features;temp];
end end
 function [ one_channel_difference_features ] = difference_features( one_channel_features,neighbour_pixels_affect )
%DIFFERENCE_FEATURES 计算邻域内个特征之间两两相减
%input:
% one_channel_features
%neighbour_pixels_affect
%output:
%one_channel_difference_features [r,c]=size(one_channel_features); one_channel_difference_features=[];
for i=:r-neighbour_pixels_affect+
for j=:c-neighbour_pixels_affect+
local_features=one_channel_features(i:i+neighbour_pixels_affect-,j:j+neighbour_pixels_affect-);
temp=local_feature_compute(local_features);
one_channel_difference_features=[one_channel_difference_features;temp];%特征拼接
end
end
end function [ local_differece_feature ]=local_feature_compute( local_features )
[r,c]=size(local_features);
result_mat=local_features-local_features(,).*ones(r,c);
result_vector=reshape(result_mat,r*c,);
local_differece_feature=result_vector(:r*c,);%把第一个特征去掉,自己减自己没有任何特征信息可言
end
%{
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 可调参数 test_path='C:\Users\cong\Desktop\研一实战\项目\图像中时间数字识别\OCR\one\3.jpg';
neighbour_pixels_affect=;
target_digit=;
% forestTrain()参数设置
% .M - [] number of trees to train
% .H - [max(hs)] number of classes
% .N1 - [*N/M] number of data points for training each tree
% .F1 - [sqrt(F)] number features to sample for each node split
% .split - ['gini'] options include 'gini', 'entropy' and 'twoing'
% .minCount - [] minimum number of data points to allow split
% .minChild - [] minimum number of data points allowed at child nodes
% .maxDepth - [] maximum depth of tree
% .dWts - [] weights used for sampling and weighing each data point
% .fWts - [] weights used for sampling features
% .discretize - [] optional function mapping structured to class labels
% format: [hsClass,hBest] = discretize(hsStructured,H);
varargin.M=;
%varargin.H=; % forestApply()的输入设置
% data - [NxF] N length F feature vectors
% forest - learned forest classification model
% maxDepth - [] maximum depth of tree
% minCount - [] minimum number of data points to allow split
% best - [] if true use single best prediction per tree % forestApply()输出结果及对比的阀值
% hs - [Nx1] predicted output labels
% ps - [NxH] predicted output label probabilities
ps_val_more_than0_3=0.2; %滑窗检测,窗口尺度,步长
win_h=;
win_w=;
step=;
disp('参数配置成功...');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('正在读入图片及特征提取...');
%读入图片及特征提取
data=[];
label=[];
temp_r1=;
temp_c1=; for i_digit=:
% if(i_digit==target_digit) %%%%%%%%%%%%%%%%%%%%%%
% this_image_label=;
% end
%数字转字符
str=num2str(i_digit); %%数据是不是不平衡
path_temp=strcat('C:\Users\cong\Desktop\研一实战\项目\图像中时间数字识别\trainingSample\num',str,'\');
file=dir(path_temp);
for i=:length(file)
path= strcat(path_temp,file(i).name); %%%%%%%%%%%%%%%%%%%%%%%%%%
% 加载图片
%%%%%%%%%%%%%%%%%%%%%%%%%%
I=imread(path);
%I=imread('E:/WeChat.jpg');
%%%%%%%%%%%%%%%%%%%%%%%%%%
% 提取channel features
%%%%%%%%%%%%%%%%%%%%%%%%%%
[all_channel_difference_features,temp_r1,temp_c1]=extract_features(I,neighbour_pixels_affect,);
data=[data,all_channel_difference_features];
label=[label;i_digit+];
if(rem(i,)==)
disp('...');
end
end % for i=:length(file)
disp('数字')
i_digit
disp('的特征提取完毕...');
end % for i_digit=:
disp('读入图片及特征提取完毕...');
%%%%%%%%%%%%%%%%%%%%%%%%%%
% 扔进分类器中,训练
%%%%%%%%%%%%%%%%%%%%%%%%%%
data=data';
disp('正在训练,请稍等...');
forest = forestTrain( data, label, varargin );
disp('训练完毕...');
%}
%%%%%%%%%%%%%%%%%%%%%%%%%%
% 检测,测试
test_label=[];
test_label_p=[];
win_h=;
win_w=;
windSize = [,];
step=;
ps_val_more_than0_3=0.07; disp('正在检测...');
test_image=imread(test_path);
%滑窗检测,窗口尺度,步长
[test_r,test_c,test_z]=size(test_image);
figure;
imshow(test_image);
hold on for i_test=:step:test_r-win_h+
for j_test=:step:test_c-win_w+
%model
model=test_image(i_test:i_test+win_h-,j_test:j_test+win_w-,:);
%resize
test_image_rs=imresize(model,[temp_r1 temp_c1]);
test_data=extract_features(test_image_rs,neighbour_pixels_affect,);
test_data=test_data';
test_data=single(test_data); [hs,ps] = forestApply( test_data, forest,,,);%尺度问题
test_label=[test_label,hs];
test_label_p=[test_label_p,ps(hs)];
if(ps>ps_val_more_than0_3)
%画框
%draw_rect(test_image,);
i_test
j_test
rectangle('Position',[i_test,j_test,,],'LineWidth',,'EdgeColor','r');
%pointAll = [i_test,j_test];
%[state,results]=draw_rect(test_image,pointAll,windSize);
hold on
end end
hold on
end
disp('检测完毕!恭喜恭喜!')
%%%%%%%%%%%%%%%%%%%%%%%%%%

项目代码matlab的更多相关文章

  1. 借助GitHub托管你的项目代码

    PS:话说自己注册了GitHub都很久了,却没有怎么去弄,现在系统学习一下,也把自己的学习经历总结下来share给大家,希望大家都能把GitHub用起来,把你的项目代码happy地托管起来! 一.基本 ...

  2. .NET 项目代码风格要求

    原文:http://kb.cnblogs.com/page/179593/ 项目代码风格要求 PDF版下载:项目代码风格要求V1.0.pdf 代码风格没有正确与否,重要的是整齐划一,这是我拟的一份&l ...

  3. [Asp.net 5] DependencyInjection项目代码分析-目录

    微软DI文章系列如下所示: [Asp.net 5] DependencyInjection项目代码分析 [Asp.net 5] DependencyInjection项目代码分析2-Autofac [ ...

  4. [Asp.net 5] DependencyInjection项目代码分析4-微软的实现(5)(IEnumerable<>补充)

    Asp.net 5的依赖注入注入系列可以参考链接: [Asp.net 5] DependencyInjection项目代码分析-目录 我们在之前讲微软的实现时,对于OpenIEnumerableSer ...

  5. IntelliJ IDEA 乱码解决方案 (项目代码、控制台等)

    IntelliJ IDEA 乱码解决方案 (项目代码.控制台等) 最近IDE从eclipse改成IntelliJ IDEA 了,原因是公司大部分人都在用这个IDE,而且一直推荐用,所以尝尝鲜.换的第一 ...

  6. 【转载】借助GitHub托管你的项目代码

    PS:自己关注博客园有2年之久了,不久前才申请注册账号.GitHub也差不多一年多了,因英语水平刚刚及格,所以去GitHub没有博客园多,也是几个月前才注册了账号,前几天休息时看到 EdisonCho ...

  7. C# API项目代码正确 ,页面出不来的问题

    C# API项目代码正确  页面出不来的问题,截图如下: 解决方法: 在项目里设置好[起始页],就可以了.

  8. git上传项目代码到github

    参考: git学习——上传项目代码到github github上传时出现error: src refspec master does not match any解决办法 git 上传本地文件到gith ...

  9. [Asp.net 5] DependencyInjection项目代码分析4-微软的实现(2)

    在 DependencyInjection项目代码分析4-微软的实现(1)中介绍了“ServiceTable”.“ServiceEntry”.“IGenericService”.“IService”. ...

随机推荐

  1. java基础知识面试题(41-95)

    41.日期和时间:- 如何取得年月日.小时分钟秒?- 如何取得从1970年1月1日0时0分0秒到现在的毫秒数?- 如何取得某月的最后一天?- 如何格式化日期?答:问题1:创建java.util.Cal ...

  2. flask jinja的宏

    form中关于表单的定义 class AreaListForm(Form): area1 = BooleanField(u'1区', default=False) area2 = BooleanFie ...

  3. Python:导入numpy报错 No module named numpy

    Numpy是python的一种开源的数值计算扩展.这种工具可用来存储和处理大型矩阵,比python自身的嵌套列表结构要高效的多.但是在使用numpy时可能会出错(如上图). 解决办法:下载安装对应版本 ...

  4. SQL substring()函数

    ①substring()函数是个截取函数,不同的数据库语法有区别 MySQL: SUBSTR( ), SUBSTRING( ) Oracle: SUBSTR( ) SQL Server: SUBSTR ...

  5. 20165207 预备作业3 Linux安装及学习

    Linux安装及学习 假期我没有把我的电脑带回家,受到家里的台式机内存和网吧的一些条件的限制我只在台式机安装了32位系统然后学习了实验楼的Vim课程以及Linux的前八课. 问题与解决 安装过程 我家 ...

  6. 2017-2018-2 20165207 实验三《敏捷开发与XP实践》实验报告

    java 实验三 实验报告 实验内容 代码规范 不规范的代码可能妨碍阅读,在粘贴下来老师在云班课中设置的提交点一的代码之后,我首先使用了IDEA中Code选项卡的Reformat Code功能规范代码 ...

  7. 【运维技术】CentOS7上从零开始安装阿里RocketMQ版本:release-4.0.1【亲测哈哈】

    CentOS7上从零开始安装阿里RocketMQ版本:release-4.0.1[亲测哈哈] 安装git # 更新包 $ yum update # 安装git $ yum install git # ...

  8. MySQL中的索引的引用

    博文首先说明索引的分类及创建,然后会涉及到索引的可用性选择以及索引的优化. 索引是什么?先说创建索引的目的,创建索引是为提高对数据的查询速度.在字典的目录中,我们可以很快找到某个字的位置,索引的作用就 ...

  9. Vue学习笔记之vue-cli脚手架安装和webpack-simple模板项目生成

    vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue-cli 可以快速创建 vue 项目. GitHub地址是:https://github.com/vuejs/vue-cli 一. ...

  10. 20145221 《Java程序设计》第七周学习总结

    20145221 <Java程序设计>第七周学习总结 教材学习内容总结 第十二章部分 - Lambda 认识Lambda语法 Lambda去可以重复,符合DRY原则,而且Lambda表达式 ...