现在的位置: 首页 > 综合 > 正文

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

2013年10月01日 ⁄ 综合 ⁄ 共 20980字 ⁄ 字号 评论关闭
  1. // patternDlg.cpp : implementation file    
  2. //    
  3.    
  4. #include "stdafx.h"    
  5. #include "pattern.h"    
  6. #include "patternDlg.h"    
  7. #include "Afxwin.h"    
  8. #include "Afxdlgs.h"    
  9. #include "winuser.h"    
  10. #include "Store.h"    
  11.  #include <STDIO.H>    
  12. //#define   _MBCS    
  13.    
  14. #ifdef _DEBUG    
  15. #define new DEBUG_NEW    
  16. #undef THIS_FILE    
  17. static char THIS_FILE[] = __FILE__;   
  18. #endif    
  19.    
  20. #include<WINDOWS.H>    
  21. #include<MATH.H>    
  22.    
  23. #define Startx 30    
  24. #define Starty 190    
  25. #define wid  192    
  26. #define lon 192    
  27. #define yu 3 //2 area    
  28. #define yu1 5 //dou dong    
  29.    
  30. #define yu2  4     
  31. int num,Time;   
  32.    
  33. int xmax,ymax,xmin,ymin; //随时纪录书写过程中的书写范围    
  34.    
  35. //存储书写笔迹的坐标序列,按笔划存储,每个笔划最多300个点    
  36. //每个字最多15个笔划    
  37. struct    
  38. {   
  39.     int x;   
  40.     int y;   
  41. }store[15][300];   
  42.    
  43. //备份的序列    
  44. struct    
  45. {   
  46.     int x;   
  47.     int y;   
  48. }storeback[15][300];   
  49.    
  50. struct   
  51. {      
  52.     int total;//总的笔划数    
  53.     char zifu[2];//代表字符    
  54.     int dian[15];//每个笔划的点数    
  55.     struct{   
  56.         int relate;//相对前点特征    
  57.         int region;//全局位置特征    
  58.         int arc;//过渡带特征    
  59.     }detail[15][20];//15个笔划上的特征点,每个笔划20个特征点    
  60. }tez[2002];   
  61.    
  62. struct   
  63. {   
  64.     int total;   
  65.     int dian[15];   
  66.     struct   
  67.     {   
  68.         int relate;   
  69.         int region;   
  70.         int arc;   
  71.     }detail[15][20];   
  72. }test;//意义同上,为测试点的结构    
  73.    
  74. int queue[50];   
  75. int  queue1[40];   
  76. int zong;   
  77.    
  78. /////////////////////////////////////////////////////////////////////////////    
  79. // CAboutDlg dialog used for App About    
  80.    
  81. class CAboutDlg : public CDialog   
  82. {   
  83. public:   
  84.     CAboutDlg();   
  85.    
  86. // Dialog Data    
  87.     //{{AFX_DATA(CAboutDlg)    
  88.     enum { IDD = IDD_ABOUTBOX };   
  89.     //}}AFX_DATA    
  90.    
  91.     // ClassWizard generated virtual function overrides    
  92.     //{{AFX_VIRTUAL(CAboutDlg)    
  93.     protected:   
  94.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support    
  95.     //}}AFX_VIRTUAL    
  96.    
  97. // Implementation    
  98. protected:   
  99.     //{{AFX_MSG(CAboutDlg)    
  100.     //}}AFX_MSG    
  101.     DECLARE_MESSAGE_MAP()   
  102. };   
  103.    
  104. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)   
  105. {   
  106.     //{{AFX_DATA_INIT(CAboutDlg)    
  107.     //}}AFX_DATA_INIT    
  108. }   
  109.    
  110. void CAboutDlg::DoDataExchange(CDataExchange* pDX)   
  111. {   
  112.     CDialog::DoDataExchange(pDX);   
  113.     //{{AFX_DATA_MAP(CAboutDlg)    
  114.     //}}AFX_DATA_MAP    
  115. }   
  116.    
  117. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)   
  118.     //{{AFX_MSG_MAP(CAboutDlg)    
  119.         // No message handlers    
  120.     //}}AFX_MSG_MAP    
  121. END_MESSAGE_MAP()   
  122.    
  123. /////////////////////////////////////////////////////////////////////////////    
  124. // CPatternDlg dialog    
  125.    
  126. CPatternDlg::CPatternDlg(CWnd* pParent /*=NULL*/)   
  127.     : CDialog(CPatternDlg::IDD, pParent)   
  128. {   
  129.     //{{AFX_DATA_INIT(CPatternDlg)    
  130.     //}}AFX_DATA_INIT    
  131.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32    
  132.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);   
  133. }   
  134.    
  135. void CPatternDlg::DoDataExchange(CDataExchange* pDX)   
  136. {   
  137.     CDialog::DoDataExchange(pDX);   
  138.     //{{AFX_DATA_MAP(CPatternDlg)    
  139.     DDX_Control(pDX, IDC_EDIT2, m_edit2);   
  140.     DDX_Control(pDX, IDC_EDIT1, m_edit1);   
  141.     DDX_Control(pDX, IDC_BUTTON4, m_escape);   
  142.     DDX_Control(pDX, IDC_BUTTON3, m_clear);   
  143.     DDX_Control(pDX, IDC_BUTTON1, m_recog);   
  144.     DDX_Control(pDX, IDC_BUTTON2, m_study);   
  145.     //}}AFX_DATA_MAP    
  146. }   
  147.    
  148. BEGIN_MESSAGE_MAP(CPatternDlg, CDialog)   
  149.     //{{AFX_MSG_MAP(CPatternDlg)    
  150.     ON_WM_SYSCOMMAND()   
  151.     ON_WM_PAINT()   
  152.     ON_WM_QUERYDRAGICON()   
  153.     ON_BN_CLICKED(IDC_BUTTON4, OnEsp)   
  154.     ON_BN_CLICKED(IDC_BUTTON1, OnRecog)   
  155.     ON_WM_MOUSEMOVE()   
  156.     ON_BN_CLICKED(IDC_BUTTON3, OnClear)   
  157.     ON_BN_CLICKED(IDC_BUTTON2, OnStudy)   
  158.     ON_WM_LBUTTONUP()   
  159.     ON_WM_LBUTTONDOWN()   
  160.     ON_COMMAND(ID_EXIT_MENU, OnExitMenu)   
  161.     ON_COMMAND(ID_ABOUT_MENU, OnAboutMenu)   
  162.     ON_COMMAND(ID_SAVE_MENU, OnSaveMenu1)   
  163.     ON_COMMAND(ID_OPEN_MENU, OnOpenMenu)   
  164.     //}}AFX_MSG_MAP    
  165. END_MESSAGE_MAP()   
  166.    
  167. /////////////////////////////////////////////////////////////////////////////    
  168. // CPatternDlg message handlers    
  169.    
  170. BOOL CPatternDlg::OnInitDialog()   
  171. {   
  172.     CFile cf;   
  173.        
  174.     CDialog::OnInitDialog();   
  175.    
  176.     mouseDown=0;   
  177.        
  178.     int i,j,k;   
  179.    
  180.     //将每个笔划上坐标初始化为空    
  181.     for(i=0;i<15;i++)   
  182.     {   
  183.         for(j=0;j<300;j++)   
  184.         {   
  185.             store[i][j].x=-1;   
  186.             store[i][j].y=-1;   
  187.         }   
  188.     }   
  189.    
  190.     for(i=0;i<15;i++)   
  191.     {   
  192.         for(j=0;j<300;j++)   
  193.         {   
  194.             storeback[i][j].x=-1;   
  195.             storeback[i][j].y=-1;   
  196.         }   
  197.     }   
  198.    
  199.     for(i=0;i<10;i++)   
  200.     {   
  201.         tez[i].total=-1;   
  202.    
  203.         for(j=0;j<15;j++)    
  204.             tez[i].dian[j]=-1;   
  205.    
  206.         for(j=0;j<15;j++)   
  207.         {   
  208.             for(k=0;k<20;k++)   
  209.             {   
  210.                 tez[i].detail[j][k].relate=0;   
  211.                 tez[i].detail[j][k].arc=0;   
  212.                 tez[i].detail[j][k].region=0;   
  213.             }   
  214.         }   
  215.     }   
  216.    
  217.     Time=0;   
  218.     num=0;   
  219.     zong=-1;//tez下标    
  220.     xmax=0;   
  221.     ymax=0;   
  222.     xmin=31;   
  223.     ymin=31;   
  224.    
  225.     for(i=0;i<50;i++)   
  226.         queue[i]=-1;   
  227.     for(i=0;i<40;i++)   
  228.         queue1[i]=-1;   
  229.    
  230.     test.total=-1;   
  231.     for(j=0;j<15;j++)    
  232.         test.dian[j]=-1;   
  233.    
  234.     for(j=0;j<15;j++)   
  235.     {   
  236.         for(k=0;k<20;k++)   
  237.         {   
  238.             test.detail[j][k].relate=0;   
  239.             test.detail[j][k].arc=0;   
  240.             test.detail[j][k].region=0;   
  241.         }   
  242.     }   
  243.    
  244.     // Add "About..." menu item to system menu.    
  245.     // IDM_ABOUTBOX must be in the system command range.    
  246.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);   
  247.     ASSERT(IDM_ABOUTBOX < 0xF000);   
  248.    
  249.     CMenu* pSysMenu = GetSystemMenu(FALSE);   
  250.     if (pSysMenu != NULL)   
  251.     {   
  252.         CString strAboutMenu;   
  253.         strAboutMenu.LoadString(IDS_ABOUTBOX);   
  254.         if (!strAboutMenu.IsEmpty())   
  255.         {   
  256.             pSysMenu->AppendMenu(MF_SEPARATOR);   
  257.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);   
  258.         }   
  259.     }   
  260.    
  261.     // Set the icon for this dialog.  The framework does this automatically    
  262.     //  when the application's main window is not a dialog    
  263.     SetIcon(m_hIcon, TRUE);         // Set big icon    
  264.     SetIcon(m_hIcon, FALSE);        // Set small icon    
  265.        
  266.     // TODO: Add extra initialization here    
  267.     if(cf.Open("mydata.dat",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite)==NULL){   
  268.         AfxMessageBox("打开文件失败,/n您最好退出程序");}   
  269.    
  270.     return TRUE;  // return TRUE  unless you set the focus to a control    
  271. }   
  272.    
  273. void CPatternDlg::OnSysCommand(UINT nID, LPARAM lParam)   
  274. {   
  275.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)   
  276.     {   
  277.         CAboutDlg dlgAbout;   
  278.         dlgAbout.DoModal();   
  279.     }   
  280.     else   
  281.     {   
  282.         CDialog::OnSysCommand(nID, lParam);   
  283.     }   
  284. }   
  285.    
  286. // If you add a minimize button to your dialog, you will need the code below    
  287. //  to draw the icon.  For MFC applications using the document/view model,    
  288. //  this is automatically done for you by the framework.    
  289.    
  290. void CPatternDlg::OnPaint()    
  291. {   
  292.     CPaintDC dc(this);    
  293.     HBRUSH hB;   
  294.     hB=CreateSolidBrush(RGB(255,255,255));   
  295.     SelectObject(dc,hB);   
  296.     Rectangle(dc,Startx,Starty,Startx+wid-1,Starty+lon-1);   
  297.     DeleteObject(hB);   
  298.    
  299.     if (IsIconic())   
  300.     {   
  301.         // device context for painting    
  302.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);   
  303.    
  304.         // Center icon in client rectangle    
  305.         int cxIcon = GetSystemMetrics(SM_CXICON);   
  306.         int cyIcon = GetSystemMetrics(SM_CYICON);   
  307.         CRect rect;   
  308.         GetClientRect(&rect);   
  309.         int x = (rect.Width() - cxIcon + 1) / 2;   
  310.         int y = (rect.Height() - cyIcon + 1) / 2;   
  311.    
  312.         // Draw the icon    
  313.         dc.DrawIcon(x, y, m_hIcon);   
  314.     }   
  315.     else   
  316.     {   
  317.         CDialog::OnPaint();   
  318.     }   
  319. }   
  320.    
  321. // The system calls this to obtain the cursor to display while the user drags    
  322. //  the minimized window.    
  323. HCURSOR CPatternDlg::OnQueryDragIcon()   
  324. {   
  325.     return (HCURSOR) m_hIcon;   
  326. }   
  327.    
  328. void CPatternDlg::OnEsp()    
  329. {   
  330.     OnOK();    
  331. }   
  332.    
  333. //识别函数    
  334. void CPatternDlg::OnRecog()    
  335. {     
  336.     int j1,k1,m1,n1,x,y,xmod,ymod;//xmod,ymod;    
  337.     int  flagok2=0;   
  338.     char s[20];   
  339.     DealData();   
  340.    
  341.     //安次序检验,有点下标数    
  342.     for(j1=0;j1<=zong&&test.total>=0&&flagok2==0;j1++)   
  343.     {             
  344.         if(tez[j1].total==test.total)       //如果总条数相等    
  345.         {          
  346.             for(k1=0;k1<=test.total;k1++)              
  347.             {     
  348.                 if(test.dian[k1]!=tez[j1].dian[k1])     
  349.                     break;   
  350.             }   
  351.                      
  352.             if(k1>test.total)      
  353.             //每条得点数相同    
  354.             {      
  355.                 for(m1=0;m1<=test.total;m1++)           //每条    
  356.                 {        
  357.                     for(n1=0;n1<=test.dian[m1];n1++)        //每点    
  358.                     {   
  359.                         xmod=2*(tez[j1].detail[m1][n1].region % 8);  //8等分    
  360.                         ymod=2*((int)tez[j1].detail[m1][n1].region/8);   
  361.                         x=test.detail[m1][n1].region % 16;   
  362.                         y=(int)test.detail[m1][n1].region/16;    //   5/16                                                                
  363.                          
  364.                         if(( test.detail[m1][n1].relate!=tez[j1].detail[m1][n1].relate   
  365.                             &&(test.detail[m1][n1].relate-10*(int)(test.detail[m1][n1].relate/10))!=tez[j1].detail[m1][n1].relate   
  366.                             &&(int)(test.detail[m1][n1].relate/10)!=tez[j1].detail[m1][n1].relate)   
  367.                             ||((tez[j1].detail[m1][n1].arc!=test.detail[m1][n1].arc)&&(test.total<4)&&(test.dian[m1]<4))   
  368.                             ||((x<XMOD-3||X>xmod+3)||(y<YMOD-3||Y>ymod+3)))//shi为total+1    
  369.                             break;   
  370.                     }   
  371.                     if(n1<=test.dian[m1])     
  372.                         break;     
  373.                 }   
  374.                 if(m1>test.total)   
  375.                 {   
  376.                     flagok2=1;   
  377.                     sprintf(s,"输入正确,可识别,为:%s, 在字库%d个",tez[j1].zifu,j1);   
  378.                     AfxMessageBox(s);   
  379.                     m_edit1.ReplaceSel(tez[j1].zifu);    
  380.                     OnClear();   
  381.                 }   
  382.             }   
  383.         }   
  384.     }                                               
  385.           
  386.     if(flagok2==0)   
  387.     {    
  388.         AfxMessageBox("字库不足或输入不规范,无法识别,请学习");   
  389.         OnRecogch();   
  390.     }   
  391. }      
  392.     
  393. //学习函数      
  394. void CPatternDlg::OnStudy()    
  395. {        
  396.     int j1,k1,m1,n1,k,m,xmod,ymod,x,y;//j1代表字典中的一个字,k 表示笔划,m 表示一个点    
  397.     CString z1;   
  398.     int i,j;   
  399.     int flagok1=0; //o无法识别,1可识别,已经识别出结果    
  400.     char s[30];   
  401.     Inputdialog inputdlg;   
  402.    
  403.     //处理数据    
  404.     DealData();   
  405.    
  406.     if(test.total==-1)   
  407.     {   
  408.         AfxMessageBox("没有笔迹输入,/n请重示");   
  409.     }   
  410.    
  411.     for(j1=0;j1<=zong&&test.total!=-1;j1++)   
  412.     {       
  413.         if(flagok1==1)    
  414.             break;   
  415.    
  416.         if(tez[j1].total==test.total&&flagok1==0)      //总笔划相等    
  417.         {         
  418.             for(k1=0;k1<=test.total;k1++)   
  419.             {   
  420.                 if(test.dian[k1]!=tez[j1].dian[k1])     
  421.                     break;   
  422.             }   
  423.    
  424.             if(k1>test.total)      //每笔划点数相同下    
  425.             {     
  426.                 for(m1=0;m1<=test.total;m1++)   
  427.                 {   
  428.                     for(n1=0;n1<=test.dian[m1];n1++)   
  429.                     {   
  430.                         if(( test.detail[m1][n1].relate!=tez[j1].detail[m1][n1].relate   
  431.                             &&(test.detail[m1][n1].relate % 10)!=tez[j1].detail[m1][n1].relate   
  432.                             &&((int)(test.detail[m1][n1].relate/10))!=tez[j1].detail[m1][n1].relate)   
  433.                             ||(tez[j1].detail[m1][n1].arc!=test.detail[m1][n1].arc))//shi为total+1    
  434.                             break;   
  435.                         xmod=2*(tez[j1].detail[m1][n1].region % 8);  //8等分    
  436.                         ymod=2*((int)tez[j1].detail[m1][n1].region/8);   
  437.                         x=test.detail[m1][n1].region % 16;   
  438.                         y=(int)test.detail[m1][n1].region/16;   
  439.                         if((x<XMOD-1||X>xmod+1)||(y<YMOD-1||Y>ymod+1))   
  440.                             break;      //3/16    
  441.                     }         //对一个笔划的判断,tezheng不等,跳出n    
  442.                     if(n1<=test.dian[m1])     
  443.                         break;  //ci bihua不等,跳出m循环    
  444.                 }   
  445.    
  446.                 if(m1>test.total&&k1>test.total)//当前库字与输入相符合    
  447.                 {   
  448.                     flagok1=1;   
  449.                        
  450.                     sprintf(s,"您输入的是:%s,数据已有",tez[j1].zifu);    
  451.                     AfxMessageBox(s);   
  452.                     m_edit1.ReplaceSel(tez[j1].zifu);   
  453.                     OnClear();   
  454.                 }   
  455.             }   
  456.         }   
  457.     }   
  458.        
  459.     if(flagok1==0&&test.total>=0&&inputdlg.DoModal()==IDOK) //shuruzifu    
  460.     {      
  461.         if(inputdlg.m_input1!=inputdlg.m_input2   
  462.             ||inputdlg.m_input1==""||inputdlg.m_input1==" ")   
  463.         {   
  464.             AfxMessageBox("您的输入有误(不等或空格),/n请重新输入");   
  465.             for(i=0;i<50;i++)   
  466.                 queue[i]=-1;   
  467.             for(i=0;i<40;i++)   
  468.                 queue1[i]=-1;   
  469.    
  470.             test.total=-1;   
  471.             for(j=0;j<15;j++)    
  472.                 test.dian[j]=-1;   
  473.    
  474.             for(j=0;j<15;j++)   
  475.             {   
  476.                 for(k=0;k<20;k++)   
  477.                 {   
  478.                     test.detail[j][k].relate=0;   
  479.                     test.detail[j][k].region=0;   
  480.                 }   
  481.             }   
  482.         }   
  483.         else   
  484.         {   
  485.             zong++;    
  486.             sprintf(tez[zong].zifu,"%s",inputdlg.m_input1);   
  487.             tez[zong].total=test.total;   
  488.    
  489.             for(i=0;i<=test.total;i++)   
  490.             {   
  491.                 tez[zong].dian[i]=test.dian[i];   
  492.                 for(j=0;j<=test.dian[i];j++)   
  493.                 {   
  494.                     tez[zong].detail[i][j].relate=(test.detail[i][j].relate % 10);   
  495.                     tez[zong].detail[i][j].arc=test.detail[i][j].arc;   
  496.    
  497.                     x=(int)(test.detail[i][j].region % 16)/2;   
  498.                     y=(int)(test.detail[i][j].region/16)/2;   
  499.                     tez[zong].detail[i][j].region=8*y+x;   
  500.                 }   
  501.             }   
  502.             OnSaveMenu();   
  503.        
  504.             if(zong>=2000)    
  505.                 AfxMessageBox("版本太低,容量受限,Sorry!");   
  506.    
  507.             m_edit1.ReplaceSel(inputdlg.m_input1);   
  508.             OnClear();   
  509.         }//zong dang前库下标    
  510.     }   
  511. }   
  512.    
  513. void CPatternDlg::OnLButtonDown(UINT nFlags, CPoint point)   
  514. {   
  515.     mouseDown=1;   
  516.     CWnd::OnLButtonDown(nFlags, point);   
  517. }   
  518.    
  519. //鼠标左键抬起    
  520. void CPatternDlg::OnLButtonUp(UINT nFlags, CPoint point)   
  521. {   
  522.     mouseDown=0;   
  523.    
  524.     if(store[num][Time-1].x>=0&&Time>0)   
  525.     {   
  526.         num++;   
  527.         Time=0;   
  528.     }   
  529.     if(num>=14)    
  530.     {   
  531.         AfxMessageBox("写入有误(笔划太多)",NULL,NULL);   
  532.         OnClear();   
  533.     }   
  534.    
  535.     CWnd::OnLButtonUp(nFlags, point);   
  536. }   
  537.    
  538. //鼠标移动事件,模拟手写笔输入    
  539. void CPatternDlg::OnMouseMove(UINT nFlags, CPoint point)    
  540. {   
  541.     // TODO: Add your message handler code here and/or call default    
  542.     int x,y;   
  543.     CBrush Brush (RGB (0, 0 , 255) );   
  544.     CBrush* pOldBrush;   
  545.     CDC *pDC=GetDC();   
  546.     CRgn Rgn;   
  547.     Rgn.CreateRectRgn(Startx,Starty,Startx+wid-1,Starty+lon-1);   
  548.     pDC->SelectClipRgn(&Rgn);   
  549.    
  550.     if((point.x>=Startx)&&(point.x<STARTX+WID)&&(POINT.Y>=Starty)   
  551.         &&(point.y<STARTY+LON)) m_HCross="AfxGetApp()-" m_HCross; HCURSOR {>LoadStandardCursor(IDC_CROSS);   
  552.         SetCursor(m_HCross);   
  553.     }   
  554.    
  555.     if((mouseDown==1)&&(point.x>=Startx)&&(point.x<STARTX+WID) &&(point.y>=Starty)&&(point.y<STARTY+LON)) { pOldBrush="pDC-" CBrush* . context device the into brush Select>SelectObject (&Brush);   
  556.         pDC->Ellipse(point.x-4,point.y-4,point.x+4,point.y+4);   
  557.         pDC->SelectObject (pOldBrush );   
  558.         x=(int)(point.x-Startx)*32/wid;   
  559.         y= (int)(point.y-Starty)*32/lon;   
  560.            
  561.         if(Time==0)   
  562.         {    
  563.             store[num][Time].x=x;   
  564.             store[num][Time].y=y;   
  565.             Time++;   
  566.             if(y>ymax)    
  567.                 ymax=y;   
  568.             if(y<YMIN) if(x ymin="y;">xmax)    
  569.                 xmax=x;   
  570.             if(x<XMIN) { if(y Time++; 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)    
  571.                     ymax=y;   
  572.                 if(y<YMIN) if(x ymin="y;">xmax)    
  573.                     xmax=x;   
  574.                 if(x<XMIN) } xmin="x;" if(Time>=300)   
  575.         {   
  576.             AfxMessageBox("当前笔划写入有误(太多)",NULL,NULL);   
  577.             OnClear();   
  578.         }   
  579.     }   
  580.        
  581.     ReleaseDC(pDC );   
  582.     DeleteObject(pOldBrush);   
  583.     DeleteObject(Rgn);   
  584.     DeleteObject(Brush);   
  585.        
  586.     CWnd::OnMouseMove(nFlags, point);   
  587. }   
  588.    
  589. //清空画板    
  590. void CPatternDlg::OnClear()    
  591. {   
  592.     int i,j,k;   
  593.     CDC *pDC=GetDC();   
  594.     pDC-> PatBlt (Startx,Starty,wid,lon, PATCOPY );   
  595.     ReleaseDC(pDC );   
  596.     mouseDown=0;   
  597.    
  598.     for(i=0;i<15;i++){   
  599.         for(j=0;j<300;j++)   
  600.         {   
  601.             store[i][j].x=-1;   
  602.             store[i][j].y=-1;   
  603.         }   
  604.     }   
  605.    
  606.     for(i=0;i<15;i++){   
  607.         for(j=0;j<300;j++)   
  608.         {   
  609.             storeback[i][j].x=-1;   
  610.             storeback[i][j].y=-1;   
  611.         }   
  612.     }   
  613.    
  614.     Time=0;   
  615.     num=0;   
  616.     xmax=0;   
  617.     ymax=0;   
  618.     xmin=32;   
  619.     ymin=32;   
  620.    
  621.     for(i=0;i<50;i++)   
  622.         queue[i]=-1;   
  623.     for(i=0;i<40;i++)   
  624.         queue1[i]=-1;   
  625.    
  626.     test.total=-1;   
  627.     for(j=0;j<15;j++)    
  628.         test.dian[j]=-1;   
  629.     for(j=0;j<15;j++)   
  630.     {   
  631.         for(k=0;k<20;k++)   
  632.         {   
  633.             test.detail[j][k].relate=0;   
  634.             test.detail[j][k].arc=0;   
  635.             test.detail[j][k].region=0;   
  636.         }   
  637.     }   
  638.       
  639.     return;   
  640. }   
  641.    
  642. //去除噪声    
  643. int CPatternDlg::Ridnoise(int j)         //返回k+1个特征点    
  644. {   
  645.     int i,k,ff;   
  646.     k=0;   
  647.     ff=test.total+1;      //ff,当前的处理条数,total为已存条数的最大下标    
  648.    
  649.     queue1[0]=queue[0];   
  650.     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; int smax="0;ci=0;vct=0;" s; float x1,x2,y1,y2,x3,y3,t1,smax,ci,vct,are; j) CPatternDlg::Getarc(int 得到arc特征 k; return queue1[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)<2 if( {;} &&(((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+1 if ||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)    
  651.         are=abs(y1-y3);   
  652.         
  653.     for(t1=queue1[j-1]+1;t1<QUEUE1[J];T1++) { if(s s="(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)   
  654.         {   
  655.             if(s*smax==0)   
  656.             {   
  657.                 if(s>0)   
  658.                     vct=1;   
  659.                 else   
  660.                     vct=-1;   
  661.             }   
  662.             
  663.             if(s*smax<=0)   
  664.             {   
  665.                 ci++;   
  666.                 smax=s;   
  667.             }   
  668.    
  669.             if(abs(smax)<ABS(S)) { } int smax="s;" float return if(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(int void 保存特征点 ci; ci="vct*ci;">0)   
  670.         {   
  671.             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))   
  672.             {   
  673.                 test.detail[test.total][j].relate=1;   
  674.                 test.detail[test.total][j].arc=Getarc(j);   
  675.             }   
  676.             else    
  677.             {   
  678.                 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))   
  679.                 {   
  680.                     test.detail[test.total][j].relate=9;   
  681.                     test.detail[test.total][j].arc=Getarc(j);   
  682.                 }   
  683.                 else   
  684.                 {   
  685.                     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))   
  686.                     {   
  687.                         test.detail[test.total][j].relate=7;   
  688.                         test.detail[test.total][j].arc=Getarc(j);   
  689.                     }   
  690.                     else    
  691.                     {   
  692.                         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))   
  693.         

抱歉!评论已关闭.