%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 可调参数 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. TeamViewer远程唤醒主机实战教程(多图)

    前言:首先感谢大家来到这里.这篇文章其实算是一个教程,文章中涉及到了TeamViewer,Mac OS X,TP-Link家用路由器,以及花生壳DDNS,对于新手而言内容可能稍微有些多,但我相信按照我 ...

  2. 制造抽象基类--《C++必知必会》 条款33

    抽象类,含有纯虚函数的类,不可以创建对象. 然而,有时我们并不需要某个函数定义为纯虚函数,但是任然希望此类像抽象类一样,不可以创建对象. 方法1:通过确保类中不存在共有构造函数来模拟抽象基类的性质.意 ...

  3. 11Qt样式表

    Qt样式表 Qt样式表的思想很大程度上是来自原HTML的层叠式样式表(CSS),通过调用Qwdiget::setStyleSheet()或是Qapplication::setStyleSheet(), ...

  4. SQL group by的使用

    ①定义 "group by" 从字面上理解是根据“by"指定的规则对数据进行分组 ②简单示例 ③group by 中的select字段是受限制的 select指定的字段要 ...

  5. tomcat_日志打印格式问题

    1.需要在Catalina/conf/server.xml中设置一下:将文件中这一段的注释去掉(如下),然后将pattern的值改为combined ,这个模式下记录的日志比较详细.          ...

  6. js 打印软件 Lodop

    官网首页:http://www.c-lodop.com/index.html 下载页面里有使用手册可下载.

  7. git clone时,提示warning: remote HEAD refers to nonexistent ref, unable to checkout

    一.环境 发行版:Ubuntu 18.04.1 LTS 代号:bionic 内核版本:4.15.0-30-generic 二.背景 git clone https://source.codeauror ...

  8. POJ 1860 Currency Exchange(最短路&spfa正权回路)题解

    题意:n种钱,m种汇率转换,若ab汇率p,手续费q,则b=(a-q)*p,你有第s种钱v数量,问你能不能通过转化让你的s种钱变多? 思路:因为过程中可能有负权值,用spfa.求是否有正权回路,dis[ ...

  9. vim 录制宏,自动循环执行组合操作

    前言 在 vim 中录制宏的意思就是把一段操作录制下来,然后可以重复执行.打个比方,我有一个文本,一共 50000 行,我要在每一行后面加一个英文句号.这个操作如果手动做的话效率非常低.这时候我可以这 ...

  10. linux启停jar包的shell脚本

    start.sh  启动脚本 #!/bin/bashcd /home/hygwnohup java -jar hy-web.jar >> /home/hygw/logs/server.lo ...