⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form.cpp

📁 Handwritten digital recognition is made by matlab nerve network toolbox in visual c++.net
💻 CPP
字号:
// Form.cpp : implementation file
//

#include "stdafx.h"
#include "test.h"
#include "Form.h"
#include "Glob.h"
#include "Analyze_map.h"
#include "DemoView.h"
#include "testDoc.h"
#include "User.h"
#include <conio.h>
#include <stdlib.h>
#include "fstream.h"
#include <io.h>
#include <string.h>
#include <stdio.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CForm

IMPLEMENT_DYNCREATE(CForm, CFormView)

CForm::CForm()
	: CFormView(CForm::IDD)
{
	//{{AFX_DATA_INIT(CForm)
	m_num = 4;
	//}}AFX_DATA_INIT
}

CForm::~CForm()
{
}

void CForm::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CForm)
	DDX_Control(pDX, IDC_EDIT2, m_size);
	DDX_Control(pDX, IDC_COMBO1, m_sel);
	DDX_Text(pDX, IDC_EDIT2, m_num);
	DDV_MinMaxInt(pDX, m_num, 4, 100);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CForm, CFormView)
	//{{AFX_MSG_MAP(CForm)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnOperate)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	ON_BN_CLICKED(IDC_BUTTON3, Onkeyinstrains)
	ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CForm diagnostics

#ifdef _DEBUG
void CForm::AssertValid() const
{
	CFormView::AssertValid();
}

void CForm::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CForm message handlers

void CForm::OnButton1() 
{
	// TODO: Add your control notification handler code here
//	this->GetDocument()->OnOpenDocument("");
CFileDialog MyFileDlg(TRUE,NULL,NULL,OFN_ALLOWMULTISELECT,"All Files (*.*)|*.*| |",NULL);
POSITION pos;
CString strPathName;
char *p=new char[101];
GetCurrentDirectory(100,p);
mapcount.RemoveAll();

  if (MyFileDlg.DoModal()==IDOK)
  {
	pos = MyFileDlg.GetStartPosition();
	//MyFileDlg.m_ofn.Flags=OFN_PATHMUSTEXIST   |   OFN_FILEMUSTEXIST   |   OFN_ALLOWMULTISELECT   |   OFN_EXPLORER   |   OFN_HIDEREADONLY| OFN_ALLOWMULTISELECT;
    while( pos )
	{
     // get next file
     strPathName = MyFileDlg.GetNextPathName( pos );
     mapcount.Add(strPathName);
	}	
  }
 SetCurrentDirectory(p);
 input_ok=true;
}

void CForm::OnOperate() 
{
	// TODO: Add your control notification handler code here
	if(!input_ok)
	{
		MessageBox("请先点击'读入测试文件'按钮!");
	    return;
	}
    CTestDoc *pDoc = (CTestDoc*)GetDocument();
	//=====================
	 mapData.RemoveAll();
     bitarr * mapinfo=new bitarr[mapcount.GetSize()];
      CString ss,aa;
	  int i;
	  intarr gets;
	  strarr sa;
	  
  /*
for (int i1=0;i1<this->GetDocument()->mapdata.get) {mapcount.GetSize()
}*/
  for (i=0;i<mapcount.GetSize();i++)
  {
	  this->GetDocument()->OnOpenDocument(mapcount.GetAt(i));
	  mapData.RemoveAll();
	  mapData.Copy(mapdata);
	  mapinfo[i].Copy(mapData);

  }
  CAnalyze_map info(mapinfo[0].GetAt(mapinfo[0].GetSize()-2),mapinfo[0].GetAt(mapinfo[0].GetSize()-1));
  sa.RemoveAll();
  for (i=0;i<1;i++)//mapcount.GetSize()	test1[j]	CXX0033: Error: error in OMF type information

  {    
	  ss="";
	  ss+="特征: ";
      info.analyse_chara(gets,mapinfo[i]);
	  for (int j=0;j<13;j++) 
	  {
			test1[j]=gets.GetAt(j);
			switch(gets.GetAt(j))
			{
			case 0:test2[3*j]=-1;
				   test2[3*j+1]=-1;
				   test2[3*j+2]=-1;
				   break;
		    case 1:test2[3*j]=-1;
				   test2[3*j+1]=-1;
				   test2[3*j+2]=1;
				   break;
			case 2:test2[3*j]=-1;
				   test2[3*j+1]=1;
				   test2[3*j+2]=-1;
				   break;
		    case 3:test2[3*j]=-1;
				   test2[3*j+1]=1;
				   test2[3*j+2]=1;
				   break;
		    case 4:test2[3*j]=1;
				   test2[3*j+1]=-1;
				   test2[3*j+2]=-1;
				   break;
		    case 5:test2[3*j]=1;
				   test2[3*j+1]=-1;
				   test2[3*j+2]=1;
				   break;
			case 6:test2[3*j]=1;
				   test2[3*j+1]=1;
				   test2[3*j+2]=-1;
				   break;
			case 7:test2[3*j]=1;
				   test2[3*j+1]=1;
				   test2[3*j+2]=1;
				   break;
			default:test2[3*j]=1;
				    test2[3*j+1]=1;
				    test2[3*j+2]=1;
				    break;

			}
          aa.Format(" %d",gets.GetAt(j));
	
			ss+=aa;
		}
		ss+="  bmp图片>";
		ss+=mapcount.GetAt(i);
         
		 sa.Add(ss);
  }
 
	//-------------------------

    chuli=TRUE;
	GetDocument()->UpdateAllViews(NULL,2,(CObject*)&sa);
    

}

void CForm::OnSelchangeCombo1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	option = m_sel.GetCurSel();
	if((option==1)||(option==2))
		m_size.EnableWindow(FALSE);
	else
		m_size.EnableWindow(TRUE);
	UpdateData(FALSE);
}

void CForm::Onkeyinstrains() 
{
	// TODO: Add your control notification handler code hereF:\\humy\\test
	CString    aa;
	CString    strPath;
	CString    strTitle;
	CString    ss;
	CString    dd;
	int        i;
	int        icount;
	int        j;
	int        strnum;
	int        ii;
	int        index;
	bitarr     data;
	intarr     gets;
	strarr     str[10];
	char       *p;
	CFileFind  ff;
	CTestDoc *pDoc = (CTestDoc*)GetDocument();
    CAnalyze_map info(144,144);
	trains.RemoveAll();
	BOOL res = ff.FindFile("trains\\*.bmp");
	icount=0;
	for (i=0;i<10;i++) 
		str[i].RemoveAll();
	while (res) 
	{
		icount++;
		res = ff.FindNextFile();
		strPath = ff.GetFilePath();	
		strTitle = ff.GetFileName();
        for (i=0;i<10;i++)
		{
			aa.Format("%d",i);
            p=aa.GetBuffer(aa.GetLength());
	        if(!strTitle.FindOneOf(p))
			{
				this->GetDocument()->OnOpenDocument(strPath);
                data.RemoveAll();
		        data.Copy(mapdata);
	            info.analyse_chara(gets,data);
		        ss="";
		 	    for (int j=0;j<13;j++) 
				{
					dd.Format("%d",gets.GetAt(j));
	                ss+=dd;
				}
		//===============================================add to file
                str[i].Add(ss);
		//----------------------------------------------------------
		 
			}
		} 
	}
//==================================================================存入文件。文件流
   char      yubo; 
   ofstream  fin;
   ofstream  fnum;
   fin.open("FILE\\Train_P.txt");
   fnum.open("FILE\\Train_Num.txt");
   for (index=0;index<10;index++) 
   {
	   strnum = str[index].GetSize();
	   for (ii=0;ii<strnum;ii++) 
	   {
		   j= str[index].GetAt(ii).GetLength();
           for (i=0;i<j;i++)
		   {
			   fin<<str[index].GetAt(ii).GetAt(i);
		   }
           fnum<<index;
	   }
   }
   fin.close();
   fnum.close();
   ifstream  fp;
   ifstream  fn;
   ofstream  fh;
   ofstream  ft;
   fp.open("FILE\\Train_P.txt");
   fn.open("FILE\\Train_Num.txt");
   fh.open("FILE\\Train_Hop.txt");
   ft.open("FILE\\Train_T.txt");
   i=0;
   while ((fp>>yubo)&&fp)
   {
       switch(yubo-48)
	   {
		case 0:fh<<8<<8<<8;
			break;
		case 1:fh<<8<<8<<1;
			break;
		case 2:fh<<8<<1<<8;
			break;
		case 3:fh<<8<<1<<1;
			break;
		case 4:fh<<1<<8<<8;
			break;
		case 5:fh<<1<<8<<1;
			break;
		case 6:fh<<1<<1<<8;
			break;
		case 7:fh<<1<<1<<1;
			break;
		default:
			break;
	   }
	}
 while ((fn>>yubo)&&fn)
 {
	switch(yubo-48)
	{
		case 0:ft<<0<<0<<0<<0;
			break;
		case 1:ft<<0<<0<<0<<1;
			break;
		case 2:ft<<0<<0<<1<<0;
			break;
		case 3:ft<<0<<0<<1<<1;
			break;
		case 4:ft<<0<<1<<0<<0;
			break;
		case 5:ft<<0<<1<<0<<1;
			break;
		case 6:ft<<0<<1<<1<<0;
			break;
		case 7:ft<<0<<1<<1<<1;
			break;
		case 8:ft<<1<<0<<0<<0;
			break;
		case 9:ft<<1<<0<<0<<1;
			break;
		default:
			break;
	}
 }
    fp.close();
	fh.close();
	ft.close();
	fn.close();
	check=TRUE;
}

void CForm::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	m_sel.SetCurSel(0);
}

void CForm::OnChangeEdit2() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	size=m_num;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -