ERROR READING SPECIAL CHARACTER USING OCR
Mostrar comentarios más antiguos
walter i have posted the code for reference of OCR
% PRINCIPAL PROGRAM
warning off %#ok<WNOFF>
% Clear all
clc, close all, clear all
% Read image
imagen=imread('image.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')
http://imgur.com/YHYFD and for this image also in need to extract score
4 comentarios
Jan
el 24 de Oct. de 2011
This is your 38th question. Yozu should know how to format the code now. Please spend the time to improve the readability. If you are in doubt, follow the "Markup help" link on this page again.
For the "clear all" see: http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301
There is a missing parenthesis in the "title('INPUT IMAGE...'" line.
We cannot guess the contents of "load templates; global templates".
As far as I remember your problem is the wrong recognition of characters. Then the shown program is not interesting, because the problem appears in the function "read_letter".
Finally this message does not contain a question anymore. If you reference another question, it would be better to insert the code there or add at least a link to the original question.
FIR
el 24 de Oct. de 2011
FIR
el 24 de Oct. de 2011
Jan
el 24 de Oct. de 2011
@FIR: Did you read my comment?
Is there a reason not to apply a proper code formatting? Bad formatted code provokes the impression, that you do not care about the readability of your question.
I've mentioned, that the problems occur in a part of the code, which you did not post: "letter=read_letter(img_r, num_letras);". Therefore answering requires wild guessing.
If you have problems with your code, "warning off" is a very bad idea. You want support of this forum, but reject the help of your local Matlab.
Please, FIR, post the relevant code using a proper formatting: Let MATLAB's editor auto-indent the code, copy it, paste it here, mark it with the mouse and hit the "{} code" button.
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 24 de Oct. de 2011
0 votos
Yes, I see you did, as you had already posted in the active question.
In my time zone, it is presently 2 AM, and you posted sometime after 1 AM here, which was after the last time I checked Answers for the evening at 12:55 AM. I am not going to look at this code at the present time: I need sleep.
1 comentario
Jan
el 24 de Oct. de 2011
Good night, Walter.
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!