项目代码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”. ...
随机推荐
- webdriver js点击无法点击的元素
原文地址https://blog.csdn.net/galen2016/article/details/56847545 [WebDriver]调用JavaScript 一.WebDriver 提供了 ...
- docker——libnetwork插件网络功能
从1.7.0版本开始,Docker正是把网络和存储这两部分的功能都以插件化形式剥离出来,允许用户通过指令来选择不同的后端实现.剥离出来的独立容器网络项目叫libnetwork,从名字就能看出,它希望将 ...
- DNS(bind)添加A、CNAME、MX、PTR记录、智能DNS(ACL)
1.添加一条A记录(记得更改serial): vim /var/named/chroot/etc/lnh.com.zone 重启一下: rndc reload 查看从服务器: 测试结果: master ...
- 排序问题Java
package zhuzhuangtu; import java.util.*; import java.io.*; public class Main{ public static void mai ...
- uva10417 概率DP
这题 to[i][j] 为第i个人送j这个礼物的概率 我们用13进制进行压缩这个留下的的礼物的个数,这样我们将dp[i][k]表示为当第i个人放完礼物后得到的状态为k时的概率,那么通过记忆化搜索我们就 ...
- hdu5107 线段树
hdu 5107 这题说的是给了一个二维的 平面, 平面内有30000个点每个点都有自己的高度,然后又30000次的查询,每次查询给的是(X,Y,K), 要求出set(x,y){x,y|x<=X ...
- centos6 pip install python-ldap报错
error: Setup script exited with error: command 'gcc' failed with exit status 1 解决方法: 原因是版本不兼容,centos ...
- git仓库迁移的两种解决方案
Git仓库迁移而不丢失log的方法 要求能保留原先的commit记录,应该如何迁移呢? 同时,本地已经clone了原仓库,要配置成新的仓库地址,该如何修改呢? 注意:如果使用了代码审核工具Gerrit ...
- SDN原理 控制层 Controller控制器
本文参照SDN原理视频而成:SDN原理 Controller 概念 从上面这个图片,我们能够知道,Controller 是一个非常重要的东西:承上启下,左右拓展. 从整个SDN的架构来看,控制器 处在 ...
- MySQL 5.7.17 Windows安装和启动
1.在官网http://dev.mysql.com/downloads/下载 MySQL Community Server 2.解压后是这个样子(5.7.18解压后没有my-default.ini文件 ...