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

📄 addnewimage.cpp

📁 这是一个用c++编写的实现指纹识别的程序
💻 CPP
字号:
// AddNewImage.cpp : implementation file
//

#include "stdafx.h"
#include "eFinger.h"
#include "AddNewImage.h"
#include "bmp.h"
#include "Matching.h"
#include "enhancement.h"
#include "ip-header/fvs_enhancer.h"


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



/////////////////////////////////////////////////////////////////////////////
// AddNewImage dialog

// global data of the image
Image *image;

AddNewImage::AddNewImage(CWnd* pParent /*=NULL*/)
	: CDialog(AddNewImage::IDD, pParent)
{
	//{{AFX_DATA_INIT(AddNewImage)
	m_inputFile = _T("");
	m_slidValue = 0;
	m_value = _T("");
	//}}AFX_DATA_INIT
}


void AddNewImage::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(AddNewImage)
	DDX_Control(pDX, IDC_SLIDER1, m_slider);
	DDX_Control(pDX, IDC_bmp6, m_bmp6);
	DDX_Control(pDX, IDC_bmp5, m_bmp5);
	DDX_Control(pDX, IDC_bmp4, m_bmp4);
	DDX_Control(pDX, IDC_bmp2, m_bmp2);
	DDX_Control(pDX, IDC_bmp1, m_bmp1);
	DDX_Text(pDX, IDC_inputFile, m_inputFile);
	DDX_Slider(pDX, IDC_SLIDER1, m_slidValue);
	DDX_Text(pDX, IDC_value, m_value);
	//}}AFX_DATA_MAP
}



BEGIN_MESSAGE_MAP(AddNewImage, CDialog)
	//{{AFX_MSG_MAP(AddNewImage)
	ON_BN_CLICKED(IDC_next1, Onnext1)
	ON_BN_CLICKED(IDC_next2, Onnext2)
	ON_BN_CLICKED(IDC_next4, Onnext4)
	ON_BN_CLICKED(IDC_browse, Onbrowse)
	ON_BN_CLICKED(IDC_store, Onstore)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// AddNewImage message handlers


BOOL AddNewImage::GetBitmapFileName(TCHAR *filename, int len, HWND hWnd)
{
	OPENFILENAME	ofn;

	ZeroMemory(&ofn, sizeof(OPENFILENAME));
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hWnd;
	ofn.lpstrFilter = _T("Bitmap Files (*.bmp)\0*.bmp\0All Files (*.*)\0*.*\0\0");
	ofn.lpstrFile = filename;
	ofn.nMaxFile = len;
	ofn.lpstrTitle = _T("Browse");
	ofn.Flags = /*OFN_FILEMUSTEXIST |*/ OFN_HIDEREADONLY;
	return GetOpenFileName(&ofn);
}

//TCHAR  BitmapFilename[256];
//TCHAR  outputFilename[256];


void AddNewImage::Onbrowse() 
{
	// TODO: Add your control notification handler code here

	GetBitmapFileName(BitmapFilename,sizeof(BitmapFilename) / sizeof(TCHAR), NULL);
	m_inputFile = CString(BitmapFilename);
	UpdateData(false);

	HBITMAP newBmp;
	newBmp = (HBITMAP) LoadImage(NULL,BitmapFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	m_bmp1.SetBitmap(newBmp);
	
}

void AddNewImage::Onnext1() 
{
	// TODO: Add your control notification handler code here
	
	sprintf(outputFilename,"output.bmp");

	enhancement *enh = new enhancement();
	enh->Create(IDD_DIALOG_enhance,this);
	enh->ShowWindow(SW_SHOW);
	enh->m_prog.SetRange32(0,100);
//	enh->m_prog.SetPos(20);

//	enh->m_text = " Determining the ridge direction ";
//	enh->m_prog.SetPos(66);
//	enh->UpdateData(false);
	enhance(enh,BitmapFilename,outputFilename);
	enh->DestroyWindow();

	HBITMAP newBmp;
	newBmp = (HBITMAP) LoadImage(NULL,outputFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	m_bmp2.SetBitmap(newBmp);
	
}


void AddNewImage::Onnext2() 
{
	// TODO: Add your control notification handler code here
	Thinning();
	AfxMessageBox("thinning over");

	HBITMAP newBmp;
	newBmp = (HBITMAP) LoadImage(NULL,"output_t.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	m_bmp4.SetBitmap(newBmp);
	
}

void AddNewImage::Onnext4() 
{
	// TODO: Add your control notification handler code here
	Minutiae();
	//AfxMessageBox(" Minutiae detection over");

	HBITMAP newBmp;
	newBmp = (HBITMAP) LoadImage(NULL,"output_m.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	m_bmp5.SetBitmap(newBmp);

	
}

void AddNewImage::Binarize(void)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    // Start the child process. 
    if( !CreateProcess( NULL, // No module name (use command line). 
        "exe/binarize.exe",			  // Command line. 
        NULL,             // Process handle not inheritable. 
        NULL,             // Thread handle not inheritable. 
        FALSE,            // Set handle inheritance to FALSE. 
        0,                // No creation flags. 
        NULL,             // Use parent's environment block. 
        NULL,             // Use parent's starting directory. 
        &si,              // Pointer to STARTUPINFO structure.
        &pi )             // Pointer to PROCESS_INFORMATION structure.
    ) 
    {
        //ErrorExit( "CreateProcess failed." );
    }

    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );

    // Close process and thread handles. 
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );


}

void AddNewImage::Thinning(void)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    // Start the child process. 
    if( !CreateProcess( NULL, // No module name (use command line). 
        "exe/thinning.exe",			  // Command line. 
        NULL,             // Process handle not inheritable. 
        NULL,             // Thread handle not inheritable. 
        FALSE,            // Set handle inheritance to FALSE. 
        0,                // No creation flags. 
        NULL,             // Use parent's environment block. 
        NULL,             // Use parent's starting directory. 
        &si,              // Pointer to STARTUPINFO structure.
        &pi )             // Pointer to PROCESS_INFORMATION structure.
    ) 
    {
        //ErrorExit( "CreateProcess failed." );
    }

    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );

    // Close process and thread handles. 
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );


}

void AddNewImage::Minutiae(void)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    // Start the child process. 
    if( !CreateProcess( NULL, // No module name (use command line). 
        "exe/minutiae.exe",			  // Command line. 
        NULL,             // Process handle not inheritable. 
        NULL,             // Thread handle not inheritable. 
        FALSE,            // Set handle inheritance to FALSE. 
        0,                // No creation flags. 
        NULL,             // Use parent's environment block. 
        NULL,             // Use parent's starting directory. 
        &si,              // Pointer to STARTUPINFO structure.
        &pi )             // Pointer to PROCESS_INFORMATION structure.
    ) 
    {
        //ErrorExit( "CreateProcess failed." );
    }

    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );

    // Close process and thread handles. 
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );


}




void AddNewImage::Onstore() 
{
	// TODO: Add your control notification handler code here
	//AfxMessageBox("store ");
	MakeMinutiaeArray();
	
}

void AddNewImage::MakeMinutiaeArray()
{
	// TODO: Add your control notification handler code here
	char inputBmp[256];
	char outputBmp[256];
	int rows,cols;
	image = new Image;
	float value=0;
	int i,j,noMinutiae=0;

	sprintf(inputBmp,"output_m.bmp");
	readBmp(inputBmp,image);
	rows = image->Vres;
	cols = image->Hres;

	removeNoise(image->p,30);

	//sprintf(test,"%d %d",rows,cols);
	//AfxMessageBox(test);

	for(i=1;i<rows-1;i++)
	{
		for(j=1;j<cols-1;j++)
		{
			value =image->p[i][j];
			if(value==1)
			{
				noMinutiae++;
				value=0;
			}
		}
	}

	int **minData,sno=0;
	minData = new int*[noMinutiae];

	for(i=0;i<noMinutiae;i++)
		minData[i] = new int[2];

	//AfxMessageBox(" minData ");

	for(i=0;i<rows;i++)
	{
		for(j=0;j<cols;j++)
		{
			value =image->p[i][j];
			if(value==1)
			{
				//minData[sno][0]=sno;
				minData[sno][0]=i;
				minData[sno][1]=j;
				sno++;
				value=0;
			}
		}
	}

	//AfxMessageBox(" minutiae data extracted ");

	////////////// reading the index file //////////
	FILE *index,*data;
	char imageFile[256],dataFile[256],thinFile[256];
	int sNo=0;
	index = fopen("Database/index.txt","r");

	while(!feof(index))
	{
		fscanf(index,"%d %s %s %s\n",&sNo,imageFile,dataFile,thinFile);
		if(feof(index))
			break;
	}
	fclose(index);

	////////////// updating index file //////////////
	sNo = sNo+1;
	sprintf(imageFile,"Database/image_min/%d.bmp",sNo);
	sprintf(dataFile,"Database/data/%d.txt",sNo);
	sprintf(thinFile,"Database/image_thin/%d.bmp",sNo);

	index = fopen("Database/index.txt","a");
	fprintf(index,"%d %s %s %s\n",sNo,imageFile,dataFile,thinFile);
	fclose(index);

	////////////// storing bmp file /////////////////

	sprintf(outputBmp,imageFile);
	writeBmp(outputBmp,image);

	////////////// storing thin bmp file /////////////////
	sprintf(inputBmp,"output_t.bmp");
	readBmp(inputBmp,image);
	removeNoise(image->p, 25);
	sprintf(outputBmp,"Database/image_thin/%d.bmp",sNo);
	writeBmp(outputBmp,image);

	////////////// storing data file //////////////// 

	data = fopen(dataFile,"w");
	for(i=1;i<sno;i++)
	{
		fprintf(data,"%d %d \n",minData[i][0],minData[i][1]);
	}
	fclose(data);

	AfxMessageBox(" Database Updated ");

	//char buf[512];
	//sprintf(buf, "%d %% matched", match1(minData, sno, minData, sno) );
	//AfxMessageBox(buf);

}



void AddNewImage::OnReleasedcaptureSlider1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	char mesg[256],inputBmp[256],outputBmp[256];
	int rows,cols;
	image = new Image;

	int x = m_slidValue;
	sprintf(mesg,"%d",x);
	m_value = CString(mesg);
	UpdateData(false);

	sprintf(inputBmp,"output_m.bmp");
	readBmp(inputBmp,image);
	
	rows = image->Vres;
	cols = image->Hres;

	
	removeNoise(image->p,x);

	

	sprintf(outputBmp,"output_m2.bmp");
	writeBmp(outputBmp,image);

	HBITMAP newBmp;
	newBmp = (HBITMAP) LoadImage(NULL,"output_m2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	m_bmp6.SetBitmap(newBmp);

	*pResult = 0;
}

BOOL AddNewImage::OnInitDialog() 
{
	CDialog::OnInitDialog();

	m_slider.SetRange(0,100);
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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