%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 可调参数 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. CSV文件读取类

    最近项目中,经常需要读取Csv文件.基本步骤是: (1)按行读取 (2)然后将一行数据按逗号,分割为字符串数组 (3)将各列字符串转换成相应类型的数据 ,如int double类型 写了一个简单的Cs ...

  2. Java用数据结构解决实现问题之数学问题

    有趣的整数: 完数:如果一个数字恰好等于他的因子之和,就叫做完数,需求是求出10000以内的所有的完数. 解法:1.用n去除以1-n之间的所有的整数,将能整除的被除数保存到一个数组中,作为n的一个因子 ...

  3. sql server 将时间中的时分秒改为00:00:00

    select convert(varchar(10),getdate(),120

  4. springcloud7---hystrix

    目前使用eureka server完成了服务注册和服务发现,ribbon完成了客户端负载均衡.如果服务提供者的响应很慢那么服务消费者会强制等待,一直等到http请求超时,如果服务消费者还是其他的服务提 ...

  5. scp命令简单应用

    实例1:从远处复制文件到本地目录 $scp root@10.6.159.147:/opt/soft/demo.tar /opt/soft/ 说明: 从10.6.159.147机器上的/opt/soft ...

  6. c++第二十三天

    p124~p126: 算数运算符 1.形如+ -(一元) * / % + -(二元)为算数运算符. 2.所有算数运算符都满足左结合律. 3.算数运算符的运算对象和求值结果都是右值. 4.在表达式求值之 ...

  7. php 发送邮件类

    //******************** 配置信息 ********************************            $smtpserver = "smtp.263 ...

  8. 前端学习笔记之JavaScript

    JavaScript概述 JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中),后将其改名ScriptEase(客 ...

  9. 20145204《Java程序设计》第3周学习总结

    20145204<Java程序设计>第3周学习总结 教材学习内容总结 对象和类. Java有基本类型和类类型这两个类型系统.本章主要介绍类类型.定义类时用关键词class,利用类建立对象实 ...

  10. jQuery Mobile中的页面加载与跳转机制

    第一次做用jQuery Mobile做东西,发现一些跟平时的思维习惯不太一样的.其中这个框架的页面加载机制便是其中一个.如果不明白其中的奥秘,往往会出现一些让人摸不着头脑的怪现象,比如页面进入后点击按 ...