📄 exampledlg.cpp
字号:
// exampleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "example.h"
#include "exampleDlg.h"
#include "Sjwl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExampleDlg dialog
CExampleDlg::CExampleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CExampleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CExampleDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CExampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExampleDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExampleDlg, CDialog)
//{{AFX_MSG_MAP(CExampleDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExampleDlg message handlers
BOOL CExampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CExampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CExampleDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CExampleDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
///////////////////////////神经网络开发包调用例程////////////////////////////////////
// 工程说明:本例程演示了对手写数字的识别。
// 1、 外围软件:从信息采集设备(如摄象机、数码相机、扫描仪、手写板等)输入的每一个手写体的数字图像数据,
// 经过处理后都得到一个统一规格的包含相应内容的二值表。(这些二值表可以建成训练文件以方便后期对网络进行训练)
// 2、 设计神经网络输入接口:
// a、假设本例程的外围程序都将图像转化成了24X16阵的二值表:(在这里只使用了其中分别记录着1和2的两个二值表a与b)
bool a[24][16]={
{0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,1,0,0,0,0,0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0,0,0,0,0,0,0},
{0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0},
{0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1},
{1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
{0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0}};
// b、设计接口可根据实际情况选择设计接口方案,
// 如本例的24*16点阵图就可以用一个输入神经元去依次扫描所有的点,每扫描一个点使用一个周期,扫描一幅图的时间time=24*16。
// 也可以设计24个输入神经元竖的拍成一排,从左至右或从右到左扫描,这样一幅图需要的时间time=16。
// 当然也可以用16个输入神经元从上到下的扫描,甚至可以用24*16个输入神经元在一个周期内就读入一幅图,需要的时间time=1。
//本例采用了24个输入神经元的方式:所以用SJWL_A_init(24,1000,100,5)初始化系统,后三个参数只用于调节软件的运行效率。
unsigned int aa=0,bb=0; //样本号
void CExampleDlg::OnButton1()
{
////////
if (!SJWL_A_init(24,1000,100,5)) AfxMessageBox(Err_Str);
else AfxMessageBox("初始化完成");
aa=0,bb=0;
}
void CExampleDlg::OnButton2()
{
////////打开神经网络//没有发行序列号的输入“0”
if (!SJWL_A_lib("0")) AfxMessageBox(Err_Str);
else AfxMessageBox("神经网络开启完成");
}
void CExampleDlg::OnButton3()
{
int nn,mm;
int result;
////////学习样本a
xunlian_a:
int time=16-1;//学习周期0~15
for(nn=0;nn<16;nn++)
{
for(mm=0;mm<24;mm++) //将每二值表中一列的值输入到神经元中。
{
result=SJWL_A_Input(a[mm][nn],mm,time,1,NULL,&aa);
if (result<0) {AfxMessageBox(Err_Str); return;}
if (time ==0 ) break;
}
//一个时间周期结束
if (time ==0) break;
result=SJWL_A_Cycle(5,1);
time--;
if (result<0) {AfxMessageBox(Err_Str); return;}
else if (result>0) {/*有输出,在Out_pl中的前result个数字即为输出结果*/}
}
if (result==0) goto xunlian_a;
else if (result==2) {/*将训练样本a保存到样本文件,因为每新增一个样本后都要先重学一遍其他样本*/
if (aa!=0) goto xunlian_a; else {/*你把样本放到哪儿了?*/}
}else if (result==1) {/*样本a训练完毕*/}
////////学习样本b
xunlian_b:
time=16-1;//学习周期0~15
for(nn=0;nn<16;nn++)
{
for(mm=0;mm<24;mm++) //将每二值表中一列的值输入到神经元中。
{
result=SJWL_A_Input(b[mm][nn],mm,time,2,NULL,&bb);
if (result<0) {AfxMessageBox(Err_Str); return;}
if (time ==0 ) break;
}
//一个时间周期结束
if (time ==0) break;
result=SJWL_A_Cycle(5,1);
time--;
if (result<0) {AfxMessageBox(Err_Str); return;}
else if (result>0) {/*有输出,在Out_pl中的前result个数字即为输出结果*/}
}
if (result==0) goto xunlian_b;
else if (result==2) {/*将训练样本b保存到样本文件,因为每新增一个样本后都要先重学一遍其他样本*/
if (aa!=0) goto xunlian_a; else {/*你把样本a放到哪儿了?*/}
}else if (result==1) {/*样本b训练完毕*/}
if (Study_Over) AfxMessageBox("神经网络训练完毕!!!");
else {Study_Over=true; goto xunlian_a;}
}
void CExampleDlg::OnButton4()
{
///////////关闭神经网络
if (!SJWL_A_lib_Close()) AfxMessageBox(Err_Str);
else AfxMessageBox("神经网络关闭完成");
}
//////////////////////////////应用/////////////////////////////////
void CExampleDlg::OnButton5()
{
if (!SJWL_B_lib("0")) AfxMessageBox(Err_Str);
else AfxMessageBox("神经网络开启完成");
}
void CExampleDlg::OnButton6()
{
int nn,mm;
int result;
char str[80];
char strtmp[10];
////////学习样本a
int time=16-1;//学习周期0~15
for(nn=0;nn<16;nn++)
{
for(mm=0;mm<24;mm++) //将每二值表中一列的值输入到神经元中。
{
result=SJWL_B_Input(a[mm][nn],mm);
if (result<0) {AfxMessageBox(Err_Str); return;}
if (time ==0 ) break;
}
//一个时间周期结束
result=SJWL_B_Cycle(10);
time--;
if (result<0) {AfxMessageBox(Err_Str); return;}
else if (result>0) {/*有输出,在Out_pl中的前result个数字即为输出结果*/
strcpy(str,"");
for(mm=0;mm<result&&mm<80;mm++)
{
itoa(*(Out_pl+mm),strtmp,10);
strcat(str,strtmp);strcat(str,"|");
}
AfxMessageBox(str);
}
}
//注意:系统不会马上给出识别的结果,因为SJWL_B_Cycle(10)中带了延时参数“10”
////////学习样本b
////////
for(nn=0;nn<16;nn++)
{
for(mm=0;mm<24;mm++) //将每二值表中一列的值输入到神经元中。
{
result=SJWL_B_Input(b[mm][nn],mm);
if (result<0) {AfxMessageBox(Err_Str); return;}
if (time ==0 ) break;
}
//一个时间周期结束
result=SJWL_B_Cycle(10);
if (result<0) {AfxMessageBox(Err_Str); return;}
else if (result>0) {/*有输出,在Out_pl中的前result个数字即为输出结果*/
strcpy(str,"");
for(mm=0;mm<result&&mm<80;mm++)
{
itoa(*(Out_pl+mm),strtmp,10);
strcat(str,strtmp);strcat(str,"|");
}
AfxMessageBox(str);
}
}
AfxMessageBox("神经网络识别完毕!!!");
}
void CExampleDlg::OnButton7()
{
if (!SJWL_B_lib_Close()) AfxMessageBox(Err_Str);
else AfxMessageBox("神经网络关闭完成");
}
void CExampleDlg::OnButton8()
{
char shenqing[300];
Get_Shenqing(shenqing);
AfxMessageBox(shenqing);
}
void CExampleDlg::OnButton9()
{
char shenqing[300];
strcpy(shenqing,"在此输入序列号");
if (!Set_Shenqing(shenqing))
{
AfxMessageBox(Err_Str);
}
}
void CExampleDlg::OnButton10()
{
char shenqing[300];
Get_Shenqing(shenqing);
AfxMessageBox(shenqing);
}
void CExampleDlg::OnButton11()
{
char shenqing[300];
strcpy(shenqing,"在此输入序列号");
if (!Set_Shenqing(shenqing))
{
AfxMessageBox(Err_Str);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -