function CharacterRecognitionAndSpeech()
%%
%The function uses morphological operation of hit and miss transform to
%recognize characters and uses Microsoft speech API for text to speech
%conversion.The charecter size of the integers present in the image
%should be exactly 26, otherwise it may not recognize it.
%%
%--------------------------------------------------------------------------
%Author Usman Qayyum Feb,23,2008
%Thanks to : Jahanzeb Rajput and Mohammad Fahad for character recognition
% and W.Garn for text to speech code
%--------------------------------------------------------------------------
%%
%%
text2speech( 'Start of the programme' ) %first time load the library
%%
%Z=imread('testimage1.bmp');
%Z=imread('testimage2.bmp');
Z=imread('testimage3.bmp');
SETDELAY =.6; %Set the parameter accordingly only for display latency
%%
try
figure,imshow(Z)
end
%%
A= imread ('zero.bmp');
B= imread ('one.bmp');
C= imread ('two.bmp');
D= imread ('three.bmp');
E= imread ('four.bmp');
F= imread ('five.bmp');
G= imread ('six.bmp');
H= imread ('seven.bmp');
I= imread ('eight.bmp');
J= imread ('nine.bmp');
%%
DISW = size(A,1); %Display box size
%%
%Create the structuring elements of 3*3
SE = strel('square',3);
%%
K=imdilate(A,SE);A2=K-A;
L=imdilate(B,SE);B2=L-B;
M=imdilate(C,SE);C2=M-C;
N=imdilate(D,SE);D2=N-D;
O=imdilate(E,SE);E2=O-E;
P=imdilate(F,SE);F2=P-F;
Q=imdilate(G,SE);G2=Q-G;
R=imdilate(H,SE);H2=R-H;
S=imdilate(I,SE);I2=S-I;
T=imdilate(J,SE);J2=T-J;
%-------------------------
%Hit or Miss
%-------------------------
%%
disp('The recognize digits are as follows:');
title('Recognizing the character and speaking it')
temp=bwhitmiss(Z,A,A2);
if ~isempty(nonzeros(temp))
text2speech( 'Zero' )
[r c]=find(temp==1);
disp(['0 found at loc (' num2str(c) ',' num2str(r) ')']);
hold on
plot(r,c,'--rs','LineWidth',2,'MarkerEdgeColor','r','MarkerSize',DISW)
drawnow
pause(SETDELAY)
end
%%
temp=bwhitmiss(Z,B,B2);
if ~isempty(nonzeros(temp))
text2speech( 'one' )
[r c]=find(temp==1);
disp(['1 found at loc (' num2str(c) ',' num2str(r) ')']);
hold on
plot(c,r,'--rs','LineWidth',2,'MarkerEdgeColor','r','MarkerSize',DISW)
drawnow
pause(SETDELAY)
end
%%
temp=bwhitmiss(Z,C,C2);
if ~isempty(nonzeros(temp))
text2speech( 'two' )
[r c]=find(temp==1);
disp(['2 found at loc (' num2str(c) ',' num2str(r) ')']);
hold on
plot(c,r,'--rs','LineWidth',2,'MarkerEdgeColor','r','MarkerSize',DISW)
drawnow
pause(SETDELAY)
end
%%
temp=bwhitmiss(Z,D,D2);
if ~isempty(nonzeros(temp))
text2speech( 'three' )
[r c]=find(temp==1);
disp(['3 found at loc (' num2str(c) ',' num2str(r) ')']);
hold on
plot(c,r,'--rs','LineWidth',2,'MarkerEdgeColor','r','MarkerSize',DISW)
drawnow
pause(SETDELAY)
end
%%
temp=bwhitmiss(Z,E,E2);
if ~isempty(nonzeros(temp))
text2speech( 'four' )
[r c]=find(temp==1);
disp(['4 found at loc (' num2str(c) ',' num2str(r) ')']);
hold on
plot(c,r,'--rs','LineWidth',2,'MarkerEdgeColor','r','MarkerSize',DISW)
drawnow
pause(SETDELAY)
end
%%
temp=bwhitmiss(Z,F,F2);
if ~isempty(nonzeros(temp))
text2speech( 'five' )
[r c]=find(temp==1);
disp(['5 found at loc (' num2str(c) ',' num2str(r) ')']);
hold on
plot(c,r,'--rs','LineWidth',2,'MarkerEdgeColor','r','MarkerSize',DISW)
drawnow
pause(SETDELAY)
end
%%
temp=bwhitmiss(Z,G,G2);
if ~isempty(nonzeros(temp))
text2speech( 'six' )
[r c]=find(temp==1);
disp(['6 found at loc (' num2str(c) ',' num2str(r) ')']);
hold on
plot(c,r,'--rs','LineWidth',2,'MarkerEdgeColor','r','MarkerSize',DISW)
drawnow
pause(SETDELAY)
end
%%
temp=bwhitmiss(Z,H,H2);
if ~isempty(nonzeros(temp))
text2speech( 'seven' )
[r c]=find(temp==1);
disp(['7 found at loc (' num2str(c) ',' num2str(r) ')']);
hold on
plot(c,r,'--rs','LineWidth',2,'MarkerEdgeColor','r','MarkerSize',DISW)
drawnow
pause(SETDELAY)
end
%%
temp=bwhitmiss(Z,I,I2);
if ~isempty(nonzeros(temp))
text2speech( 'eight' )
[r c]=find(temp==1);
disp(['8 found at loc (' num2str(c) ',' num2str(r) ')']);
hold on
plot(c,r,'--rs','LineWidth',2,'MarkerEdgeColor','r','MarkerSize',DISW)
drawnow
pause(SETDELAY)
end
%%
temp=bwhitmiss(Z,J,J2);
if ~isempty(nonzeros(temp))
text2speech( 'nine' )
[r c]=find(temp==1);
disp(['9 found at loc (' num2str(c) ',' num2str(r) ')']);
hold on
plot(c,r,'--rs','LineWidth',2,'MarkerEdgeColor','r','MarkerSize',DISW)
drawnow
pause(SETDELAY)
end
%%
text2speech( 'End of the programme' )
%% Text to Speech code starts here
%%
function initSpeech
loadlibrary('wgText2Speech','Speak.h'); %initialization of the library
%%
function text2speech( text )
if nargin<1
text = 'Please call this function with text';
end
try
if ~isa(text,'cell')
text = {text};
end
for k=1:length(text)
calllib('wgText2Speech','Speak',text{k}); %call library
end
catch
loadlibrary('wgText2Speech','Speak.h');
text2speech( text );
end
%%
function unloadSpeechLibrary
% unloads the speech library
unloadlibrary('wgText2Speech');