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

📄 main.cpp

📁 software fingerprint v1.0
💻 CPP
字号:
#include "fpreader.h"
#include "conio.h"
#include "stdlib.h"
#include "stdio.h"


#pragma comment(lib,"fpreader.lib")
int loadBMP(FILE * pFile, unsigned char ** ppImg, int * w, int * h);


void main (int argc, char ** argv)
{

	printf("press any key to start...\n");

	_getch();

	char file1[1024];
	char file2[1024];

	do
	{
		printf("first fingeprint image (in BMP-format): \n");
		scanf("%s", file1);
		
		FILE * ffp1 = fopen(file1, "rb");
		if(!ffp1)
		{
			printf("the file %s could not be opened!");
			return;
		}
		
		printf("second fingeprint image (in BMP-format): \n");
		scanf("%s", file2);
		
		FILE * ffp2 = fopen(file2, "rb");
		if(!ffp2)
		{
			fclose(ffp1);
			printf("the file %s could not be opened!");
			return;
		}

		float thres = 0.32f;
		printf("Enter the matching threshold (default value = 0.32) [0.0-1.0]: ");
		scanf("%f", &thres);

		if(thres < 0 || thres > 1)
			thres = 0.32f;

		unsigned char *pImg1 = 0;
		int w1, h1;

		unsigned char *pImg2 = 0;
		int w2, h2;

		loadBMP(ffp1, &pImg1,&w1,&h1);
		loadBMP(ffp2, &pImg2,&w2,&h2);

		Fingerprint fp1;
		Fingerprint fp2;

		image_window win(0,0,0,0);

		// encode:
		fp1.calculateFeatures(pImg1,w1,h1,win);
		fp2.calculateFeatures(pImg2,w2,h2,win);
		
		// set the matching threshold:
		fp1.setMatchingThreshold(thres);

		// compare:
		if(fp1 == fp2)
			printf("The fingerprints are identical. The matching threshold is %.3f\n", fp1.matchingThreshold() );
		else
			printf("The fingerprints are not identical. The matching threshold is %.3f\n", fp1.matchingThreshold() );


		// clean:
		fclose(ffp1);
		fclose(ffp2);

		printf("press <q> to exit or any key to continue...\n");
		
	} while(_getch() != 'q');
}




#include <windows.h>


#define DIB_HEADER_MARKER   ((WORD) ('M' << 8) | 'B')



////////////////////////////////////////////////////////////////////////////////
//
int loadBMP(FILE * pFile, unsigned char ** ppImg, int * w, int * h)
{
	BITMAPFILEHEADER   bmfHeader;
	BITMAPINFOHEADER   bmiHeader;
	void			 * pBits;
	
	try
	{
		// ...read bmfHeader:
		int nCount = fread( &bmfHeader, 1, sizeof(BITMAPFILEHEADER), pFile);
		if (nCount != sizeof( BITMAPFILEHEADER )) 
			return -1;

		if (bmfHeader.bfType != DIB_HEADER_MARKER) 
			return (FALSE);
		
		// ...read bmiHeader:
		nCount = fread((LPSTR)&bmiHeader, 1, sizeof(BITMAPINFOHEADER), pFile);
		if (nCount != sizeof( BITMAPINFOHEADER )) 
			return -2;
		
		if (bmiHeader.biHeight < 0 || bmiHeader.biWidth < 0) 
			return -3;
		
		int iRealWidth = ( ( ( bmiHeader.biWidth ) + 3) / 4 ) * 4;
		
		// ... alloc bits buffer:
		int iSize = bmiHeader.biHeight * iRealWidth * (bmiHeader.biBitCount / 8);
		if(iSize == 0)
			return -5;

		pBits = new char [iSize];
		if (!pBits)
			return -4;

		// ...read Bits:
		fseek( pFile, 256 * sizeof(RGBQUAD), SEEK_CUR);
		nCount = fread(pBits, 1, iSize, pFile);
		if (nCount != iSize) 
		{
			delete [] pBits;
			return -6;
		}

		*w = bmiHeader.biWidth;
		*h = bmiHeader.biHeight;

		*ppImg    = new unsigned char [iSize];
		if (!*ppImg)
		{
			delete [] pBits;
			return -7;
		}

		unsigned char * pOutBuf = (unsigned char *)( *ppImg );
		unsigned char * pInBuf = (unsigned char *)pBits;

		for( int y = 0; y < bmiHeader.biHeight; y++)
		{
			for( int x = 0; x < bmiHeader.biWidth ; x++)
			{
				pOutBuf[x + bmiHeader.biWidth * (bmiHeader.biHeight - y-1)] = pInBuf[x + iRealWidth * y];
			}
		}

		delete [] pBits;
	}
	catch(...)
	{
	}
	
	return 0;
}

⌨️ 快捷键说明

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