error found while writing in notepad using OCR

조회 수: 2 (최근 30일)
Pat
Pat 2011년 9월 20일
답변: roja m 2017년 11월 16일
I get an error ehile writing in notepad which is last line in my code,which in have pasted below,my input imge is a score card(AFTER CROPPING FROM A IMAGE)i.e IND 77-4,wen i use OCR to write to note pad,i get output as IND 7ZK,CAN ANYONE TELL WHAT MISTAKE I HAVE MADE
% PRINCIPAL PROGRAM
warning off %#ok<WNOFF>
% Clear all
clc, close all, clear all
% Read image
imagen=imread('samp22.jpg');
% Show image
imshow(imagen);
title('INPUT IMAGE WITH NOISE'
% Convert to gray scale
if size(imagen,3)==3 %RGB image
imagen=rgb2gray(imagen);
end
% Convert to BW
threshold = graythresh(imagen);
imagen =~im2bw(imagen,threshold);
% Remove all object containing fewer than 30 pixels
imagen = bwareaopen(imagen,30);
%Storage matrix word from image
%FIGURE,IM
word=[ ];
re=imagen;
%Opens text.txt as file for write
fid = fopen('text.txt', 'wt');
% Load templates
load templates
global templates
% Compute the number of letters in template file
num_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
figure,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]);
%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=[ ];
if isempty(re) %See variable 're' in Fcn 'lines'
break
end
end
fclose(fid);
%Open 'text.txt' file
winopen('text.txt')
  댓글 수: 1
Jan
Jan 2011년 9월 20일
Please format the code to improve the readability.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2011년 9월 20일
WARNING OFF is a bad idea. Usually warnings should be avoided, not ignored.
CLEAR ALL is also a bad idea. It removes all parsed functions from the memory and reading the files again from the disk takes a lot of time. There is not benefit to use this. Nevertheless it appears in many files of beginners, such that I assume it is recommended in a textbook. In spite of this, it is not useful.
If I understand correctly, the problem is found in this line (and all other lines do not concern the problem at all):
letter = read_letter(img_r, num_letras);
This function replies a wrong character - correct? As long as we do not have any information about this function, it is impossible to suggest any improvements.
  댓글 수: 1
Ahmed Mehar
Ahmed Mehar 2015년 8월 10일
Jan Simon here is the function definition of read_letter........ function letter=read_letter(imagn,num_letras) global templates comp=[ ]; for n=1:num_letras sem=corr2(templates{1,n},imagn); comp = [comp sem]; end vd=find(comp==max(comp)); %*-*-*-*-*-*-*-*-*-*-*-*-*- if vd==1 letter='A'; elseif vd==2 letter='a'; elseif vd==3 letter='B'; elseif vd==4 letter='b'; elseif vd==5 letter='C'; elseif vd==6 letter='c'; elseif vd==7 letter='D'; elseif vd==8 letter='d'; elseif vd==9 letter='E'; elseif vd==10 letter='e'; elseif vd==11 letter='F'; elseif vd==12 letter='f'; elseif vd==13 letter='G'; elseif vd==14 letter='g'; elseif vd==15 letter='H'; elseif vd==16 letter='h'; elseif vd==17 letter='I'; elseif vd==18 letter='i'; elseif vd==19 letter='J'; elseif vd==20 letter='j'; elseif vd==21 letter='K'; elseif vd==22 letter='k'; elseif vd==23 letter='L'; elseif vd==24 letter='l'; elseif vd==25 letter='M'; elseif vd==26 letter='m'; elseif vd==27 letter='N'; elseif vd==28 letter='n'; elseif vd==29 letter='O'; elseif vd==30 letter='o'; elseif vd==31 letter='P'; elseif vd==32 letter='p'; elseif vd==33 letter='Q'; elseif vd==34 letter='q'; elseif vd==35 letter='R'; elseif vd==36 letter='r'; elseif vd==37 letter='S'; elseif vd==38 letter='s'; elseif vd==39 letter='T'; elseif vd==40 letter='t'; elseif vd==41 letter='U'; elseif vd==42 letter='u'; elseif vd==43 letter='V'; elseif vd==44 letter='v'; elseif vd==45 letter='W'; elseif vd==46 letter='w'; elseif vd==47 letter='X'; elseif vd==48 letter='x'; elseif vd==49 letter='Y'; elseif vd==50 letter='y'; elseif vd==51 letter='Z'; elseif vd==52 letter='z';
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

roja m
roja m 2017년 11월 16일
num_letras=size(templates,2); here why we have to take 2? if u know explaination of each line of program then plz esplain me.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by