该课题为基于Matlab的手写数字识别系统。在一张图像上面手写了很多手写数字。利用鼠标进行框定你所要识别的数字区域。裁剪灰度化处理,二值化处理。提取数字特征。利用神经网络的方法进行识别。带有人际交互界面,需要在人际交互界面的基础上进行相应拓展。
GUI设计图:
gui实现代码:
function varargout = charGUI(varargin)
%窗体初始化代码
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @charGUI_OpeningFcn, ...
'gui_OutputFcn', @charGUI_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
% End initialization code - DO NOT EDIT
% --- Executes just before charGUI is made visible.
function charGUI_OpeningFcn(hObject, eventdata, handles, varargin)
load data;
assignin('base','net',net);
handles.output = hObject;
set(gcf,'name','联系微信:matlab1998 ');
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = charGUI_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- 装入图像.
function pbLoad_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.bmp';'*.jpg';'*.gif';'*.*'}, '装入图像文件');
S = imread([pathname,filename]);
axes(handles.axes1);
imshow(S);
handles.S = S;
guidata(hObject, handles);
% --- 选择识别区域.
function pbSelect_Callback(hObject, eventdata, handles)
S = handles.S;
axes(handles.axes1);
img_crop = imcrop(S);
axes(handles.axes2);
imshow(img_crop);
handles.img_crop = img_crop;
guidata(hObject, handles);
% --- 图像预处理.
function pbPreprocess_Callback(hObject, eventdata, handles)
img_crop = handles.img_crop;
imgGray = rgb2gray(img_crop);
bw = im2bw(img_crop,graythresh(imgGray));
axes(handles.axes3);
imshow(bw);
bw2 = edu_imgcrop(bw);
axes(handles.axes4);
imshow(bw2);
handles.bw2 = bw2;
guidata(hObject, handles);
% --- 特征抽取.
function pbExtract_Callback(hObject, eventdata, handles)
msgbox('后续思路:微信:matlab1998')
return
% -字符识别.
function pbRecognize_Callback(hObject, eventdata, handles)
msgbox('后续思路:微信:matlab1998')
return
% --- Executes on button press in pbNN.
function pbNN_Callback(hObject, eventdata, handles)
function editNN_Callback(hObject, eventdata, handles)
function editNN_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function editResult_Callback(hObject, eventdata, handles)
function editResult_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
主程序代码:
%%训练神经网络
%% Read the image
I = imread('sample.bmp');
%% Image Preprocessing
img = edu_imgpreprocess(I);
for cnt = 1:50
bw2 = edu_imgcrop(img{cnt});
charvec = edu_imgresize(bw2);
out(:,cnt) = charvec;
end
%% Create Vectors for the components (objects)
P = out(:,1:40);
T = [eye(10) eye(10) eye(10) eye(10)];
Ptest = out(:,41:50);
%% Creating and training of the Neural Network
net = edu_createnn(P,T);
%% Testing the Neural Network
[a,b]=max(sim(net,Ptest));
disp(b);
运行步骤:
基于BP神经网络的手写数字识别
运行方式:
matlab命令行窗口输入guide回车,选择文件夹内的charGUI.fig文件运行即可。
char3.m是神经网络训练程序,训练样本是sample.bmp
完整源码下载: