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

📄 iddetect.cpp

📁 北京航空航天大学指纹识别系统源码
💻 CPP
字号:
// IdDetect.cpp : implementation file
//

#include "stdafx.h"
#include "FingerDemo.h"
#include "IdDetect.h"
#include "fingerdll.h"
#include "scandialog.h"
#include "zhongzhgetbmp.h"

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

/////////////////////////////////////////////////////////////////////////////
// CIdDetect
extern CFingerDemoApp theApp;

IMPLEMENT_DYNCREATE(CIdDetect, CRecordView)

CIdDetect::CIdDetect()
	: CRecordView(CIdDetect::IDD)
{
	//{{AFX_DATA_INIT(CIdDetect)
	m_pSet = NULL;
	//}}AFX_DATA_INIT

	quli=type=0;
	cenx=ceny=0;
	m_Minutia1=(unsigned char*)GlobalAlloc(GMEM_FIXED,MAXNUM*DIM+4);
	m_Minutia2=(unsigned char*)GlobalAlloc(GMEM_FIXED,MAXNUM*DIM+4);
	memset(m_Minutia1,0,MAXNUM*DIM+4);
	memset(m_Minutia2,0,MAXNUM*DIM+4);
	sbmp=new Scan_Bmp();
	sbmp->ReadFile(theApp.m_ProgramePath+"\\Samplea.bmp");
	this->OnGetRecordset();
	theApp.m_pDistinView=this;
}

CIdDetect::~CIdDetect()
{
	GlobalFree(m_Minutia1);
	GlobalFree(m_Minutia2);
	delete sbmp;
	theApp.m_bFingerDistin=false;

	if (m_pSet)
		delete m_pSet;
}

void CIdDetect::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIdDetect)
	DDX_Control(pDX, IDC_FINGER_BMP, m_Image);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CIdDetect, CRecordView)
	//{{AFX_MSG_MAP(CIdDetect)
	ON_BN_CLICKED(IDC_INPORT_BMPFILE, OnInportBmpfile)
	ON_BN_CLICKED(IDC_INPORT_CAPTURE, OnInportCapture)
	ON_BN_CLICKED(IDC_SHIBIE, OnShibie)
	ON_WM_ERASEBKGND()
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIdDetect diagnostics

#ifdef _DEBUG
void CIdDetect::AssertValid() const
{
	CRecordView::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CIdDetect message handlers

CRecordset* CIdDetect::OnGetRecordset()
{
	if (m_pSet != NULL)
		return m_pSet;

	m_pSet = new CFingerDemoSet(NULL);
	m_pSet->Open();

	return m_pSet;
}

CFingerDemoSet* CIdDetect::GetRecordset()
{
	CFingerDemoSet* pData = (CFingerDemoSet*) OnGetRecordset();
	ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CFingerDemoSet)));
	return pData;
}

void CIdDetect::OnInitialUpdate()
{
	BeginWaitCursor();
	GetRecordset();
	CRecordView::OnInitialUpdate();
	if (m_pSet->IsOpen())
	{
		CString strTitle = m_pSet->m_pDatabase->GetDatabaseName();
		CString strTable = m_pSet->GetTableName();
		if (!strTable.IsEmpty())
			strTitle += _T(":") + strTable;
		GetDocument()->SetTitle(strTitle);
	}
	EndWaitCursor();
	
}

void CIdDetect::OnInportBmpfile() 
{
	// TODO: Add your control notification handler code here
	CFileDialog fg(TRUE, // TRUE for FileOpen, FALSE for FileSaveAs
		"*.bmp",
		NULL,
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		"位图文件(*.bmp)|*.bmp",
		this);
	if(fg.DoModal() == IDOK)
	{
		CString fn;
		fn=fg.GetFileName();
		sbmp->ReadFile(fn);
		CPaintDC dc(this); // device context for painting
    	sbmp->DrawDib(m_Image.GetDC(),1,0,0);
	}
	if(!GetMinutia(sbmp->m_Bmp_pBmpValue,NULL,sbmp->m_Height,sbmp->m_Width ,m_Minutia1,quli,type,cenx,ceny))
	{
		MessageBox("指纹图像不合格,请重试!","注意",MB_OK);
		return;
	}
	
}

void CIdDetect::OnInportCapture() 
{
	// TODO: Add your control notification handler code here
 if(theApp.cap_type==1)//////////光电指纹采集仪采集图像/////////////////////
 {
	 CScanDialog gfr(sbmp);
    	if(gfr.DoModal()==IDOK)
		{
        	if(!GetMinutia(sbmp->m_Bmp_pBmpValue,NULL,sbmp->m_Height,sbmp->m_Width ,m_Minutia1,quli,type,cenx,ceny))
			{
	        	MessageBox("指纹图像不合格,请重试!","注意",MB_OK);
        		return;
			}
			RECT rc;
			GetDlgItem(IDC_FINGER_BMP)->GetWindowRect(&rc);
			InvalidateRect(&rc);

		}
 }
 else if(theApp.cap_type==2)/////////////电容传感器采集指纹图像////////////
 {
	CZhongzhGetBmp zz;
	zz.GetBmp(sbmp);
    if(!GetMinutia(sbmp->m_Bmp_pBmpValue,NULL,sbmp->m_Height,sbmp->m_Width ,m_Minutia1,quli,type,cenx,ceny))
	{
	    MessageBox("指纹图像不合格","注意",MB_OK);
	   	return;
	}
	RECT rc;
	GetDlgItem(IDC_FINGER_BMP)->GetWindowRect(&rc);
	InvalidateRect(&rc);
 }

}

void CIdDetect::OnShibie() 
{
	// TODO: Add your control notification handler code here
	int res=0;
	BYTE *buff;
	bool isdetect=false;
if(!theApp.testdb)
{
	if(!m_pSet)
	{
		MessageBox("指纹数据库无法打开","注意",MB_OK);
		return;
	}
	m_pSet->Requery();
	while(!m_pSet->IsEOF())
	{
		if(m_pSet->m_type==type)
		{
        	buff=m_pSet->m_feature.GetData();
        	if(m_pSet->m_feature.GetSize()>3)
			{
	        	memcpy(m_Minutia2,buff,MAXNUM*DIM+4);//m_pSet->m_feature.GetSize());
				res=FingerMatch(m_Minutia1,m_Minutia2,cenx,ceny,m_pSet->m_centerx,m_pSet->m_centery);
            	if(res>=theApp.m_nMatchDoor)
				{
					isdetect=true;
					break;
				}
			}
		}
		m_pSet->MoveNext();
	}
	if(isdetect)
		MessageBox("欢迎您:"+m_pSet->m_name,"您好",MB_OK);
	else
		MessageBox("对不起!请您在指纹数据库中注册您的指纹,然后再进行识别","注意",MB_OK);

}
else
{
	FPTEST* test;
	test=theApp.testdb;
	for(int i=0;i<theApp.num;i++)
	{
		if(test->type==type)
		{
			res=FingerMatch(m_Minutia1,test->minu,cenx,ceny,test->centerx,test->centery);
           	if(res>=theApp.m_nMatchDoor)
			{
				isdetect=true;
				break;
			}
		}
		test++;
	}
	if(isdetect)
		MessageBox("欢迎您:"+CString(test->name),"您好",MB_OK);
	else
		MessageBox("对不起!请您在指纹数据库中注册您的指纹,然后再进行识别","注意",MB_OK);

}

	

}

void CIdDetect::OnDraw(CDC* pDC) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(sbmp)
	    sbmp->DrawDib(m_Image.GetDC(),1,0,0);

}

BOOL CIdDetect::OnEraseBkgnd(CDC* pDC) 
{
	theApp.backbmp.ReadFile(theApp.m_backfilename);//"c:\\z1.bmp"	
	CRect rect;
	GetClientRect(&rect);
	for (int nX = 0; nX < rect.Width(); nX +=theApp.backbmp. m_Width)
		for (int nY = 0; nY < rect.Height(); nY +=theApp.backbmp. m_Height)
			theApp.backbmp.DrawDib(pDC,1,nX,nY);
	return TRUE;
}

HBRUSH CIdDetect::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CRecordView::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if(nCtlColor==CTLCOLOR_EDIT||nCtlColor==CTLCOLOR_LISTBOX)
		return hbr;
	else
	{
		pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(theApp.m_textcolor);
		return ((HBRUSH)::GetStockObject(HOLLOW_BRUSH));
	}

	// TODO: Return a different brush if the default is not desired
	return hbr;
}

⌨️ 快捷键说明

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