项目代码matlab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 可调参数 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的更多相关文章
- 借助GitHub托管你的项目代码
PS:话说自己注册了GitHub都很久了,却没有怎么去弄,现在系统学习一下,也把自己的学习经历总结下来share给大家,希望大家都能把GitHub用起来,把你的项目代码happy地托管起来! 一.基本 ...
- .NET 项目代码风格要求
原文:http://kb.cnblogs.com/page/179593/ 项目代码风格要求 PDF版下载:项目代码风格要求V1.0.pdf 代码风格没有正确与否,重要的是整齐划一,这是我拟的一份&l ...
- [Asp.net 5] DependencyInjection项目代码分析-目录
微软DI文章系列如下所示: [Asp.net 5] DependencyInjection项目代码分析 [Asp.net 5] DependencyInjection项目代码分析2-Autofac [ ...
- [Asp.net 5] DependencyInjection项目代码分析4-微软的实现(5)(IEnumerable<>补充)
Asp.net 5的依赖注入注入系列可以参考链接: [Asp.net 5] DependencyInjection项目代码分析-目录 我们在之前讲微软的实现时,对于OpenIEnumerableSer ...
- IntelliJ IDEA 乱码解决方案 (项目代码、控制台等)
IntelliJ IDEA 乱码解决方案 (项目代码.控制台等) 最近IDE从eclipse改成IntelliJ IDEA 了,原因是公司大部分人都在用这个IDE,而且一直推荐用,所以尝尝鲜.换的第一 ...
- 【转载】借助GitHub托管你的项目代码
PS:自己关注博客园有2年之久了,不久前才申请注册账号.GitHub也差不多一年多了,因英语水平刚刚及格,所以去GitHub没有博客园多,也是几个月前才注册了账号,前几天休息时看到 EdisonCho ...
- C# API项目代码正确 ,页面出不来的问题
C# API项目代码正确 页面出不来的问题,截图如下: 解决方法: 在项目里设置好[起始页],就可以了.
- git上传项目代码到github
参考: git学习——上传项目代码到github github上传时出现error: src refspec master does not match any解决办法 git 上传本地文件到gith ...
- [Asp.net 5] DependencyInjection项目代码分析4-微软的实现(2)
在 DependencyInjection项目代码分析4-微软的实现(1)中介绍了“ServiceTable”.“ServiceEntry”.“IGenericService”.“IService”. ...
随机推荐
- 模块讲解----subprocess模块
历史 #输出结果到屏幕上,并不返回执行状态os.system('dir')#保存命令的执行结果输出ret = os.popen('dir').read() 问题:上面2条是把命令结果保存下来了,但是返 ...
- [C#]解决程序Vista/Win7下因UAC导致的读写错误
在微软的操作系统中,vista和win7加入了UAC的功能,UAC(User Account Control,用户帐户控制)是微软为提高系统安全而在Windows Vista中引入的新技术,它要求用户 ...
- web前端几个小知识点笔记
1.css实现宽度是百分比的盒子为正方形 <div style="width:50%;padding-bottom:50%;height:0px;background:#ccc;&qu ...
- python 字典(dict)get方法应用
如果我们需要获取字典值的话,我们有两种方法,一个是通过dict['key'],另外一个就是dict.get()方法. 今天给大家分享的就是字典的get()方法. 这里我们可以用字典做一个小游戏,假设用 ...
- OpenCV中Denoising相关函数的简单介绍
参考:http://wenhuix.github.io/research/denoise.html一.基本情况 (一)基本方法 Fast Non-Local Me ...
- 20145315 《Java程序设计》第三周学习总结
20145315 <Java程序设计>第三周学习总结 教材学习内容总结 第四章 4.1类与对象 4.1.1定义类: new clothes():新建一个对象. class clothes ...
- 【转载】通过JSFL让Flash Professional CS4或CS5拥有批量FLA导出SVG的功能
近期一个项目要求博主爱吾所爱(爱生活=爱技术)将 所有的.fla源文件里的图形都转为.svg矢量图,经常一番搜索之后,发现新版本的Flash Professional CC已经有此功能,但无奈我等用的 ...
- sqlyog注册码
姓 名(Name):ttrar 序 列 号(Code):8d8120df-a5c3-4989-8f47-5afc79c56e7c或者(OR)姓 名(Name):ttrar序 列 号(C ...
- LightOJ 1027 A Dangerous Maze(期望)
https://cn.vjudge.net/problem/LightOJ-1027 题意:有n扇门,每扇门有个时间ti,选择正数的门可以在ti后带你走出迷宫,负数的门会在ti后带你回到起点,然后重新 ...
- HDU 3315 My Brute(二分图最佳匹配+尽量保持原先匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=3315 题意: 有S1到Sn这n个勇士要和X1到Xn这n个勇士决斗,初始时,Si的决斗对象是Xi. 如果Si赢了X ...