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

📄 fingerdlg.cpp

📁 这是个手指指纹识别的源代码 ,也是从网络上下载的
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// FingerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Finger.h"
#include "FingerDlg.h"
#include "Dib.h"
#include "DIBStatic.h"
#include "math.h"
#include "CustomRs.h"
#include "Count.h"
#include "FingerEnd.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()

/////////////////////////////////////////////////////////////////////////////
// CFingerDlg dialog

CFingerDlg::CFingerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFingerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFingerDlg)	
	m_EmployeeName = _T("");
	m_EmployeeDepartName = _T("");
	m_TimeOutCharge = COleDateTime::GetCurrentTime();
	m_TimeOnCharge = COleDateTime::GetCurrentTime();
	m_EmployeeId = _T("");
	m_TimeType = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFingerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFingerDlg)
	DDX_Text(pDX, IDC_NAME, m_EmployeeName);
	DDX_Text(pDX, IDC_DEPARTNAME, m_EmployeeDepartName);
	DDX_Text(pDX, IDC_OUTCHARGE, m_TimeOutCharge);
	DDX_Text(pDX, IDC_ONCHARGE, m_TimeOnCharge);
	DDX_Text(pDX, IDC_ID, m_EmployeeId);
	DDX_Text(pDX, IDC_CHARGETYPE, m_TimeType);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFingerDlg, CDialog)
	//{{AFX_MSG_MAP(CFingerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_Exit, OnExit)
	ON_BN_CLICKED(IDC_OnWork, OnOnWork)
	ON_BN_CLICKED(IDC_OutWork, OnOutWork)
	ON_BN_CLICKED(IDC_ZhuCe, OnZhuCe)
	ON_BN_CLICKED(IDC_GoOut, OnGoOut)
	ON_BN_CLICKED(IDC_GoBack, OnGoBack)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFingerDlg message handlers

//************************************************************
BYTE data[300][300];            ///////
BYTE data0[300][300];           ////////
BYTE direct[300][300];//用来记录方向场的数值;
int databmp[300][2];
CDIBStatic m_DIBStatic;
LPBYTE pMypdib;
CDib m_Dib;
////////////////////////
int zhubiao;
int dengji;
struct enddian
{
int x;
int y;
int dirx;
int diry;
};
int zhuendcount;
int newendcount;
int moendcount;
enddian  zhuenddian[20];
enddian  moenddian[20];
enddian  newenddian[20];
////////////////////////
int lx,ly;
int m_idengflag;
BOOL Being=FALSE;
BOOL IfRead=FALSE;
BOOL ChangeWindow;
BOOL DoubleValueOK=FALSE;

BYTE beijin[300][300];
BYTE show[300][300];
int count;
BYTE mart[300][300];
int tvx,tvy;
int linendx,linendy;
int lianban[60][60];
int nextx,nexty;
BYTE c[300][300];


//************************************************************


BOOL CFingerDlg::OnInitDialog()
{
	
	CDialog::OnInitDialog();   
	// Add "About..." menu item to system menu.	
		m_DIBStatic.SubclassDlgItem(IDC_IMAGE, this);	
	// 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
    createDB();
	pMypdib=NULL;
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFingerDlg::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 CFingerDlg::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
	{
		if(Being)
		{
			ShowBmp();
			m_DIBStatic.UpdateDib();
		}
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CFingerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}



////////////////////////////////////////////////
////////////求全图的均值
int CFingerDlg::GiveDataAvery()
{
	long sum=0,number=0;	 
	for(int c=4;c<296;c++)
	{
		 for(int d=databmp[c][0];d<databmp[c][1];d++)
		 {
			 sum+=data[c][d];
			 number++;			
		 }
	}
	if((float)((int)(sum/number)+0.5)<(sum/number))
		return( (int)(sum/number));
	return((int)(sum/number)+1);
}
////////////////////////////////////////////////
////////求全图的方差
long CFingerDlg::GiveDataSqurtgap()
{
	int Number=0;
	long squrtgap=0;
	GiveDatabmp();
	int averry=GiveDataAvery();
	for(int i=4;i<296;i++)
		for(int j=databmp[i][0];j<databmp[i][1];j++)
		{
			squrtgap+=( (data[i][j]-averry) * (data[i][j]-averry) );
			Number++;
		}
		return(squrtgap/(Number-1));
}
//////////////////////////////////
/////求平均值
float CFingerDlg::FindAvery(int a0,int a1,int a2,int a3,int a4,int a5,int a6)
{
	return (((float)a0+(float)a1+(float)a2+(float)a3+(float)a4+(float)a5+(float)a6)/7);
}
////////////////////////////////
/////求方差
float CFingerDlg::FindAveriance(int a0,int a1,int a2,int a3,int a4,int a5,int a6,float a)
{
	return(((float)a0-a)*((float)a0-a)
            +((float)a1-a)*((float)a1-a)
			+((float)a2-a)*((float)a2-a)
			+((float)a3-a)*((float)a3-a)
			+((float)a4-a)*((float)a4-a)
			+((float)a5-a)*((float)a5-a)
			+((float)a6-a)*((float)a6-a));
}

//////////////////////////////////////////////////////////////////////
//////得到数组
void CFingerDlg::GiveData()
{
	pMypdib=m_DIBStatic.GetPBmp();
    LPBYTE p=pMypdib;
	if(p==NULL)
   {
		AfxMessageBox("No Data!!");
		return;
   }
	if(p!=NULL)
	{
	for(int i=0;i<300;i++)
		for(int j=0;j<300;j++)
		{
			data[i][j]=(*p);
			p++;
		}
		
	}
}

///////////////////////////////////////////////
////得到数组
void CFingerDlg::GiveDatabmp()
{
	 for(int i=0;i<300;i++)
	{		    
			for(int j=3;j<150;j++)
			{
				if(data[i][j]<=200)
				break;				
			}
			databmp[i][0]=j;			
	}
	///////
	 for(int x=0;x<300;x++)
	{		    
			for(int y=297;y>150;y--)
			{
				if(data[x][y]<=200)
				break;			
			}
			databmp[x][1]=y;			
	}
	 	for(int k=0;k<300;k++)
		{
			if(databmp[k][0]<4)databmp[k][0]=4;
			if(data[k][1]>295)databmp[k][1]=295;
		}
		//////////////////
	for(int t=0;t<4;t++)
		for(int j=0;j<300;j++)data[t][j]=255;
	for(int f=300;f>296;f--)
		for(int j=0;j<300;j++)data[f][j]=255;

    for(int l=4;l<296;l++)
		for(int m=0;m<databmp[l][0];m++)data[l][m]=255;
    for(int h=4;h<296;h++)
		for(int m=300;m>databmp[h][1];m--)data[h][m]=255;
}

/////////////////////////////////////////////////////////////////
//////////图象二值化
///二值化nXn模板
void CFingerDlg::BordDoubleValue(int n,int a[])
{
	int sum=0;	
	for(int i=0;i<(n*n);i++)
		sum=sum+a[i];
	sum=sum/(n*n);
	for(int j=0;j<n*n;j++)
	{
		if(a[j]<sum)a[j]=0;
		if(a[j]>=sum)a[j]=255;
	}
}





///////////////////////////////////////////////////////////////
///////显示处理后的图片
void CFingerDlg::ShowBmp()
{
	CClientDC Mydc(this);
		int color=255;
		for(int i=0,k=299;i<300;i++,k--)
			for(int j=0;j<300;j++)
			{				
				color=data[k][j];
				Mydc.SetPixel(j+470,i+240,RGB(color,color,color));
			}
}

/////////////////////////////////////
/////求取方向图
///求模板角度
int CFingerDlg::BordDirection(int a[8][8])
{
   	int nCount[4];
	nCount[0]=0;   //0/180
	nCount[1]=0;   //45
	nCount[2]=0;   //90
	nCount[3]=0;   //135
	for(int i=0;i<15;i++)
		for(int j=0;j<15;j++)
		{
			int aa[4]={a[i][j],a[i][j+1],a[i+1][j],a[i+1][j+1]};
            if(aa[0]==0&&aa[1]==0&&aa[2]==1&&aa[3]==1)
				nCount[0]++;
			if(aa[0]==1&&aa[1]==1&&aa[2]==0&&aa[3]==0)
				nCount[0]++;
			//////end of 0/180
			if(aa[0]==0&&aa[1]==0&&aa[2]==0&&aa[3]==1)
				nCount[1]++;
			if(aa[0]==0&&aa[1]==1&&aa[2]==1&&aa[3]==1)
				nCount[1]++;
			if(aa[0]==1&&aa[1]==1&&aa[2]==1&&aa[3]==0)
				nCount[1]++;
			if(aa[0]==1&&aa[1]==0&&aa[2]==0&&aa[3]==0)
				nCount[1]++;
			/////end of 45
			if(aa[0]==0&&aa[1]==1&&aa[2]==0&&aa[3]==1)
				nCount[2]++;
			if(aa[0]==1&&aa[1]==0&&aa[2]==1&&aa[3]==0)
				nCount[2]++;
			/////end of 90
			if(aa[0]==0&&aa[1]==1&&aa[2]==0&&aa[3]==0)
				nCount[3]++;
			if(aa[0]==1&&aa[1]==0&&aa[2]==1&&aa[3]==1)
				nCount[3]++;
			if(aa[0]==1&&aa[1]==1&&aa[2]==0&&aa[3]==1)
				nCount[3]++;
			if(aa[0]==0&&aa[1]==0&&aa[2]==1&&aa[3]==0)
				nCount[3]++;
		}//end of 135
		int shuxu[4]={100,100,100,100};
			
			for(int past=0;past<4;past++)
			{
				int Number=0;
				for(int past1=0;past1<4;past1++)
				{
					if(nCount[past]-nCount[past1]>=0)
						Number++;
				}
				if(Number==4)
				{
					for(int l=0;l<4;l++)
						if(shuxu[l]==100)
						{
							shuxu[0]=past;
							break;
						}
				}
				
			}
		return(shuxu[0]);
}
///画模板方向图
void CFingerDlg::DrawBordDiretion(int i,int j,int n)
{
	if(n==0)
	{
		for(int r=0;r<16;r++)
		{
			if(r==7||r==8)
			for(int s=0;s<16;s++)
			{
				data[16*i+22+r][16*j+22+s]=0;			
			}
//			else

//				for(int s=0;s<16;s++)
//					data[16*i+22+r][16*j+22+s]=data[16*i+22+r][16*j+22+s]/2;
		}
	}///end of 0
	if(n==3)
	{
		for(int r=0;r<16;r++)
			for(int s=0;s<16;s++)
			{
				if(s==r)
					data[16*i+22+r][16*j+22+s]=0;
				else if(s>0&&s==r-1)
					data[16*i+22+r][16*j+22+s]=0;
				else if(s<16&&s==r+1)
					data[16*i+22+r][16*j+22+s]=0;
//				else
//				data[16*i+22+r][16*j+22+s]=data[16*i+22+r][16*j+22+s]+20;
			}
	}///end of 45
	if(n==2)
	{
		for(int r=0;r<16;r++)
			for(int s=0;s<16;s++)
			{
				if(s==7)
					data[16*i+22+r][16*j+22+s]=0;
				if(s==8)
					data[16*i+22+r][16*j+22+s]=0;
//				else
//				data[16*i+22+r][16*j+22+s]=data[16*i+22+r][16*j+22+s]+20;
			}
	}////end of 90
	if(n==1)
	{
		for(int r=0;r<16;r++)
			for(int s=0;s<16;s++)
			{
				if(s==r)
					data[16*i+37-r][16*j+22+s]=0;
				else if(s>0&&s==r-1)
					data[16*i+37-r][16*j+22+s]=0;
				else if(s<16&&s==r+1)
					data[16*i+37-r][16*j+22+s]=0;
//				else
//				data[16*i+37-r][16*j+22+s]=255;
			}
	}//////end of 135
}
//////////////////////////
////画方向图

int CFingerDlg::Takeon(int type) 
{
	// TODO: Add your control notification handler code here
    int t,v;
	duoblevalue();

	getdirect();
    delalate();
	directfilter();
	delalate();
	directfilter();
	directmid();
	directfilter();
	directmid();
	directfilter();
    thing();
	getendandstart();
    chargekongdong();
	getendandstart();
    chargezabo();
	fanwei(type);
    t=fencha(type);
	v=sao(type);
	ShowBmp();
	if(v==1&&t==1)
		return 1;
	else
	{
		MessageBox("图象质量不行");
		return 0;
	}
	}

long CFingerDlg::duoblevalue()
{
	if(!Being)
	{
		AfxMessageBox("未输入指纹图像!");
		return 0;
	}
   ////
	UpdateData(TRUE);
	int Bordwidth=10;
	int number=Bordwidth*Bordwidth;
	int aa[2500];
	for(int i=0;i<300/Bordwidth;i++)
	{
		for(int j=0;j<300/Bordwidth;j++)
		{
			for(int l=0;l<Bordwidth;l++)
			{
				for(int m=0;m<Bordwidth;m++)
				{
					aa[Bordwidth*l+m]=data[i*Bordwidth+l][j*Bordwidth+m];
				}
			}
            BordDoubleValue(Bordwidth,aa);
			for(int x=0;x<Bordwidth;x++)
			{
				for(int y=0;y<Bordwidth;y++)
				{
					data[i*Bordwidth+x][j*Bordwidth+y]=aa[Bordwidth*x+y];
				}
			}

		}
	}
	DoubleValueOK=TRUE;
	ShowBmp();
	m_DIBStatic.UpdateDib();
	return 0;
}

long CFingerDlg::getend()
{
int i,j,k,v;
BYTE t[300][300];
//////////////初始化t[][]数组
for(i=0;i<300;i++)
{
for(j=0;j<300;j++)
{
t[i][j]=140;
}
}
//////////////从左到右
for(i=2;i<298;i++)
{
j=0;
while(j<300)
	{
	if(data[i][j]>220)
	j++;
	else
		break;
	}//计算出到黑点的列值
for(k=-1;k<2;k++)
{
for(v=0;v<j;v++)
{
t[i+k][v]=255;
}
}
}
////////////////从右到左
for(i=2;i<298;i++)
{
j=299;
	while(j>0)
	{
	if(data[i][j]>220)
	j--;
	else
		break;
	}
for(k=-1;k<2;k++)
{
for(v=299;v>j;v--)
{
t[i+k][v]=255;
}
}
}
///////////////从上到下
for(i=2;i<298;i++)
{
j=0;
	while(j<300)
	{
	if(data[j][i]>220)
		j++;
	else
		break;
	}
for(k=-1;k<2;k++)
{
for(v=0;v<j;v++)
{
t[v][i+k]=255;
}
}
}
//////////////////从下到上
for(i=2;i<298;i++)
{
j=299;
	while(j>=0)
	{
	if(data[j][i]>220)
		j--;
	else
		break;
	}
for(k=-1;k<2;k++)
{
for(v=299;v>j;v--)
{
t[v][i+k]=255;
}
}
}
/////////////////////反色
for(i=0;i<300;i++)
{
for(j=0;j<300;j++)
{
if(t[i][j]==140)
t[i][j]=data[i][j];
}
}
/////////////回送到data[]去
for(i=0;i<300;i++)
{
for(j=0;j<300;j++)
{
data[i][j]=t[i][j];
}
}
ShowBmp();///显示图象
return 0;
}

long CFingerDlg::getdirect()
{
	// TODO: Add your control notification handler code here
	if(!Being)
	{
		AfxMessageBox("未输入指纹图像!");
		return 0;
	}
	int a[8][8];
	for(int i=0;i<300;i++)
	{
		for(int j=0;j<300;j++)
		{
				direct[j][i]=5;
		}
	}// 对方向场数组进行初始化,没有方向场的地方值为5;
	for(  i=1;i<37;i++)
		for( int j=1;j<37;j++)
		{
			for(int l=0;l<8;l++)
			{
				for(int m=0;m<8;m++)
				{
						if(data[8*i+l][8*j+m]<10)
							a[l][m]=1;
						else
                            a[l][m]=0;
				}
			}
			int dir;
			dir=BordDirection(a);

			for( l=0;l<8;l++)
			{
				for(int m=0;m<8;m++)
				{

⌨️ 快捷键说明

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