MATLAB GUI设计手写输入板

最近要做一些模式识别的课程作业,设计一个手写输入板来实现测试样本的识别,好吧,废话不多说,干货来了。
要实现的目标:
1.实现手写
2.手写的图像能够保存
大概就是下面这个样子
![界面](https://img-blog.csdn.net/20151018102952336)
实现步骤:
1.添加控件,有点类似VB那种,先创建新的GUI界面,然后把控件拖里面去就行。
![创建界面](https://img-blog.csdn.net/20151018103234403)
2.创建一些回调函数
![回调函数](https://img-blog.csdn.net/20151018103457787)
每个回调函数下面可以写函数,用到的回调函数也就那么几个,下面一一介绍
No.1 获取鼠标位置(鼠标按下)
function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global draw_enable;
global x;
global y;
draw_enable=1;
if draw_enable
    position=get(gca,'currentpoint');
    x(1)=position(1);
    y(1)=position(3);
end
No.2更新鼠标位置并画线(鼠标在按下的情况下运动)
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global draw_enable;
global x;
global y;
if draw_enable
    position=get(gca,'currentpoint');
    x(2)=position(1);
    y(2)=position(3);
    line(x,y,'EraseMode','xor','LineWidth',5,'color','b');
    x(1)=x(2);
    y(1)=y(2);
end
No.3鼠标放开后停止画线
function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global draw_enable
draw_enable=0;
No.4清除图像(按下清除按键,这里要说明一下创建回调函数的时候要在清除按钮上右键,比较快)
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes1);
cla;
NO.5保存图像(按下保存按键)
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
h=getframe(handles.axes1);
imwrite(h.cdata,'output.bmp','bmp');
cla(handles.axes1);
将上述函数都一一调用后就可以实现手写输入了,这里要感谢MATLAB中文论坛的大神,上面的源代码基本上是他们原创的,我只是整理,稍微改写添加了一下。
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值