You are on page 1of 3

function varargout = main(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function main_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = main_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgr
oundColor'))
set(hObject,'BackgroundColor','white');
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function pushbutton1_Callback(hObject, eventdata, handles)
global fid
try
delete(fid)
delete(v)
catch
end
v = videoinput('winvideo',1);
preview(v)
function pushbutton2_Callback(hObject, eventdata, handles)
global fid v
try
a=instrfind;
fclose(a);
delete(a);
catch
end
v = videoinput('winvideo',1);
fid = serial('COM1','baudrate',9600);
fopen(fid);
% Key board Key specificatin
Table = ['0' '1' '2' '3' '4' '5' '6' '7' '8' '9'
'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' '+' '-' 'B' 'W'];
%Capture image from camera
a=im2bw(getsnapshot(v));
set(handles.text1,'string','mask created');
pause(1)
set(handles.text1,'string','');
[r,c] = size(a);
% findout the inner region of the keyboard boundary
col_min = sum(a(:,1:floor(size(a,1)/2)),1);
row_min = sum(a(1:floor(size(a,2)/2),:),2);
col_max = sum(a(:,floor(size(a,2)/2):size(a,2)),1);
row_max = sum(a(floor(size(a,1)/2):size(a,1),:),2);
col_start = find(col_min<min(col_min)+10);
row_start = find(row_min<min(row_min)+10);
col_stop = find(col_max<min(col_max)+10);
row_stop = find(row_max<min(row_max)+10);
%row boundary
rr1 = row_start(end);
rr2 = row_stop(1)+floor(size(a,1)/2);
%colum boundary
cc1 = col_start(end);
cc2 = col_stop(1)+floor(size(a,2)/2);
a(1:rr1,:)=0;
a(:,1:cc1)=0;
a(rr2:size(a,1),:)=0;
a(:,cc2:size(a,2))=0;
% mask
mask = a;
%define the block width and height
H_Res = (rr2-rr1)/size(Table,1);
V_Res = (cc2-cc1)/size(Table,2);
%--------------------------------------------------------------------------
%start infinite loop for finding the ket pressed
result='';
while 1
try
% get the image from the camera
b = im2bw(getsnapshot(v));
b=b.*mask;
% whiten the reion except the handregion inside the keyboard boundary
b(1:rr1+10,:)=1;
b(rr2-10:size(a,1),:)=1;
b(:,1:cc1+10)=1;
b(:,cc2-10:size(a,2))=1;
s_r = sum(b,2);
% find the row and column of the key pressed
indbr = find(s_r<size(b,2)-20);
indbc = find(b(indbr(1),:)==0);
%find out the key pressed
row = ceil((indbr(1)-rr1)/H_Res);
col = ceil((indbc(1)-cc1)/V_Res);
result = Table(row,col);
% display the key pressed in the GUI along with prevoius pressed key value
s
set(handles.text1,'string',strcat(get(handles.text1,'string'),result));
% feed the value to the dll to perform virtual keypad simulation
mes(result)
% send to the PIC microcontroller board for displaying the detecred key on
LCD
fprintf(fid,'%c',result);
catch
continue;
end
end

function pushbutton3_Callback(hObject, eventdata, handles)


% clear LCD on exit
% fprintf(fid,'%c','C');
%terminate GUI
delete(main)