minutiaedlg.cpp
来自「这是一个用c++编写的实现指纹识别的程序」· C++ 代码 · 共 330 行
CPP
330 行
// minutiaeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "minutiae.h"
#include "minutiaeDlg.h"
#include "bmp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMinutiaeDlg dialog
CMinutiaeDlg::CMinutiaeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMinutiaeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMinutiaeDlg)
m_text1 = _T("");
m_text2 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMinutiaeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMinutiaeDlg)
DDX_Control(pDX, IDC_PROGRESSBAR, m_prog);
DDX_Text(pDX, IDC_text, m_text1);
DDX_Text(pDX, IDC_text2, m_text2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMinutiaeDlg, CDialog)
//{{AFX_MSG_MAP(CMinutiaeDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMinutiaeDlg message handlers
BOOL CMinutiaeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMinutiaeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMinutiaeDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMinutiaeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// global data of the image
Image *image;
void CMinutiaeDlg::DetectMinutiae()
{
char inputBmp[256];
char outputBmp[256];
char test[256];
int rows,cols;
Image *img2;
//CProgressCtrl *prog;
//prog = GetI;
image = new Image;
img2 = new Image;
/*
function b = minutiae()
% detecting the minutiae points in a fingerprint image
img = imread('output_t.bmp','bmp');
size_i = size(img);
rows = size_i(1);
cols = size_i(2);*/
sprintf(inputBmp,"output_t.bmp");
sprintf(outputBmp,"output_m.bmp");
readBmp(inputBmp);
//writeBmp(outputBmp);
rows = image->Vres;
cols = image->Hres;
img2->Hres = image->Hres;
img2->Vres = image->Vres;
img2->Size = image->Size;
img2->i = new Pixel[image->Size];
img2->p = new Pixel*[image->Size];
for(int x=0;x<image->Hres;x++)
img2->p[x] = new Pixel[image->Vres];
//sprintf(test,"%d %d",rows,cols);
//AfxMessageBox(test);
/*
% mask for detecting the end points or bifurcation points in ridges
mask = [ 1 1 1
1 10 1
1 1 1]/10;
*/
float mask[3][3] = {{0.1,0.1,0.1},{0.1,1,0.1},{0.1,0.1,0.1}};
/*
% new image depecting minutiaes
img2(1:rows,1:cols)=0;
% detection starts
for i=2:rows-1
for j=2:cols-1
value = double(img(i-1:i+1,j-1:j+1)).*double(mask);
mag = sum(sum(value));
% if mag is 1.1 it means only one neighbour present
if mag == 1.1
fprintf('ridge end \n');
img2(i,j) = 1;
end
% if mag is 1.3 it means exactly 2 neighbours present
if mag == 1.3
fprintf('ridge bifurcation \n ');
img2(i,j) = 1;
end
end
end
*/
float value;
char mesg[256];
int i,j,k,l;
m_prog.SetRange32( 0, 100 );
for(i=1;i<rows-1;i++)
{
m_prog.SetPos( (float)i/(float)rows * 100.0f );
for(j=1;j<cols-1;j++)
{
value=0;
for(k=-1;k<2;k++)
{
for(l=-1;l<2;l++)
{
value = value + (float)((int)(image->p[i+k][j+l])*mask[k+1][l+1]);
//sprintf(test,"%f %d %d",(float) image->p[i+k][j+l],(i+k),(j+l));
//if((float)image->p[i+k][j+l]>1.0)
//AfxMessageBox(test);
}
}
// if mag is 1.1 it means only one neighbour present
if((int)(value*10) == 11)
{
sprintf(mesg,"ridge end \n");
img2->p[i][j] = 1;
//AfxMessageBox(" end detected ");
}
// if mag is 1.3 it means exactly 2 neighbours present
if((int)(value*10) == 13)
{
sprintf(mesg,"ridge bifurcation \n");
img2->p[i][j] = 1;
//AfxMessageBox(" bifurcation detected ");
}
}
}
for(int r=0;r<img2->Vres;r++)
{
for(int s=0;s<img2->Hres;s++)
{
image->p[r][s] = img2->p[r][s];
}
}
/*
img2 = im2bw(img2,0.5);
imwrite(img2,'output_k.bmp','bmp');
*/
writeBmp(outputBmp);
}
void CMinutiaeDlg::OnOK()
{
// TODO: Add extra validation here
DetectMinutiae();
OnCancel();
//AfxMessageBox(" Detection Over");
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?