




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、基于VC 手写数字识别程序设计 ;/计算当前画板中数字的特征值GetTeZheng ;/首先判断当前的数字类型是否已经在模板中for int j 0;j i;j+ cf.Read void * temp,sizeof TEZHENG ;/从文件cf的当前位置读数据for int k 0;k 15;k+ if temp- VHDerectionk! mytezheng- VHDerectionk /判断水平特征break; if k 15 && temp- decon mytezheng- decon && temp- lenfirst mytezheng- le
2、nfirst && temp- lenth1 mytezheng- lenth1 && temp- lenth mytezheng- lenth && temp- lenend mytezheng- lenend char s20;sprintf s,"您输入的是:%d,数据已有",temp- value ;AfxMessageBox s ;break; /说明该数字类型不在模板中if j i if inputdlg.DoModal IDOK /判断数字输入对话框中的两个数字是否相同if inputdlg.m_value1!
3、inputdlg.m_value2 AfxMessageBox "您的输入有误,n请重新输入" ; /相同,则将新的数字类型写入模板文件中else GetTeZheng ;try mytezheng- value inputdlg.m_value1;cf.SeekToEnd ;/定位当前文件指针到文件尾cf.Write &mytezheng- value,sizeof signed char ;/将文件数据写入当前文件位置cf.Write mytezheng- VHDerection,sizeof signed char *15 ;cf.Write &myt
4、ezheng- lenth1,sizeof signed char ;cf.Write &mytezheng- lenth,sizeof signed char ;cf.Write &mytezheng- decon,sizeof signed char ;cf.Write &mytezheng- lenfirst,sizeof signed char ;cf.Write &mytezheng- lenend,sizeof signed char ; catch CFileException *e /Alert user to errore- Delete ;
5、/end try-catch /end if-else /end if /end ifreturn; 4、识别程序void CPatternView:OnRecognize void cf.SeekToBegin ;int nFileSize cf.GetLength ;int i nFileSize/sizeof TEZHENG ;TEZHENG *temp;temp TEZHENG * malloc sizeof TEZHENG ;/计算特征值GetTeZheng ;/在模板文件中寻找,是否有与当前特征值相同的for int j 0;j i;j+ cf.Read void * temp,s
6、izeof TEZHENG ;for int k 0;k 15;k+ if temp- VHDerectionk! mytezheng- VHDerectionk break; /找到识别结果if k 15 && temp- decon mytezheng- decon && temp- lenfirst mytezheng- lenfirst && temp- lenth1 mytezheng- lenth1 && temp- lenth mytezheng- lenth && temp- lenend myte
7、zheng- lenend char s20;sprintf s,"您输入的是:%d",temp- value ;AfxMessageBox s ;break;/搜索结束 if j i AfxMessageBox "抱歉,无法识别" ; return; 5、清除程序void CPatternView:OnClear void CDC *pDC GetDC ;/*检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备上下文环境中绘图*/CBrush BrushBoard RGB 255, 255 , 255
8、;CBrush pOldBrush;pDC- PatBlt 8,8,176,240, PATCOPY ;for int i 0;i 16;i+ for int j 0;j 16;j+ bitgraphij 0;mouseDown 0;mytime 0;for i 0;i 100;i+ mypointi.x -1;mypointi.y -1; curvalue -1;mytezheng- value -1;mytezheng- lenth 0;mytezheng- lenth1 0;for i 0;i 15;i+ mytezheng- VHDerectioni -1;mytezheng- dec
9、on 0;return; 6、特征提取程序void CPatternView:GetTeZheng int p,q;int i 0;/从第一个点到最后一个点for int j 0;j mytime-1;j+ if i 0 mytezheng- lenth1+; if i 13 AfxMessageBox "内存溢出,呵呵",NULL,NULL ;return; /判断两个相邻点的距离p mypointj+1.x-mypointj.x * mypointj+1.x-mypointj.x ;q mypointj+1.y-mypointj.y * mypointj+1.y-myp
10、ointj.y ;/如果不是8连接,则为断裂点或者是写的太快if p 1 | q 1 mytezheng- decon 1;j+;i+;if j+1 mytime-1 AfxMessageBox "您可能写得太快了,呵呵",NULL,NULL ;return; if mypointj+1.x mypointj.x mytezheng- VHDerectioni 1;else if mypointj+1.y mypointj.y mytezheng- VHDerectioni 2;else if mypointj+1.x mypointj.x mytezheng- VHDer
11、ectioni 3;else mytezheng- VHDerectioni 4;mytezheng- lenth 1; /尽量保持目前的方向else if j 0 if mypoint1.x mypoint0.x mytezheng- VHDerection0 1;else if mypoint1.y mypoint0.y mytezheng- VHDerection0 2;else if mypoint1.x mypoint0.x mytezheng- VHDerection0 3;else mytezheng- VHDerection0 4;mytezheng- lenth 1; /en
12、d ifelse switch mytezheng- VHDerectioni case 1:if mypointj+1.x mypointj.x i+;mytezheng- lenth 1;if mypointj+1.y mypointj.y mytezheng- VHDerectioni 2;else if mypointj+1.y mypointj.y mytezheng- VHDerectioni 4;else mytezheng- VHDerectioni 3; else mytezheng- lenth+;break;case 2:if mypointj+1.y mypointj.
13、y i+;mytezheng- lenth 1;if mypointj+1.x mypointj.x mytezheng- VHDerectioni 3;else if mypointj+1.x mypointj.x mytezheng- VHDerectioni 1;else mytezheng- VHDerectioni 4; else mytezheng- lenth+;break;case 3:if mypointj+1.x mypointj.x i+;mytezheng- lenth 1;if mypointj+1.y mypointj.y mytezheng- VHDerectio
14、ni 4;else if mypointj+1.y mypointj.y mytezheng- VHDerectioni 2;else mytezheng- VHDerectioni 1; else mytezheng- lenth+;break;case 4:if mypointj+1.y mypointj.y i+;mytezheng- lenth 1;if mypointj+1.x mypointj.x mytezheng- VHDerectioni 1;else if mypointj+1.x mypointj.x mytezheng- VHDerectioni 3;else myte
15、zheng- VHDerectioni 2; else mytezheng- lenth+;break;default:break; /end switch /end else /end else /end forfor p 0;p 4;p+ for q p+1;q mytime;q+ if mypointp mypointq break; if q mytime break; if p 4 mytezheng- lenfirst 2;elsemytezheng- lenfirst 1;for p mytime-1;p mytime-6;p- for q p-1;q 0;q- if mypoi
16、ntp mypointq break; if q 0 break; if p mytime-6 mytezheng- lenend 2;else mytezheng- lenend 1;if mytezheng- lenth 0&& mytezheng- lenth 4 mytezheng- lenth 1;else mytezheng- lenth 2;if mytezheng- lenth1 4 mytezheng- lenth1 2;else mytezheng- lenth1 1; 7、鼠标左键按下程序void CPatternView:OnLButtonDown UI
17、NT nFlags, CPoint point mouseDown 1;if point.x 220 && point.x 270 && point.y 20 && point.y 40 OnStudy ; if point.x 220 && point.x 270 && point.y 80 && point.y 100 OnRecognize ; if point.x 220 && point.x 270 && point.y 140 && poi
18、nt.y 160 OnClear ; CView:OnLButtonDown nFlags, point ; 8、鼠标移动程序void CPatternView:OnMouseMove UINT nFlags, CPoint point / TODO: Add your message handler code here and/or call defaultCDC *pDC GetDC ;/*检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备上下文环境中绘图*/CRgn Rgn;/CRgn类封装了一个Windows图形设备接口(GDI)区域
19、/限制在输入区域的范围内Rgn.CreateRectRgn startX,startY,startX+stepX*16-1,startY+stepY*16-1 ;/*用一个矩形区域来初始化一个CRgn对象*/pDC- SelectClipRgn &Rgn ;/*选择一个区域作为指定设备环境的当前剪切区域*/if point.x startX && point.x startX+stepX*16 && point.y startY && point.y startY+stepY*16 HCURSOR m_HCross;m_HCross Af
20、xGetApp - LoadStandardCursor IDC_CROSS ;:SetCursor m_HCross ; int i point.x-startX /stepX;int j point.y-startY /stepY;if mouseDown 1 && point.x startX && point.x startX+stepX*16 && point.y startY && point.y startY+stepY*16 CBrush Brush RGB 0, 0 , 0 ;/ Select the brush into the device context .CBrush* pOldBrush pDC- SelectObject &Brush ;pDC- Ellipse point.x-6,point.y-6,point.x+6,point.y+6 ;pDC- SelectObject pOldBrush ;/保
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 新课标北师大版小学科学四年级下册期末试卷含参考答案
- 第2章答案章节课件
- 《这里的黎明静悄悄》测试题带答案
- 安全气囊专项测试卷含答案
- 2025届内蒙古翁牛特旗乌丹第六中学英语七下期中达标检测模拟试题含答案
- 单根ZnO-Ga微米带激光光源的构筑与性能研究
- 城镇社区失能老人家庭照护者成长小组动力发展实践研究
- 基于生物信息学技术的鱼皮抗氧化肽生物活性构效关系研究
- 天然环缩肽fusarihexins、petrosamides和xylaroamide A及其类似物的合成与抗癌活性研究
- 董事高管责任险、信息披露与债券利差
- 【完美排版】山东科技出版社二年级下册综合实践活动教案
- 公共政策学(第三版)-课件
- 齐鲁医学Lisfranc-损伤
- 大型钢网架整体提升施工工法
- 干熄焦炉内固_气流动与传热数值模拟毕业论文
- 公司股东变更登记申请书(一变一)
- 供应链金融业务工作开展情况总结汇报
- 基于motor的六相电机绕组分相设置
- 一年级数学学困生转化典型案例
- 广西壮族自治区医院大全
- 电子时钟 Multisim仿真
评论
0/150
提交评论