`

识别简单的数字,字母的手写识别框架

 
阅读更多
  1. //patternDlg.cpp:implementationfile
  2. //
  3. #include"stdafx.h"
  4. #include"pattern.h"
  5. #include"patternDlg.h"
  6. #include"Afxwin.h"
  7. #include"Afxdlgs.h"
  8. #include"winuser.h"
  9. #include"Store.h"
  10. #include<STDIO.H>
  11. //#define_MBCS
  12. #ifdef_DEBUG
  13. #definenewDEBUG_NEW
  14. #undefTHIS_FILE
  15. staticcharTHIS_FILE[]=__FILE__;
  16. #endif
  17. #include<WINDOWS.H>
  18. #include<MATH.H>
  19. #defineStartx30
  20. #defineStarty190
  21. #definewid192
  22. #definelon192
  23. #defineyu3//2area
  24. #defineyu15//doudong
  25. #defineyu24
  26. intnum,Time;
  27. intxmax,ymax,xmin,ymin;//随时纪录书写过程中的书写范围
  28. //存储书写笔迹的坐标序列,按笔划存储,每个笔划最多300个点
  29. //每个字最多15个笔划
  30. struct
  31. {
  32. intx;
  33. inty;
  34. }store[15][300];
  35. //备份的序列
  36. struct
  37. {
  38. intx;
  39. inty;
  40. }storeback[15][300];
  41. struct
  42. {
  43. inttotal;//总的笔划数
  44. charzifu[2];//代表字符
  45. intdian[15];//每个笔划的点数
  46. struct{
  47. intrelate;//相对前点特征
  48. intregion;//全局位置特征
  49. intarc;//过渡带特征
  50. }detail[15][20];//15个笔划上的特征点,每个笔划20个特征点
  51. }tez[2002];
  52. struct
  53. {
  54. inttotal;
  55. intdian[15];
  56. struct
  57. {
  58. intrelate;
  59. intregion;
  60. intarc;
  61. }detail[15][20];
  62. }test;//意义同上,为测试点的结构
  63. intqueue[50];
  64. intqueue1[40];
  65. intzong;
  66. /////////////////////////////////////////////////////////////////////////////
  67. //CAboutDlgdialogusedforAppAbout
  68. classCAboutDlg:publicCDialog
  69. {
  70. public:
  71. CAboutDlg();
  72. //DialogData
  73. //{{AFX_DATA(CAboutDlg)
  74. enum{IDD=IDD_ABOUTBOX};
  75. //}}AFX_DATA
  76. //ClassWizardgeneratedvirtualfunctionoverrides
  77. //{{AFX_VIRTUAL(CAboutDlg)
  78. protected:
  79. virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport
  80. //}}AFX_VIRTUAL
  81. //Implementation
  82. protected:
  83. //{{AFX_MSG(CAboutDlg)
  84. //}}AFX_MSG
  85. DECLARE_MESSAGE_MAP()
  86. };
  87. CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD)
  88. {
  89. //{{AFX_DATA_INIT(CAboutDlg)
  90. //}}AFX_DATA_INIT
  91. }
  92. voidCAboutDlg::DoDataExchange(CDataExchange*pDX)
  93. {
  94. CDialog::DoDataExchange(pDX);
  95. //{{AFX_DATA_MAP(CAboutDlg)
  96. //}}AFX_DATA_MAP
  97. }
  98. BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
  99. //{{AFX_MSG_MAP(CAboutDlg)
  100. //Nomessagehandlers
  101. //}}AFX_MSG_MAP
  102. END_MESSAGE_MAP()
  103. /////////////////////////////////////////////////////////////////////////////
  104. //CPatternDlgdialog
  105. CPatternDlg::CPatternDlg(CWnd*pParent/*=NULL*/)
  106. :CDialog(CPatternDlg::IDD,pParent)
  107. {
  108. //{{AFX_DATA_INIT(CPatternDlg)
  109. //}}AFX_DATA_INIT
  110. //NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32
  111. m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  112. }
  113. voidCPatternDlg::DoDataExchange(CDataExchange*pDX)
  114. {
  115. CDialog::DoDataExchange(pDX);
  116. //{{AFX_DATA_MAP(CPatternDlg)
  117. DDX_Control(pDX,IDC_EDIT2,m_edit2);
  118. DDX_Control(pDX,IDC_EDIT1,m_edit1);
  119. DDX_Control(pDX,IDC_BUTTON4,m_escape);
  120. DDX_Control(pDX,IDC_BUTTON3,m_clear);
  121. DDX_Control(pDX,IDC_BUTTON1,m_recog);
  122. DDX_Control(pDX,IDC_BUTTON2,m_study);
  123. //}}AFX_DATA_MAP
  124. }
  125. BEGIN_MESSAGE_MAP(CPatternDlg,CDialog)
  126. //{{AFX_MSG_MAP(CPatternDlg)
  127. ON_WM_SYSCOMMAND()
  128. ON_WM_PAINT()
  129. ON_WM_QUERYDRAGICON()
  130. ON_BN_CLICKED(IDC_BUTTON4,OnEsp)
  131. ON_BN_CLICKED(IDC_BUTTON1,OnRecog)
  132. ON_WM_MOUSEMOVE()
  133. ON_BN_CLICKED(IDC_BUTTON3,OnClear)
  134. ON_BN_CLICKED(IDC_BUTTON2,OnStudy)
  135. ON_WM_LBUTTONUP()
  136. ON_WM_LBUTTONDOWN()
  137. ON_COMMAND(ID_EXIT_MENU,OnExitMenu)
  138. ON_COMMAND(ID_ABOUT_MENU,OnAboutMenu)
  139. ON_COMMAND(ID_SAVE_MENU,OnSaveMenu1)
  140. ON_COMMAND(ID_OPEN_MENU,OnOpenMenu)
  141. //}}AFX_MSG_MAP
  142. END_MESSAGE_MAP()
  143. /////////////////////////////////////////////////////////////////////////////
  144. //CPatternDlgmessagehandlers
  145. BOOLCPatternDlg::OnInitDialog()
  146. {
  147. CFilecf;
  148. CDialog::OnInitDialog();
  149. mouseDown=0;
  150. inti,j,k;
  151. //将每个笔划上坐标初始化为空
  152. for(i=0;i<15;i++)
  153. {
  154. for(j=0;j<300;j++)
  155. {
  156. store[i][j].x=-1;
  157. store[i][j].y=-1;
  158. }
  159. }
  160. for(i=0;i<15;i++)
  161. {
  162. for(j=0;j<300;j++)
  163. {
  164. storeback[i][j].x=-1;
  165. storeback[i][j].y=-1;
  166. }
  167. }
  168. for(i=0;i<10;i++)
  169. {
  170. tez[i].total=-1;
  171. for(j=0;j<15;j++)
  172. tez[i].dian[j]=-1;
  173. for(j=0;j<15;j++)
  174. {
  175. for(k=0;k<20;k++)
  176. {
  177. tez[i].detail[j][k].relate=0;
  178. tez[i].detail[j][k].arc=0;
  179. tez[i].detail[j][k].region=0;
  180. }
  181. }
  182. }
  183. Time=0;
  184. num=0;
  185. zong=-1;//tez下标
  186. xmax=0;
  187. ymax=0;
  188. xmin=31;
  189. ymin=31;
  190. for(i=0;i<50;i++)
  191. queue[i]=-1;
  192. for(i=0;i<40;i++)
  193. queue1[i]=-1;
  194. test.total=-1;
  195. for(j=0;j<15;j++)
  196. test.dian[j]=-1;
  197. for(j=0;j<15;j++)
  198. {
  199. for(k=0;k<20;k++)
  200. {
  201. test.detail[j][k].relate=0;
  202. test.detail[j][k].arc=0;
  203. test.detail[j][k].region=0;
  204. }
  205. }
  206. //Add"About..."menuitemtosystemmenu.
  207. //IDM_ABOUTBOXmustbeinthesystemcommandrange.
  208. ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);
  209. ASSERT(IDM_ABOUTBOX<0xF000);
  210. CMenu*pSysMenu=GetSystemMenu(FALSE);
  211. if(pSysMenu!=NULL)
  212. {
  213. CStringstrAboutMenu;
  214. strAboutMenu.LoadString(IDS_ABOUTBOX);
  215. if(!strAboutMenu.IsEmpty())
  216. {
  217. pSysMenu->AppendMenu(MF_SEPARATOR);
  218. pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);
  219. }
  220. }
  221. //Settheiconforthisdialog.Theframeworkdoesthisautomatically
  222. //whentheapplication'smainwindowisnotadialog
  223. SetIcon(m_hIcon,TRUE);//Setbigicon
  224. SetIcon(m_hIcon,FALSE);//Setsmallicon
  225. //TODO:Addextrainitializationhere
  226. if(cf.Open("mydata.dat",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite)==NULL){
  227. AfxMessageBox("打开文件失败,/n您最好退出程序");}
  228. returnTRUE;//returnTRUEunlessyousetthefocustoacontrol
  229. }
  230. voidCPatternDlg::OnSysCommand(UINTnID,LPARAMlParam)
  231. {
  232. if((nID&0xFFF0)==IDM_ABOUTBOX)
  233. {
  234. CAboutDlgdlgAbout;
  235. dlgAbout.DoModal();
  236. }
  237. else
  238. {
  239. CDialog::OnSysCommand(nID,lParam);
  240. }
  241. }
  242. //Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow
  243. //todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,
  244. //thisisautomaticallydoneforyoubytheframework.
  245. voidCPatternDlg::OnPaint()
  246. {
  247. CPaintDCdc(this);
  248. HBRUSHhB;
  249. hB=CreateSolidBrush(RGB(255,255,255));
  250. SelectObject(dc,hB);
  251. Rectangle(dc,Startx,Starty,Startx+wid-1,Starty+lon-1);
  252. DeleteObject(hB);
  253. if(IsIconic())
  254. {
  255. //devicecontextforpainting
  256. SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);
  257. //Centericoninclientrectangle
  258. intcxIcon=GetSystemMetrics(SM_CXICON);
  259. intcyIcon=GetSystemMetrics(SM_CYICON);
  260. CRectrect;
  261. GetClientRect(&rect);
  262. intx=(rect.Width()-cxIcon+1)/2;
  263. inty=(rect.Height()-cyIcon+1)/2;
  264. //Drawtheicon
  265. dc.DrawIcon(x,y,m_hIcon);
  266. }
  267. else
  268. {
  269. CDialog::OnPaint();
  270. }
  271. }
  272. //Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags
  273. //theminimizedwindow.
  274. HCURSORCPatternDlg::OnQueryDragIcon()
  275. {
  276. return(HCURSOR)m_hIcon;
  277. }
  278. voidCPatternDlg::OnEsp()
  279. {
  280. OnOK();
  281. }
  282. //识别函数
  283. voidCPatternDlg::OnRecog()
  284. {
  285. intj1,k1,m1,n1,x,y,xmod,ymod;//xmod,ymod;
  286. intflagok2=0;
  287. chars[20];
  288. DealData();
  289. //安次序检验,有点下标数
  290. for(j1=0;j1<=zong&&test.total>=0&&flagok2==0;j1++)
  291. {
  292. if(tez[j1].total==test.total)//如果总条数相等
  293. {
  294. for(k1=0;k1<=test.total;k1++)
  295. {
  296. if(test.dian[k1]!=tez[j1].dian[k1])
  297. break;
  298. }
  299. if(k1>test.total)
  300. //每条得点数相同
  301. {
  302. for(m1=0;m1<=test.total;m1++)//每条
  303. {
  304. for(n1=0;n1<=test.dian[m1];n1++)//每点
  305. {
  306. xmod=2*(tez[j1].detail[m1][n1].region%8);//8等分
  307. ymod=2*((int)tez[j1].detail[m1][n1].region/8);
  308. x=test.detail[m1][n1].region%16;
  309. y=(int)test.detail[m1][n1].region/16;//5/16
  310. if((test.detail[m1][n1].relate!=tez[j1].detail[m1][n1].relate
  311. &&(test.detail[m1][n1].relate-10*(int)(test.detail[m1][n1].relate/10))!=tez[j1].detail[m1][n1].relate
  312. &&(int)(test.detail[m1][n1].relate/10)!=tez[j1].detail[m1][n1].relate)
  313. ||((tez[j1].detail[m1][n1].arc!=test.detail[m1][n1].arc)&&(test.total<4)&&(test.dian[m1]<4))
  314. ||((x<XMOD-3||X>xmod+3)||(y<YMOD-3||Y>ymod+3)))//shi为total+1
  315. break;
  316. }
  317. if(n1<=test.dian[m1])
  318. break;
  319. }
  320. if(m1>test.total)
  321. {
  322. flagok2=1;
  323. sprintf(s,"输入正确,可识别,为:%s,在字库%d个",tez[j1].zifu,j1);
  324. AfxMessageBox(s);
  325. m_edit1.ReplaceSel(tez[j1].zifu);
  326. OnClear();
  327. }
  328. }
  329. }
  330. }
  331. if(flagok2==0)
  332. {
  333. AfxMessageBox("字库不足或输入不规范,无法识别,请学习");
  334. OnRecogch();
  335. }
  336. }
  337. //学习函数
  338. voidCPatternDlg::OnStudy()
  339. {
  340. intj1,k1,m1,n1,k,m,xmod,ymod,x,y;//j1代表字典中的一个字,k表示笔划,m表示一个点
  341. CStringz1;
  342. inti,j;
  343. intflagok1=0;//o无法识别,1可识别,已经识别出结果
  344. chars[30];
  345. Inputdialoginputdlg;
  346. //处理数据
  347. DealData();
  348. if(test.total==-1)
  349. {
  350. AfxMessageBox("没有笔迹输入,/n请重示");
  351. }
  352. for(j1=0;j1<=zong&&test.total!=-1;j1++)
  353. {
  354. if(flagok1==1)
  355. break;
  356. if(tez[j1].total==test.total&&flagok1==0)//总笔划相等
  357. {
  358. for(k1=0;k1<=test.total;k1++)
  359. {
  360. if(test.dian[k1]!=tez[j1].dian[k1])
  361. break;
  362. }
  363. if(k1>test.total)//每笔划点数相同下
  364. {
  365. for(m1=0;m1<=test.total;m1++)
  366. {
  367. for(n1=0;n1<=test.dian[m1];n1++)
  368. {
  369. if((test.detail[m1][n1].relate!=tez[j1].detail[m1][n1].relate
  370. &&(test.detail[m1][n1].relate%10)!=tez[j1].detail[m1][n1].relate
  371. &&((int)(test.detail[m1][n1].relate/10))!=tez[j1].detail[m1][n1].relate)
  372. ||(tez[j1].detail[m1][n1].arc!=test.detail[m1][n1].arc))//shi为total+1
  373. break;
  374. xmod=2*(tez[j1].detail[m1][n1].region%8);//8等分
  375. ymod=2*((int)tez[j1].detail[m1][n1].region/8);
  376. x=test.detail[m1][n1].region%16;
  377. y=(int)test.detail[m1][n1].region/16;
  378. if((x<XMOD-1||X>xmod+1)||(y<YMOD-1||Y>ymod+1))
  379. break;//3/16
  380. }//对一个笔划的判断,tezheng不等,跳出n
  381. if(n1<=test.dian[m1])
  382. break;//cibihua不等,跳出m循环
  383. }
  384. if(m1>test.total&&k1>test.total)//当前库字与输入相符合
  385. {
  386. flagok1=1;
  387. sprintf(s,"您输入的是:%s,数据已有",tez[j1].zifu);
  388. AfxMessageBox(s);
  389. m_edit1.ReplaceSel(tez[j1].zifu);
  390. OnClear();
  391. }
  392. }
  393. }
  394. }
  395. if(flagok1==0&&test.total>=0&&inputdlg.DoModal()==IDOK)//shuruzifu
  396. {
  397. if(inputdlg.m_input1!=inputdlg.m_input2
  398. ||inputdlg.m_input1==""||inputdlg.m_input1=="")
  399. {
  400. AfxMessageBox("您的输入有误(不等或空格),/n请重新输入");
  401. for(i=0;i<50;i++)
  402. queue[i]=-1;
  403. for(i=0;i<40;i++)
  404. queue1[i]=-1;
  405. test.total=-1;
  406. for(j=0;j<15;j++)
  407. test.dian[j]=-1;
  408. for(j=0;j<15;j++)
  409. {
  410. for(k=0;k<20;k++)
  411. {
  412. test.detail[j][k].relate=0;
  413. test.detail[j][k].region=0;
  414. }
  415. }
  416. }
  417. else
  418. {
  419. zong++;
  420. sprintf(tez[zong].zifu,"%s",inputdlg.m_input1);
  421. tez[zong].total=test.total;
  422. for(i=0;i<=test.total;i++)
  423. {
  424. tez[zong].dian[i]=test.dian[i];
  425. for(j=0;j<=test.dian[i];j++)
  426. {
  427. tez[zong].detail[i][j].relate=(test.detail[i][j].relate%10);
  428. tez[zong].detail[i][j].arc=test.detail[i][j].arc;
  429. x=(int)(test.detail[i][j].region%16)/2;
  430. y=(int)(test.detail[i][j].region/16)/2;
  431. tez[zong].detail[i][j].region=8*y+x;
  432. }
  433. }
  434. OnSaveMenu();
  435. if(zong>=2000)
  436. AfxMessageBox("版本太低,容量受限,Sorry!");
  437. m_edit1.ReplaceSel(inputdlg.m_input1);
  438. OnClear();
  439. }//zongdang前库下标
  440. }
  441. }
  442. voidCPatternDlg::OnLButtonDown(UINTnFlags,CPointpoint)
  443. {
  444. mouseDown=1;
  445. CWnd::OnLButtonDown(nFlags,point);
  446. }
  447. //鼠标左键抬起
  448. voidCPatternDlg::OnLButtonUp(UINTnFlags,CPointpoint)
  449. {
  450. mouseDown=0;
  451. if(store[num][Time-1].x>=0&&Time>0)
  452. {
  453. num++;
  454. Time=0;
  455. }
  456. if(num>=14)
  457. {
  458. AfxMessageBox("写入有误(笔划太多)",NULL,NULL);
  459. OnClear();
  460. }
  461. CWnd::OnLButtonUp(nFlags,point);
  462. }
  463. //鼠标移动事件,模拟手写笔输入
  464. voidCPatternDlg::OnMouseMove(UINTnFlags,CPointpoint)
  465. {
  466. //TODO:Addyourmessagehandlercodehereand/orcalldefault
  467. intx,y;
  468. CBrushBrush(RGB(0,0,255));
  469. CBrush*pOldBrush;
  470. CDC*pDC=GetDC();
  471. CRgnRgn;
  472. Rgn.CreateRectRgn(Startx,Starty,Startx+wid-1,Starty+lon-1);
  473. pDC->SelectClipRgn(&Rgn);
  474. if((point.x>=Startx)&&(point.x<STARTX+WID)&&(POINT.Y>=Starty)
  475. &&(point.y<STARTY+LON))m_HCross="AfxGetApp()-"m_HCross;HCURSOR{>LoadStandardCursor(IDC_CROSS);
  476. SetCursor(m_HCross);
  477. }
  478. if((mouseDown==1)&&(point.x>=Startx)&&(point.x<STARTX+WID)&&(point.y>=Starty)&&(point.y<STARTY+LON)){pOldBrush="pDC-"CBrush*.contextdevicetheintobrushSelect>SelectObject(&Brush);
  479. pDC->Ellipse(point.x-4,point.y-4,point.x+4,point.y+4);
  480. pDC->SelectObject(pOldBrush);
  481. x=(int)(point.x-Startx)*32/wid;
  482. y=(int)(point.y-Starty)*32/lon;
  483. if(Time==0)
  484. {
  485. store[num][Time].x=x;
  486. store[num][Time].y=y;
  487. Time++;
  488. if(y>ymax)
  489. ymax=y;
  490. if(y<YMIN)if(xymin="y;">xmax)
  491. xmax=x;
  492. if(x<XMIN){if(yTime++;store[num][Time].y="y;"store[num][Time].x="x;"if(x!="store[num][Time-1].x||y!=store[num][Time-1].y)"else}xmin="x;">ymax)
  493. ymax=y;
  494. if(y<YMIN)if(xymin="y;">xmax)
  495. xmax=x;
  496. if(x<XMIN)}xmin="x;"if(Time>=300)
  497. {
  498. AfxMessageBox("当前笔划写入有误(太多)",NULL,NULL);
  499. OnClear();
  500. }
  501. }
  502. ReleaseDC(pDC);
  503. DeleteObject(pOldBrush);
  504. DeleteObject(Rgn);
  505. DeleteObject(Brush);
  506. CWnd::OnMouseMove(nFlags,point);
  507. }
  508. //清空画板
  509. voidCPatternDlg::OnClear()
  510. {
  511. inti,j,k;
  512. CDC*pDC=GetDC();
  513. pDC->PatBlt(Startx,Starty,wid,lon,PATCOPY);
  514. ReleaseDC(pDC);
  515. mouseDown=0;
  516. for(i=0;i<15;i++){
  517. for(j=0;j<300;j++)
  518. {
  519. store[i][j].x=-1;
  520. store[i][j].y=-1;
  521. }
  522. }
  523. for(i=0;i<15;i++){
  524. for(j=0;j<300;j++)
  525. {
  526. storeback[i][j].x=-1;
  527. storeback[i][j].y=-1;
  528. }
  529. }
  530. Time=0;
  531. num=0;
  532. xmax=0;
  533. ymax=0;
  534. xmin=32;
  535. ymin=32;
  536. for(i=0;i<50;i++)
  537. queue[i]=-1;
  538. for(i=0;i<40;i++)
  539. queue1[i]=-1;
  540. test.total=-1;
  541. for(j=0;j<15;j++)
  542. test.dian[j]=-1;
  543. for(j=0;j<15;j++)
  544. {
  545. for(k=0;k<20;k++)
  546. {
  547. test.detail[j][k].relate=0;
  548. test.detail[j][k].arc=0;
  549. test.detail[j][k].region=0;
  550. }
  551. }
  552. return;
  553. }
  554. //去除噪声
  555. intCPatternDlg::Ridnoise(intj)//返回k+1个特征点
  556. {
  557. inti,k,ff;
  558. k=0;
  559. ff=test.total+1;//ff,当前的处理条数,total为已存条数的最大下标
  560. queue1[0]=queue[0];
  561. for(i=1;i<J-1;I++){else}if(abs(y1-y3)are="abs(x1-x3);"y3="store[kk][queue1[j]].y;"x3="store[kk][queue1[j]].x;"y1="store[kk][queue1[j-1]].y;"x1="store[kk][queue1[j-1]].x;"kk="test.total;"kk;intsmax="0;ci=0;vct=0;"s;floatx1,x2,y1,y2,x3,y3,t1,smax,ci,vct,are;j)CPatternDlg::Getarc(int得到arc特征k;returnqueue1[k]="queue[i];"k++;&&abs(store[ff][queue[j-1]].x-store[ff][queue1[k]].x)<2)abs(store[ff][queue[j-1]].y-store[ff][queue1[k]].y)<2if({;}&&(((store[ff][queue[i]].x-store[ff][queue1[k]].x)*(store[ff][queue[i]].x-store[ff][queue[i+1]].x))<0||abs(store[ff][queue[i]].x-store[ff][queue[i+1]].x)<yu2))(abs(store[ff][queue[i]].y-store[ff][queue1[k]].y)<yu1+1+1if||abs(store[ff][queue[i]].y-store[ff][queue[i+1]].y)<yu2))&&(((store[ff][queue[i]].y-store[ff][queue1[k]].y)*(store[ff][queue[i]].y-store[ff][queue[i+1]].y))<0(abs(store[ff][queue[i]].x-store[ff][queue1[k]].x)<yu1+1+1>are)
  562. are=abs(y1-y3);
  563. for(t1=queue1[j-1]+1;t1<QUEUE1[J];T1++){if(ss="(x1*y2+x2*y3+x3*y1-x1*y3-x2*y1-x3*y2)/are;"x2="store[kk][t1].x;"y2="store[kk][t1].y;">=yu||s<=-yu)
  564. {
  565. if(s*smax==0)
  566. {
  567. if(s>0)
  568. vct=1;
  569. else
  570. vct=-1;
  571. }
  572. if(s*smax<=0)
  573. {
  574. ci++;
  575. smax=s;
  576. }
  577. if(abs(smax)<ABS(S)){}intsmax="s;"floatreturnif(j="=0)"test.detail[tat][j].arc="0;"test.detail[tat][j].relate="10;"test.detail[tat][j].region="16*l+m;"l="(int)((store[tat][queue1[j]].y-ymin)*16/(ymax-ymin+1));"m="(int)((store[tat][queue1[j]].x-xmin)*16/(xmax-xmin+1));"for(j="0;j<=k;j++)"points,初值为-1,定义此条值test.dian[test.total]="k;//k+1"tat="test.total;//没有排序"特征总条数加一test.total++;value;i,j,m,l,tat;此条共k+1个点k)CPatternDlg::Save(intvoid保存特征点ci;ci="vct*ci;">0)
  578. {
  579. if((store[tat][queue1[j]].x-store[tat][queue1[j-1]].x)>5.67*abs(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y))
  580. {
  581. test.detail[test.total][j].relate=1;
  582. test.detail[test.total][j].arc=Getarc(j);
  583. }
  584. else
  585. {
  586. if((store[tat][queue1[j]].x-store[tat][queue1[j-1]].x)<-5.67*abs(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y))
  587. {
  588. test.detail[test.total][j].relate=9;
  589. test.detail[test.total][j].arc=Getarc(j);
  590. }
  591. else
  592. {
  593. if(5.67*abs(store[tat][queue1[j]].x-store[tat][queue1[j-1]].x)<(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y))
  594. {
  595. test.detail[test.total][j].relate=7;
  596. test.detail[test.total][j].arc=Getarc(j);
  597. }
  598. else
  599. {
  600. if(-5.67*abs(store[tat][queue1[j]].x-store[tat][queue1[j-1]].x)>(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y))
  601. {
  602. test.detail[test.total][j].relate=3;
  603. test.detail[test.total][j].arc=Getarc(j);
  604. }
  605. else
  606. {
  607. value=(float)(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)/(store[tat][queue1[j]].x-store[tat][queue1[j-1]].x);
  608. if(value<2.747&&value>0.364&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)>0)
  609. {
  610. test.detail[test.total][j].relate=6;
  611. test.detail[test.total][j].arc=Getarc(j);
  612. }
  613. if(value<2.747&&value>0.364&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)<0)
  614. {
  615. test.detail[test.total][j].relate=4;
  616. test.detail[test.total][j].arc=Getarc(j);
  617. }
  618. if(value>-2.747&&value<-0.364&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)>0)
  619. {
  620. test.detail[test.total][j].relate=8;
  621. test.detail[test.total][j].arc=Getarc(j);
  622. }
  623. if(value>-2.747&&value<-0.364&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)<0)
  624. {
  625. test.detail[test.total][j].relate=2;
  626. test.detail[test.total][j].arc=Getarc(j);
  627. }
  628. if(value<=5.61&&value>=2.747&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)>0)
  629. {
  630. test.detail[test.total][j].relate=76;
  631. test.detail[test.total][j].arc=Getarc(j);
  632. }
  633. if(value<=5.61&&value>=2.747&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)<0)
  634. {
  635. test.detail[test.total][j].relate=34;
  636. test.detail[test.total][j].arc=Getarc(j);
  637. }
  638. if(value>=-5.61&&value<=-2.747&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)>0)
  639. {
  640. test.detail[test.total][j].relate=78;
  641. test.detail[test.total][j].arc=Getarc(j);
  642. }
  643. if(value>=-5.61&&value<=-2.747&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)<0)
  644. {
  645. test.detail[test.total][j].relate=32;
  646. test.detail[test.total][j].arc=Getarc(j);
  647. }
  648. if(value<=0.364&&value>=0.1782&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)>0)
  649. {
  650. test.detail[test.total][j].relate=16;
  651. test.detail[test.total][j].arc=Getarc(j);
  652. }
  653. if(value<=0.364&&value>=0.1782&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)<0)
  654. {
  655. test.detail[test.total][j].relate=94;
  656. test.detail[test.total][j].arc=Getarc(j);
  657. }
  658. if(value>=-0.364&&value<=-0.1782&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)>0)
  659. {
  660. test.detail[test.total][j].relate=98;
  661. test.detail[test.total][j].arc=Getarc(j);
  662. }
  663. if(value>=-0.364&&value<=-0.1782&&(store[tat][queue1[j]].y-store[tat][queue1[j-1]].y)<0)
  664. {
  665. test.detail[test.total][j].relate=12;
  666. test.detail[test.total][j].arc=Getarc(j);
  667. }
  668. }
  669. }
  670. }
  671. }
  672. }
  673. }
  674. for(i=0;i<50;i++)
  675. queue[i]=-1;
  676. for(i=0;i<40;i++)
  677. queue1[i]=-1;//must
  678. }
  679. //进一步处理数据,提取特征
  680. voidCPatternDlg::DealData()
  681. {
  682. inti,j,k,num1,Time1;
  683. Inorder();
  684. for(num1=0;store[num1][0].x>-1;num1++)//第几条线
  685. {
  686. for(Time1=0,j=0;store[num1][Time1].x>-1;Time1++)
  687. {
  688. if(Time1==0)
  689. {
  690. queue[j]=Time1;j++;
  691. }
  692. if(Time1>0&&store[num1][Time1+1].x==-1)
  693. {
  694. queue[j]=Time1;j++;
  695. }
  696. if(Time1>0&&store[num1][Time1+1].x!=-1)
  697. {
  698. if((store[num1][Time1+1].x-store[num1][Time1].x)*(store[num1][Time1-1].x-store[num1][Time1].x)>0||(store[num1][Time1+1].y-store[num1][Time1].y)*(store[num1][Time1-1].y-store[num1][Time1].y)>0)
  699. {
  700. queue[j]=Time1;j++;
  701. }
  702. if(store[num1][Time1-1].x-store[num1][Time1].x==0)//&&(store[num1][Time1+1].x-store[num1][Time1].x!0))
  703. {
  704. for(i=1;store[num1][Time1-1-i].x==store[num1][Time1-1].x&&(Time1-1-i)>=0;i++){;}
  705. if((store[num1][Time1+1].x-store[num1][Time1].x)*(store[num1][Time1-1-i].x-store[num1][Time1].x)>0)
  706. {
  707. queue[j]=Time1;j++;
  708. }
  709. }
  710. if(store[num1][Time1-1].y-store[num1][Time1].y==0)//&&(store[num1][Time1+1].y-store[num1][Time1].y)<0)
  711. {
  712. for(i=1;store[num1][Time1-1-i].y==store[num1][Time1-1].y&&(Time1-1-i)>=0;i++){;}
  713. if((store[num1][Time1+1].y-store[num1][Time1].y)*(store[num1][Time1-1-i].y-store[num1][Time1].y)>0)
  714. {
  715. queue[j]=Time1;j++;
  716. }
  717. }
  718. }
  719. }
  720. k=Ridnoise(j);//共j点,0到j-1
  721. Save(k);
  722. }
  723. }
  724. CPatternDlg::OnRecogch()//清空获取的特征
  725. {
  726. inti,j,k;
  727. for(i=0;i<50;i++)
  728. queue[i]=-1;
  729. for(i=0;i<40;i++)
  730. queue1[i]=-1;
  731. test.total=-1;
  732. for(j=0;j<15;j++)
  733. test.dian[j]=-1;
  734. for(j=0;j<15;j++)
  735. {
  736. for(k=0;k<20;k++)
  737. {
  738. test.detail[j][k].relate=0;
  739. test.detail[j][k].arc=0;
  740. test.detail[j][k].region=0;
  741. }
  742. }
  743. return(1);
  744. }
  745. voidCPatternDlg::OnExitMenu()
  746. {
  747. //TODO:Addyourcommandhandlercodehere
  748. OnEsp();
  749. }
  750. voidCPatternDlg::OnAboutMenu()
  751. {
  752. CAboutDlgcabout;
  753. //TODO:Addyourcommandhandlercodehere
  754. if(cabout.DoModal()==1)
  755. {;}
  756. }
  757. voidCPatternDlg::OnSaveMenu()
  758. {
  759. //TODO:Addyourcommandhandlercodehere
  760. CFilecf;
  761. intk,j;
  762. if(cf.Open("mydata.dat",CFile::modeReadWrite)==NULL)
  763. {
  764. AfxMessageBox("打开文件失败,/n您最好退出程序");
  765. }
  766. else
  767. {
  768. cf.SeekToEnd();
  769. cf.Write(&tez[zong].zifu,sizeof(char)*2);
  770. cf.Write(&tez[zong].total,sizeof(int));
  771. for(j=0;j<=tez[zong].total;j++)
  772. {
  773. cf.Write(&tez[zong].dian[j],sizeof(int));
  774. }
  775. for(j=0;j<=tez[zong].total;j++)
  776. {
  777. for(k=0;k<=tez[zong].dian[j];k++)
  778. {
  779. cf.Write(&tez[zong].detail[j][k].relate,sizeof(int));
  780. cf.Write(&tez[zong].detail[j][k].region,sizeof(int));
  781. cf.Write(&tez[zong].detail[j][k].arc,sizeof(int));
  782. }
  783. }
  784. cf.Close();
  785. }
  786. }
  787. voidCPatternDlg::OnOpenMenu()
  788. {
  789. CFilecf;
  790. chars[20];
  791. intj,k;
  792. intnFileSize;
  793. inttt;
  794. if(cf.Open("mydata.dat",CFile::modeReadWrite)==NULL)
  795. {
  796. AfxMessageBox("打开文件失败,/n您最好退出程序");
  797. }
  798. else
  799. {
  800. cf.SeekToBegin();
  801. nFileSize=cf.GetLength();
  802. for(zong=0,tt=0;tt<NFILESIZE-1;ZONG++){}intfor(j="0;j<=tez[zong].total;j++)"voidfor(num1="0;store[num1][0].x"xxbegin,xxend,yybegin,yyend,total;i,j,k,num1,Time1;CPatternDlg::Inorder()OK?);AfxMessageBox(?SaveCPatternDlg::OnSaveMenu1()AfxMessageBox(s);%d?,zong);sprintf(s,?读入正确,共有字);cf.Close(zong--;tt="tt+sizeof(char)*2;"sizeof(int));cf.Read(&tez[zong].detail[j][k].arc,cf.Read(&tez[zong].detail[j][k].region,cf.Read(&tez[zong].detail[j][k].relate,sizeof(int));for(k="0;k<=tez[zong].dian[j];k++)"cf.Read(&tez[zong].dian[j],cf.Read(&tez[zong].total,sizeof(char)*2);cf.Read(&tez[zong].zifu,最后减一>-1;num1++)//第几条线
  803. {
  804. xxbegin=store[num1][0].x;
  805. yybegin=store[num1][0].y;
  806. for(Time1=0,j=0;store[num1][Time1].x>-1;Time1++)
  807. {;}
  808. total=Time1;
  809. xxend=store[num1][Time1-1].x;
  810. yyend=store[num1][Time1-1].y;
  811. for(Time1=0;store[num1][Time1].x>-1;Time1++)
  812. {
  813. storeback[0][total-Time1-1].x=store[num1][Time1].x;
  814. storeback[0][total-Time1-1].y=store[num1][Time1].y;
  815. }
  816. if(abs(xxbegin-xxend)>2*abs(yybegin-yyend)&&(xxbegin>xxend))
  817. {
  818. for(j=0;j<TOTAL;J++){}if(abs(xxbegin-xxend)<="2*abs(yybegin-yyend)&&(yybegin"store[num1][j].y="storeback[0][j].y;"store[num1][j].x="storeback[0][j].x;">yyend))
  819. {
  820. for(j=0;j<TOTAL;J++){}store[num1][j].y="storeback[0][j].y;"store[num1][j].x="storeback[0][j].x;"pre<>
  821. <SCRIPTsrc="/inc/gg_read2.js"></SCRIPT>

需要源码的请留下地址,我给大家发

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics