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

📄 enrollmentdlg.cpp

📁 DigitalPersona.rar
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//{
//	m_mcRegOptions = 0;
//
//	if (BST_CHECKED == IsDlgButtonChecked(IDB_DISABLE_DEFAULT_REG))
//		m_mcRegOptions |= FT_DISABLE_DEFAULT_REG;
//
//	if (BST_CHECKED == IsDlgButtonChecked(IDB_ENABLE_LEARNING))
//		m_mcRegOptions |= FT_ALLOW_LEARNING;
//
//	if (BST_CHECKED == IsDlgButtonChecked(IDB_ENABLE_XTF_REG))
//		m_mcRegOptions |= FT_ENABLE_XTF_REG;
//
//	return 0;
//}

void CEnrollmentDlg::DisplayFingerprintImage(FT_IMAGE_PT pFingerprintImage)
{
	HRESULT hr = S_OK;
	BITMAPINFO* pOutImage = NULL;
	try {
		// Prepare bitmap header and color table
		LONG dx = m_rcDrawArea.right - m_rcDrawArea.left;
		LONG dy = m_rcDrawArea.bottom - m_rcDrawArea.top;

		WORD uBPP = 8;
		ULONG LineWidth = WIDTHBYTES(dx * uBPP);

		int nColors = 256;
		DWORD dwColorsSize = nColors * sizeof(PALETTEENTRY);

		ULONG OutImgSize = sizeof(BITMAPINFOHEADER) + dwColorsSize + LineWidth * dy;
		if (NULL == (pOutImage = (BITMAPINFO*)new BYTE[OutImgSize])) _com_issue_error(E_OUTOFMEMORY);

		ULONG uImgSize = LineWidth*dy;

		// Height should be negative because the bitmap is a top-down.
		FillBitmapInfoHeader(&pOutImage->bmiHeader, dx, -dy, uImgSize, uBPP, nColors);

		PALETTEENTRY* pEntries = (PALETTEENTRY*)((LPBYTE)pOutImage + pOutImage->bmiHeader.biSize);
		FillColorTable(pEntries, nColors);

		FT_IMAGE_SIZE ImageSize = {LineWidth, dy};

		// call the toolkit function to get image pixels and draw the bitmap
		FT_RETCODE rc = FX_getDisplayImage(m_fxContext,         // Context of Feature Extraction
		                                   pFingerprintImage,   // Pointer to the image buffer
		                                   &ImageSize,          // Dimensions of the image - width must be divisible by 4 as appropriate for bitmaps
		                                   FALSE,               // Rotation, FALSE means do not rotate
		                                   nColors,             // requested number of intensity levels
		                                   ((BYTE *)pOutImage) + sizeof(BITMAPINFOHEADER) + dwColorsSize);
		if (FT_OK <= rc) {
			// Create bitmap and set its handle to the control for display.
			LPBYTE dstBits = NULL;
			HBITMAP hBmp = CreateDIBSection(0, pOutImage, DIB_RGB_COLORS, (void**)&dstBits, 0, 0);
			memcpy(dstBits, ((BYTE *)pOutImage) + sizeof(BITMAPINFOHEADER) + dwColorsSize, uImgSize);
			HBITMAP hOldBmp = reinterpret_cast<HBITMAP>(SendDlgItemMessage(IDC_STATIC_DRAWAREA, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmp));
			if (hOldBmp)
				DeleteObject(hOldBmp);
		}
	}
	catch(_com_error E) {
		hr = E.Error();
	}
	catch(...) {
		hr = E_UNEXPECTED;
	}
	delete [] pOutImage;

	if (FAILED(hr))
		ReportError(m_hWnd, hr);
}

void CEnrollmentDlg::AddToEnroll(FT_IMAGE_PT pFingerprintImage, int iFingerprintImageSize)
{
	HRESULT hr = S_OK;
	FT_BYTE* pPreRegTemplate = NULL;
	FT_BYTE* pRegTemplate = NULL;
	try {
		if (m_nRegFingerprint < m_NumberOfPreRegFeatures) { // Do not generate more Pre-Enrollment feature sets than needed
			FT_RETCODE rc = FT_OK;

			// Get recommended length of the Pre-Enrollment Fingerprint feature sets.
			// It actually could be done once at the beginning, but this is just sample code...
			int iRecommendedPreRegFtrLen = 0;
			rc = FX_getFeaturesLen(FT_PRE_REG_FTR,
								   &iRecommendedPreRegFtrLen,
								   NULL); // Minimal Fingerprint feature set Length - do not use if possible
			if (FT_OK != rc) _com_issue_error(E_FAIL);

			// Extract Features (i.e. create fingerprint template)
			FT_IMG_QUALITY imgQuality;
			FT_FTR_QUALITY ftrQuality;
			FT_BOOL bEextractOK = FT_FALSE;

			if (NULL == (pPreRegTemplate = new FT_BYTE[iRecommendedPreRegFtrLen])) _com_issue_error(E_OUTOFMEMORY);
			rc = FX_extractFeatures(m_fxContext,              // Context of Feature Extraction
									iFingerprintImageSize,    // Size of the fingerprint image
									pFingerprintImage,        // Pointer to the image buffer
									FT_PRE_REG_FTR,           // Requested Pre-Enrollment Features
									iRecommendedPreRegFtrLen, // Length of the Features(template) buffer received previously from the SDK
									pPreRegTemplate,          // Pointer to the buffer where the template to be stored
									&imgQuality,              // Returned quality of the image. If feature extraction fails because used did not put finger on the reader well enough, this parameter be used to tell the user how to put the finger on the reader better. See FT_IMG_QUALITY enumeration.
									&ftrQuality,              // Returned quality of the features. It may happen that the fingerprint of the user cannot be used. See FT_FTR_QUALITY enumeration.
									&bEextractOK);            // Returned result of Feature extraction. FT_TRUE means extracted OK.

			// If feature extraction succeeded, add the pre-Enrollment feature sets 
			// to the set of 4 templates needed to create Enrollment template.
			if (FT_OK <= rc && bEextractOK == FT_TRUE) {
				AddStatus(L"Pre-Enrollment feature set generated successfully");

				m_TemplateArray[m_nRegFingerprint++] = pPreRegTemplate;
				pPreRegTemplate = NULL;   // This prevents deleting at the end of the function

				// Display current fingerprint image number and total required number of images.
				WCHAR buffer[101] = {0};
				ULONG uSize = 100;
				_snwprintf(buffer, uSize, L"%ld", m_nRegFingerprint);
				SetDlgItemText(IDC_IMAGE_NUM, buffer);
				_snwprintf(buffer, uSize, L"%ld", m_NumberOfPreRegFeatures);
				SetDlgItemText(IDC_IMAGE_TOTAL, buffer);

				if (m_nRegFingerprint == m_NumberOfPreRegFeatures) { // We collected enough Pre-Enrollment feature sets, create Enrollment template out of them.
					// Get the recommended length of the fingerprint template (features).
					// It actually could be done once at the beginning, but this is just sample code...
					int iRecommendedRegFtrLen = 0;
					rc = MC_getFeaturesLen(FT_REG_FTR,
										   m_mcRegOptions,
										   &iRecommendedRegFtrLen,
										   NULL);

					if (FT_OK != rc) _com_issue_error(E_FAIL);

					if (NULL == (pRegTemplate = new FT_BYTE[iRecommendedRegFtrLen])) _com_issue_error(E_OUTOFMEMORY);

					FT_BOOL bRegSucceeded = FT_FALSE;
					rc = MC_generateRegFeatures(m_mcContext,              // Matching Context
												m_mcRegOptions,           // Options - collected from checkboxes in the dialog
												m_NumberOfPreRegFeatures, // Number of Pre-Enrollment feature sets submitted. It must be number received previously from the SDK.
												iRecommendedPreRegFtrLen, // Length of every Pre-Enrollment feature sets in the array
												m_TemplateArray,          // Array of pointers to the Pre-Enrollment feature sets
												iRecommendedRegFtrLen,    // Length of the Enrollment Features(template) buffer received previously from the SDK
												pRegTemplate,             // Pointer to the buffer where the Enrollment template to be stored
												NULL,                     // Reserved. Must always be NULL.
												&bRegSucceeded);          // Returned result of Enrollment Template creation. FT_TRUE means extracted OK.

					if (FT_OK <= rc && bRegSucceeded == FT_TRUE) {
						// Enrollment template is generated.
						// Normally it should be saved in some database, etc.
						// Here we just put it into a BLOB to use later for verification.
						m_RegTemplate.pbData = pRegTemplate;
						m_RegTemplate.cbData = iRecommendedRegFtrLen;

						pRegTemplate = NULL;   // This prevents deleting at the end of the function

						AddStatus(L"Enrollment Template generated successfully");
						SetDlgItemText(IDC_EDIT_PROMPT, L"Close this dialog and run Verification to verify fingerprint");
					}
					else {
						MessageBox(L"Creation of Enrollment Template Failed.", L"Fingerprint Enrollment", MB_OK | MB_ICONINFORMATION);
						SetDlgItemText(IDC_EDIT_PROMPT, L"Scan your finger for enrollment.");
						// Enrolment faled, cleanup data.
						m_nRegFingerprint = 0;

						for (int i=0; i<m_NumberOfPreRegFeatures; ++i)
							if(m_TemplateArray[i]) delete [] m_TemplateArray[i], m_TemplateArray[i] = NULL; // Delete Pre-Enrollment feature sets stored in the array.
					}
				}
				else {
					// This is normal cource of events, before all 4 fingerprint images are captured.
					SetDlgItemText(IDC_EDIT_PROMPT, L"Scan same finger again.");
				}
			}
			else {
				MessageBox(L"Creation of Pre-Enrollment feature set Failed.", L"Fingerprint Enrollment", MB_OK | MB_ICONINFORMATION);
				SetDlgItemText(IDC_EDIT_PROMPT, L"Scan your finger for enrollment.");
			}
		}
		else {
			MessageBox(L"An Enrollment Template has already been created.\n\nClose the dialog, then select \"Fingerprint Verification\" or \"Save Fingerprint Enrollment Template\".", L"Fingerprint Enrollment", MB_OK | MB_ICONSTOP);
		}
	}
	catch(_com_error E) {
		hr = E.Error();
	}
	catch(...) {
		hr = E_UNEXPECTED;
	}
	delete [] pPreRegTemplate;
	delete [] pRegTemplate;

	if (FAILED(hr))
		ReportError(m_hWnd, hr);
}

⌨️ 快捷键说明

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