MATLAB GUI设计手写输入板
2015-10-18 10:43
435 查看
最近要做一些模式识别的课程作业,设计一个手写输入板来实现测试样本的识别,好吧,废话不多说,干货来了。 要实现的目标: 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中文论坛的大神,上面的源代码基本上是他们原创的,我只是整理,稍微改写添加了一下。
相关文章推荐
- 一步一步跟我学易语言之第二个易程序菜单设计
- 基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版
- C#中设计、使用Fluent API
- 基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版
- winform异型不规则界面设计的实现方法
- 解析在main函数之前调用函数以及对设计的作用详解
- JavaScript 组件之旅(一)分析和设计
- C# 事件的设计与使用深入理解
- 大型网站设计注意事项大全
- Android中设置只有程序第一次运行才显示的界面实现思路
- Android中的脑残设计总结
- hta 实现的五子棋界面
- java和matlab画多边形闭合折线图示例讲解
- android开发之欢迎界面的小例子
- C#中载入界面的常用方法
- C#调用Matlab生成的dll方法的详细说明
- Android判断现在所处界面是否为home主桌面的方法
- android 引导界面的实现方法
- 用户权限管理设计[图文说明]
- 从java中调用matlab详细介绍