调试5——还是50%的效果吧,没啥希望
2015-11-05 21:14
246 查看
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 可调参数 %{ test_path='C:\Users\cong\Desktop\研一实战\项目\图像中时间数字识别\OCR\one\3.jpg'; neighbour_pixels_affect=3; target_digit=2; % forestTrain()参数设置 % .M - [1] number of trees to train % .H - [max(hs)] number of classes % .N1 - [5*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 - [1] minimum number of data points to allow split % .minChild - [1] minimum number of data points allowed at child nodes % .maxDepth - [64] 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=1000; %varargin.H=10; % 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 - [0] 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=20; win_w=20; step=1; disp('参数配置成功...'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp('正在读入图片及特征提取...'); %读入图片及特征提取 data=[]; label=[]; temp_r1=0; temp_c1=0; for i_digit=0:10 % if(i_digit==target_digit) %%%%%%%%%%%%%%%%%%%%%% % this_image_label=1; % end %数字转字符 str=num2str(i_digit); %%数据是不是不平衡 path_temp=strcat('C:\Users\cong\Desktop\研一实战\项目\图像中时间数字识别\trainingSample\num',str,'\'); file=dir(path_temp); for i=3: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,1); data=[data,all_channel_difference_features]; label=[label;i_digit+1]; if(rem(i,200)==0) disp('...'); end end % for i=3:length(file) disp('数字') i_digit disp('的特征提取完毕...'); end % for i_digit=0:9 disp('读入图片及特征提取完毕...'); %%%%%%%%%%%%%%%%%%%%%%%%%% % 扔进分类器中,训练 %%%%%%%%%%%%%%%%%%%%%%%%%% data=data'; disp('正在训练,请稍等...'); forest = forestTrain( data, label, varargin ); disp('训练完毕...'); %} %%%%%%%%%%%%%%%%%%%%%%%%%% % 检测,测试 test_label=[]; test_label_p=[]; win_h=20; win_w=15; windSize = [30,40]; step=2; ps_val_more_than0_3=0.07; count=0; temp_hs=0; disp('正在检测...'); test_image=imread(test_path); %滑窗检测,窗口尺度,步长 [test_r,test_c,test_z]=size(test_image); figure; imshow(test_image); hold on for j_test=1:step:(test_c-win_w+1) for i_test=1:step:(test_r-win_h+1) %model model=test_image(i_test:i_test+win_h-1,j_test:j_test+win_w-1,:); %resize test_image_rs=imresize(model,[temp_r1 temp_c1]); test_data=extract_features(test_image_rs,neighbour_pixels_affect,0); test_data=test_data'; test_data=single(test_data); [hs,ps] = forestApply( test_data, forest,0,0,1);%尺度问题 test_label=[test_label,hs]; test_label_p=[test_label_p,ps(hs)]; %if(ps>ps_val_more_than0_3) if (hs~=11) && (ps(hs)>0.27) %画框 %%%%i_test %j_test count=count+1; %hs if hs~=temp_hs switch hs case 1 rectangle('Position',[j_test,i_test,3,3],'LineWidth',2,'EdgeColor','r'); case 2 rectangle('Position',[j_test,i_test,3,3],'LineWidth',2,'EdgeColor','g'); case 3 rectangle('Position',[j_test,i_test,3,3],'LineWidth',2,'EdgeColor','b'); case 4 rectangle('Position',[j_test,i_test,3,3],'LineWidth',2,'EdgeColor','c'); case 5 rectangle('Position',[j_test,i_test,3,3],'LineWidth',2,'EdgeColor','m'); case 6 rectangle('Position',[j_test,i_test,3,3],'LineWidth',2,'EdgeColor','y'); case 7 rectangle('Position',[j_test,i_test,3,3],'LineWidth',2,'EdgeColor','b'); case 8 rectangle('Position',[j_test,i_test,3,3],'LineWidth',2,'EdgeColor','m'); case 9 rectangle('Position',[j_test,i_test,3,3],'LineWidth',2,'EdgeColor','r'); case 10 rectangle('Position',[j_test,i_test,3,3],'LineWidth',2,'EdgeColor','g'); end %rectangle('Position',[j_test,i_test,30,40],'LineWidth',2,'EdgeColor','r'); %pointAll = [i_test,j_test]; %[state,results]=draw_rect(test_image,pointAll,windSize); hold on end temp_hs=hs; end end end disp(' the value of count is:') count disp('检测完毕!恭喜恭喜!') %%%%%%%%%%%%%%%%%%%%%%%%%%
相关文章推荐
- C# winform中读写ini文件
- web客户端安全之跨站点请求伪造攻击
- React 中style的使用
- java环境变量path也配置了,但还是显示javac不是内部或外部命令的解决办法
- linux笔记:用户配置文件
- LeetCode OJ:Divide Two Integers(两数相除)
- AngularJs ngApp、ngBind、ngBindHtml、ngNonBindable
- 代理设计模式
- hihocoder #1089 : 最短路径·二:Floyd算法
- 冒泡排序语法树接下
- 简单的光照模型
- Android读取通讯录联系人
- javascript中对象的深度克隆
- Openstack API常用命令
- 【AMPPZ2014】【BZOJ4146】Divisors
- 不变模式
- python开发_xml.etree.ElementTree_XML文件操作_该模块在操作XML数据是存在安全隐患_慎用
- 2015-10-29 ado.net 1
- Comparable接口的实现和使用
- 加油,day2