OCR识别可以分为数字扫描对象的获取,数字图像的生产,数字图像的处理和OCR文本识别等四个阶段.OCR识别在信息资源数字化工作中应用时,其准确度一直是人们关注的焦点,因为OCR精确识别是保证数字化产品质量进而为整项工作提供用户保障的一个重要环节.
登录后复制
% OCR (Optical Character Recognition). % PRINCIPAL PROGRAMwarning off %#ok<WNOFF>% Clear allclc, close all, clear all% Read imageimagen=imread('TEST_1.jpg');% Show imageimshow(imagen);title('INPUT IMAGE WITH NOISE')% Convert to gray scaleif size(imagen,3)==3 %RGB image imagen=rgb2gray(imagen);end% Convert to BWthreshold = graythresh(imagen);imagen =~im2bw(imagen,threshold);% Remove all object containing fewer than 30 pixelsimagen = bwareaopen(imagen,30);%Storage matrix word from imageword=[ ];re=imagen;%Opens text.txt as file for writefid = fopen('text.txt', 'wt');% Load templatesload templatesglobal templates% Compute the number of letters in template filenum_letras=size(templates,2);while 1 %Fcn 'lines' separate lines in text [fl re]=lines(re); imgn=fl; %Uncomment line below to see lines one by one %imshow(fl);pause(0.5) %----------------------------------------------------------------- % Label and count connected components [L Ne] = bwlabel(imgn); for n=1:Ne [r,c] = find(L==n); % Extract letter n1=imgn(min(r):max(r),min(c):max(c)); % Resize letter (same size of template) img_r=imresize(n1,[42 24]); %Uncomment line below to see letters one by one %imshow(img_r);pause(0.5) %------------------------------------------------------------------- % Call fcn to convert image to text letter=read_letter(img_r,num_letras); % Letter concatenation word=[word letter]; end %fprintf(fid,'%s\n',lower(word));%Write 'word' in text file (lower) fprintf(fid,'%s\n',word);%Write 'word' in text file (upper) % Clear 'word' variable word=[ ]; %*When the sentences finish, breaks the loop if isempty(re) %See variable 're' in Fcn 'lines' break end endfclose(fid);%Open 'text.txt' filewinopen('text.txt')fprintf('For more information, visit: <a href= "http://www.matpic.com">www.matpic.com </a> \n')% clear all1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删