MATLAB Answers

How to read special characters using MATLAB in OCR ?

13 views (last 30 days)
Shavi
Shavi on 20 Apr 2012
Commented: Walter Roberson on 20 Dec 2018
How to read special characters using MATLAB in OCR ? Special characters like + , / | etc.
or
We can say that how to modify read_letter function which is used to read letters in OCR?
Please help me... Thanks

  2 Comments

Samreen kayani
Samreen kayani on 20 Dec 2018
%CREATE TEMPLATES
%Letter
clc;
close all;
A=imread('letters_numbers\A.bmp');B=imread('letters_numbers\B.bmp');
C=imread('letters_numbers\C.bmp');D=imread('letters_numbers\D.bmp');
E=imread('letters_numbers\E.bmp');F=imread('letters_numbers\F.bmp');
G=imread('letters_numbers\G.bmp');H=imread('letters_numbers\H.bmp');
I=imread('letters_numbers\I.bmp');J=imread('letters_numbers\J.bmp');
K=imread('letters_numbers\K.bmp');L=imread('letters_numbers\L.bmp');
M=imread('letters_numbers\M.bmp');N=imread('letters_numbers\N.bmp');
O=imread('letters_numbers\O.bmp');P=imread('letters_numbers\P.bmp');
Q=imread('letters_numbers\Q.bmp');R=imread('letters_numbers\R.bmp');
S=imread('letters_numbers\S.bmp');T=imread('letters_numbers\T.bmp');
U=imread('letters_numbers\U.bmp');V=imread('letters_numbers\V.bmp');
W=imread('letters_numbers\W.bmp');X=imread('letters_numbers\X.bmp');
Y=imread('letters_numbers\Y.bmp');Z=imread('letters_numbers\Z.bmp');
%lower case letters
a=imread('letters_numbers\a.png');b=imread('letters_numbers\b.png');
c=imread('letters_numbers\c.png');d=imread('letters_numbers\d.png');
e=imread('letters_numbers\e.png');f=imread('letters_numbers\f.png');
g=imread('letters_numbers\g.png');h=imread('letters_numbers\h.png');
i=imread('letters_numbers\i.png');j=imread('letters_numbers\j.png');
k=imread('letters_numbers\k.png');l=imread('letters_numbers\l.png');
m=imread('letters_numbers\m.png');n=imread('letters_numbers\n.png');
o=imread('letters_numbers\o.png');p=imread('letters_numbers\p.png');
q=imread('letters_numbers\q.png');r=imread('letters_numbers\r.png');
s=imread('letters_numbers\s.png');t=imread('letters_numbers\t.png');
u=imread('letters_numbers\u.png');v=imread('letters_numbers\v.png');
w=imread('letters_numbers\w.png');x=imread('letters_numbers\x.png');
y=imread('letters_numbers\y.png');z=imread('letters_numbers\z.png');
%Number
one=imread('letters_numbers\1.bmp'); two=imread('letters_numbers\2.bmp');
three=imread('letters_numbers\3.bmp');four=imread('letters_numbers\4.bmp');
five=imread('letters_numbers\5.bmp'); six=imread('letters_numbers\6.bmp');
seven=imread('letters_numbers\7.bmp');eight=imread('letters_numbers\8.bmp');
nine=imread('letters_numbers\9.bmp'); zero=imread('letters_numbers\0.bmp');
%*-*-*-*-*-*-*-*-*-*-*-
letter=[A B C D E F G H I J K L M...
N O P Q R S T U V W X Y Z];
number=[one two three four five...
six seven eight nine zero];
lowercase = [a b c d e f g h i j k ...
l m n o p q r s t u v w x y z];
character=[letter number lowercase];
templates=mat2cell(character,42,[24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 24 ...
24 24]);
save ('templates','templates')
clear all
i am facing problem while load .bmp files
can you please help me
Walter Roberson
Walter Roberson on 20 Dec 2018
What leads you to suspect that you are having trouble loading bmp files?
Are you using MS Windows? Do you have a directory named letters_numbers in your current folder? Do the noted files exist inside that folder?
The code given is not suitable for Mac or Linux: for those, all of the \ inside the file names should be changed to / . MS Windows supports / as well as \ so the code would be more general if / were to be used. But better yet would be to convert to use a named directory and fullfile()

Sign in to comment.

Answers (3)

Aliyu Abdu
Aliyu Abdu on 3 May 2012
You can check for "OCR.." in the "file exchanger", or you can simply try the code;
%CREATE TEMPLATES
%Letter
clc;
close all;
A=imread('letters_numbers\A.bmp');B=imread('letters_numbers\B.bmp');
C=imread('letters_numbers\C.bmp');D=imread('letters_numbers\D.bmp');
E=imread('letters_numbers\E.bmp');F=imread('letters_numbers\F.bmp');
G=imread('letters_numbers\G.bmp');H=imread('letters_numbers\H.bmp');
I=imread('letters_numbers\I.bmp');J=imread('letters_numbers\J.bmp');
K=imread('letters_numbers\K.bmp');L=imread('letters_numbers\L.bmp');
M=imread('letters_numbers\M.bmp');N=imread('letters_numbers\N.bmp');
O=imread('letters_numbers\O.bmp');P=imread('letters_numbers\P.bmp');
Q=imread('letters_numbers\Q.bmp');R=imread('letters_numbers\R.bmp');
S=imread('letters_numbers\S.bmp');T=imread('letters_numbers\T.bmp');
U=imread('letters_numbers\U.bmp');V=imread('letters_numbers\V.bmp');
W=imread('letters_numbers\W.bmp');X=imread('letters_numbers\X.bmp');
Y=imread('letters_numbers\Y.bmp');Z=imread('letters_numbers\Z.bmp');
%lower case letters
a=imread('letters_numbers\a.png');b=imread('letters_numbers\b.png');
c=imread('letters_numbers\c.png');d=imread('letters_numbers\d.png');
e=imread('letters_numbers\e.png');f=imread('letters_numbers\f.png');
g=imread('letters_numbers\g.png');h=imread('letters_numbers\h.png');
i=imread('letters_numbers\i.png');j=imread('letters_numbers\j.png');
k=imread('letters_numbers\k.png');l=imread('letters_numbers\l.png');
m=imread('letters_numbers\m.png');n=imread('letters_numbers\n.png');
o=imread('letters_numbers\o.png');p=imread('letters_numbers\p.png');
q=imread('letters_numbers\q.png');r=imread('letters_numbers\r.png');
s=imread('letters_numbers\s.png');t=imread('letters_numbers\t.png');
u=imread('letters_numbers\u.png');v=imread('letters_numbers\v.png');
w=imread('letters_numbers\w.png');x=imread('letters_numbers\x.png');
y=imread('letters_numbers\y.png');z=imread('letters_numbers\z.png');
%Number
one=imread('letters_numbers\1.bmp'); two=imread('letters_numbers\2.bmp');
three=imread('letters_numbers\3.bmp');four=imread('letters_numbers\4.bmp');
five=imread('letters_numbers\5.bmp'); six=imread('letters_numbers\6.bmp');
seven=imread('letters_numbers\7.bmp');eight=imread('letters_numbers\8.bmp');
nine=imread('letters_numbers\9.bmp'); zero=imread('letters_numbers\0.bmp');
%*-*-*-*-*-*-*-*-*-*-*-
letter=[A B C D E F G H I J K L M...
N O P Q R S T U V W X Y Z];
number=[one two three four five...
six seven eight nine zero];
lowercase = [a b c d e f g h i j k ...
l m n o p q r s t u v w x y z];
character=[letter number lowercase];
templates=mat2cell(character,42,[24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 24 ...
24 24 24 24 24 24 24 24 ...
24 24]);
save ('templates','templates')
clear all

  4 Comments

Show 1 older comment
Aliyu Abdu
Aliyu Abdu on 3 May 2012
It wont matter, even if I could because the size of your letters, font you're using...may not be the same with mine! One of the reasons why it's not working for your small case letters is because the original template wasn't made for your characters; hence the max. correlation "corr2" between your character and the template wont work. You may wanna consider creating your own template. To do that, you can crop your own letter(s) and save in a location(in your case "letters_numbers" folder to replace the old ones). Then use the "create_template" m-file to read the letters and store it in the template.
Shavi
Shavi on 7 May 2012
okay dats fine..
The problem is suppose we have smallcase letter 'c' and uppercase letter 'C'.
So i want to know how to differentiate between these two while matching templates?
Thanks Abdu!!
ayushi
ayushi on 26 Jun 2016
sir i can't able to find the correct example for special characters template matching method how to do the template matching of "@,+)*&%^$" all those special characters please help me to find out the correct procedure i have already cropped the templates and stored it in the folder and now i am not getting how to add those in the array when i am directly writting the special characters its showing error how to do please guide me ..thank you

Sign in to comment.


Walter Roberson
Walter Roberson on 20 Apr 2012
Mathworks does not supply any routine named "read_letter".
I see that there are multiple contributions in the MATLAB File Exchange that include routines named "read_letter". If you are using one of those, people would need to know which one in order to have a chance of providing advice.

  5 Comments

Show 2 older comments
Shavi
Shavi on 3 May 2012
Ya.. thats fine..but the problem is this that even smallcase letters are not recognized in this code..
so can u provide me small case letters template or just tell me how to draw these templates?
Also, letters like I and 1 are not recognized properly..both are taking as same.. so how do i distniguished these letters??
Walter Roberson
Walter Roberson on 3 May 2012
Is "c" a "special character", or did you switch topics?
Shavi
Shavi on 7 May 2012
no no ...
actually c is a smallcase letter 'C'.
So i want to know how to differentiate between these two while matching templates?
I know that this ques is not about special characters but i need the solution for this one too.
Thanks Roberson!!

Sign in to comment.


HanBaba
HanBaba on 25 Mar 2018
Can anyone please tell me why we have taken 42 & 24 ? any theory behind this ? I'll be waiting for your positive reply !

  1 Comment

Walter Roberson
Walter Roberson on 25 Mar 2018
This is just based upon the available training data.

Sign in to comment.


Translated by