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

📄 livematch.cpp

📁 通过VC++的MFC实现指纹的实时采集比对和在指纹库里进行指纹的比对。实现了指纹实用性的功能
💻 CPP
字号:
// LiveMatch.cpp : implementation file
//

#include "stdafx.h"
#include "MyFPSys.h"
#include "LiveMatch.h"
#include "FPA.H"

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

#define MAXRECORD 256
/////////////////////////////////////////////////////////////////////////////
// LiveMatch dialog
BYTE *lpLiveData1 = new BYTE[92160];
BYTE *lpFeature1 = new BYTE[430];
CString LiveFilePath;
int IndexList[MAXRECORD];
int ListSize;
CString DatabasePath;
bool bIdentify = false;


LiveMatch::LiveMatch(CWnd* pParent /*=NULL*/)
	: CDialog(LiveMatch::IDD, pParent)
{
	//{{AFX_DATA_INIT(LiveMatch)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void LiveMatch::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(LiveMatch)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(LiveMatch, CDialog)
	//{{AFX_MSG_MAP(LiveMatch)
	ON_BN_CLICKED(IDC_BUTTON_CAP, OnButtonCap)
	ON_BN_CLICKED(IDC_BUTTON_CLOSESENSOR, OnButtonClosesensor)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON_CREATE, OnButtonCreate)
	ON_BN_CLICKED(IDC_BUTTON_LOAD, OnButtonLoad)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
	ON_BN_CLICKED(IDC_BUTTON_IDENTIFY, OnButtonIdentify)
	ON_BN_CLICKED(IDC_BUTTON_NIDENTIFY, OnButtonNidentify)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// LiveMatch message handlers

void LiveMatch::OnButtonCap() 
{
	// TODO: Add your control notification handler code here
	int ret = FPA_Camera_Init();

	TCHAR tchBuffer[256 ]; 
	LPTSTR lpszCurDir;
	lpszCurDir = tchBuffer; 
	GetCurrentDirectory(256 , lpszCurDir);
	CString showme(lpszCurDir);
	LiveFilePath = showme + "\\live.bmp";
	

	SetTimer(1, 1000, 0);
}

void LiveMatch::OnButtonClosesensor() 
{
	// TODO: Add your control notification handler code here
	KillTimer(1);
	FPA_Camera_Exit();
	
}

void LiveMatch::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	int Size;
	CString t;

	if (nIDEvent == 1)
	{		
		FPA_Camera_Capture_File(LiveFilePath, lpLiveData1, 0);		
		
		HBITMAP m_hImage;
				
		m_hImage = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
								LiveFilePath,
								IMAGE_BITMAP,
								0,
								0,
								LR_LOADFROMFILE|LR_CREATEDIBSECTION);
		GetDlgItem(IDC_STATIC_LIVE)->SendMessage(STM_SETIMAGE,IMAGE_BITMAP, (LPARAM)m_hImage);

		
		if (bIdentify)
		{
			int ret = FPA_AnalyzeFeature_File((LPCSTR)LiveFilePath, lpFeature1, &Size);

			if (ret == 0)
			{			
				ret = FPA_Identify(DatabasePath, IndexList, ListSize, lpFeature1);			
		
				if (ret != -1)
				{
					int ID = IndexList[ret] / 10;
					int FingerIndex = IndexList[ret] % 10;

					t.Format("accept!   ID: %d\t\tFingerIndex:%d", ID, FingerIndex);
				}
				else
				{
					t.Format("not accept");
				}
			}
			else
			{
				t.Format("Capturing...");
			}

		
		}
		else
		{
			t.Format("Capturing...");
		}
			
		SetDlgItemText(IDC_STATIC_STATUS, t);
	}

	CDialog::OnTimer(nIDEvent);
}


void LiveMatch::OnButtonCreate() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(TRUE,"txt",".txt",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Text (*.txt)|*.TXT||");
	
	if (dlg.DoModal() != IDOK) return;		
	
	DatabasePath = dlg.GetPathName();

	FPA_CreateDatabase(DatabasePath, IndexList, &ListSize);
}

void LiveMatch::OnButtonLoad() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(TRUE,"txt",".txt",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Text (*.txt)|*.TXT||");

	if (dlg.DoModal() != IDOK) return;		

	DatabasePath = dlg.GetPathName();

	FPA_LoadDatabase(DatabasePath, IndexList, &ListSize);

	CString msg;
	msg.Format("Number of Record: %d", ListSize);
	AfxMessageBox(msg);
}

void LiveMatch::OnButtonSave() 
{
	// TODO: Add your control notification handler code here
	FPA_SaveDatabase(DatabasePath, IndexList, ListSize);
}

void LiveMatch::OnButtonAdd() 
{
	// TODO: Add your control notification handler code here
	CString FolderName = DatabasePath;
	int t = FolderName.ReverseFind('\\');
	FolderName = FolderName.Left(t);
		
	CString IDStr, FingerIndexStr;	
	GetDlgItemText(IDC_EDIT_ID, IDStr);
	GetDlgItemText(IDC_EDIT_FINGERINDEX, FingerIndexStr);

	

	int ID = atoi((LPCSTR)IDStr);
	int FingerIndex = atoi((LPCSTR)FingerIndexStr);

	int Size;

	BYTE lpFeature[430];

	FPA_AnalyzeFeature_File(LiveFilePath, lpFeature, &Size);	

	int ret = FPA_AddEntry(FolderName, ID, IndexList, &ListSize, FingerIndex, lpFeature);

	if (ret == 0)
		SetDlgItemText(IDC_STATIC_ADDSTATUS, "add successfully");
	else
		SetDlgItemText(IDC_STATIC_ADDSTATUS, "fail. please change id");
}

void LiveMatch::OnButtonIdentify() 
{
	// TODO: Add your control notification handler code here
	if (ListSize >= 0)
		bIdentify = true;
}

void LiveMatch::OnButtonNidentify() 
{
	// TODO: Add your control notification handler code here
	bIdentify = false;	
}

⌨️ 快捷键说明

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