• 大小: 2KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-04-18
  • 语言: Matlab
  • 标签: 字符分割  MATLAB  OCR  

资源简介

OCR中英文段落的提取、分割,最终得到英文字符

资源截图

代码片段和文件信息

clear all;
close all;
%% read the image needing to process and prepare
%figure ();   %figure 1
%subplot(231);
I=imread(‘C:\Users\EXIE\Desktop\test1.jpg‘);
%imshow(I);
%figure();    %figure 2
%subplot(232);
I1=rgb2gray(I);
%imshow(I1);
%figure();    %figure 3
%subplot(233);
I2=edge(I1‘robert‘0.20‘both‘);
%imshow(I2);

% new add code
se=[1;1;1];     % 
I3=imerode(I2se);
%subplot(234);
%figure();    %figure 4
%imshow(I3);   
se=strel(‘rectangle‘[2525]);  %
I4=imclose(I3se); 
%figure();   % figure 5
%subplot(235);
%imshow(I4);
%subplot(236);
I5=bwareaopen(I42000);
%figure();  % figure 6
%imshow(I5);

%I2=I5;

%------- accumulate the pixel amount ---------%
[yx]=size(I2);    % just doing process on I2 not I5
I3=double(I2);
Y1=zeros(y1);
YTest=zeros(y2);    %test each line‘s position on Y direction
for i=1:y
    YTest(i2)=i;        %test each line‘s position on Y direction
        for j=1:x
            if(I3(ij)==1)    % 1 means White 0 means Black       
                Y1(i1)= Y1(i1)+1;
                YTest(i1)=Y1(i1);   %test each line‘s position on Y direction
            end
        end
end
%figure();   % test Y1
%plot(1:yY1);
%---------- locating the paragraph position ---------%
YConcaveS=1;
YConcaveE=1;
Sign=0;

for i=1:y
    if ((Y1(i)>0) && Sign==0)         % line beginning position on Y direction
        Sign=1;
        YConcaveS=[YConcaveS i];
    elseif ((Y1(i)==0) && Sign==1)    % line endding position on Y direction
        Sign=0;
        YConcaveE=[YConcaveE i];
    end
        
end

%----------- abstract each line ----------%
[TempY n]=size(YConcaveS);


for iLine=2:2  %n   % dividing pragraph into lines
    %subplot(n-11iLine-1);
    Line=I1(YConcaveS(iLine):YConcaveE(iLine):);    % abstract each line for next step
    figure();       % display processed each line of image
    imshow(Line);   %  test LINE is corret or not
    %Line=imresize(Line[2*y2*x]);
    
    %--------- divide LINE into words ------------%
    
    I=im2bw(Line0.3);
    %I=Line;
    [y1 x1]=size(I);    % y1 x1 discrib LINE size
    
    %--------- accumulating LINE‘s Top outline --------%
    Top=zeros(1x1);
    for iWord=1:x1
        jWord=1;
        while ((I(jWordiWord)==1)&&(jWord            jWord=jWord+1;
        end
            Top(iWord)=y1-jWord;                  % accumulating Black Pixel amount
    end
    
    %--------- accumulating LINE‘s Bottom outline --------%
    Bottom=zeros(1x1);      
    for iWord=1:x1
        jWord=y1;
        while ((I(jWordiWord)==1)&&(jWord>1))
            jWord=jWord-1;
        end
        Bottom(iWord)=y1-jWord;
    end
    %figure();   % test Line Top Outline
    %plot(1:x1Top);  % Line Top outline
    
    Number=0;    % space amount between words
    Sign=0;      % state where the position is in word is 1 and in space is 0
   

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4983  2013-10-11 23:38  Untitledproject3.m

----------- ---------  ---------- -----  ----

                 4983                    1


评论

共有 条评论