📄 enhancedlg.cpp
字号:
// enhanceDlg.cpp : implementation file
//
#include "stdafx.h"
#include "enhance.h"
#include "enhanceDlg.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define _IMG_WID 240
#define _IMG_HEI 256
#define BIN_ONE 255
#include ".\fgs\fgsio.h"
#include ".\fgs\fgscore.h"
#define MY_PI 3.14159
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CEnhanceDlg dialog
CEnhanceDlg::CEnhanceDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEnhanceDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEnhanceDlg)
m_minuCount = _T("0");
m_minuCount2 = _T("0");
m_fileName1 = _T("");
m_fileName2 = _T("");
m_strOutput = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_buffer=NULL;
m_star1=NULL;
m_star2=NULL;
}
void CEnhanceDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEnhanceDlg)
DDX_Control(pDX, IDC_LIST_MINU_SET2, m_lstMinuSet2);
DDX_Control(pDX, IDC_LIST_MINU_SET1, m_lstMinuSet1);
DDX_Control(pDX, IDC_STATIC_PICBOX2, m_picBox2);
DDX_Control(pDX, IDC_STATIC_PICBOX, m_picBox);
DDX_Text(pDX, IDC_STATIC_MINU_COUNT, m_minuCount);
DDX_Text(pDX, IDC_STATIC_MINU_COUNT2, m_minuCount2);
DDX_Text(pDX, IDC_EDIT_FILE_NAME1, m_fileName1);
DDX_Text(pDX, IDC_EDIT_FILE_NAME2, m_fileName2);
DDX_Text(pDX, IDC_EDIT_OUTPUT, m_strOutput);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEnhanceDlg, CDialog)
//{{AFX_MSG_MAP(CEnhanceDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_OPEN_FILE2, OnOpenFile2)
ON_BN_CLICKED(IDC_BUTTON_REFRESH, OnButtonRefresh)
ON_LBN_SELCHANGE(IDC_LIST_MINU_SET1, OnSelchangeListMinuSet1)
ON_LBN_SELCHANGE(IDC_LIST_MINU_SET2, OnSelchangeListMinuSet2)
ON_BN_CLICKED(IDC_BUTTON_GO, OnButtonGo)
ON_BN_CLICKED(IDC_BUTTON2, Onjinghua)
ON_BN_CLICKED(IDC_BUTTON_ENHANCE3, Onxihua)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEnhanceDlg message handlers
BOOL CEnhanceDlg::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
m_relyMap = FgsFieldCreate(FgsFieldBit);
m_mask = FgsFieldCreate(FgsFieldBit);
m_oriMap = FgsFieldCreate(FgsFieldFloat);
m_imgNorm = FgsFieldCreate(FgsFieldFloat);
m_imgBin = FgsImageCreate();
// m_imgBin1 = FgsImageCreate();
// m_imgBina = FgsImageCreate();
// m_imgBinb = FgsImageCreate();
m_freqMap =FgsFieldCreate(FgsFieldFloat);
//设置图象和场大小
for (int i=0 ; i < 2; i++){
m_minutia[i] = FgsMinutiaSetCreate(100);
m_sdc[i] = FgsCreateSDC();
m_image[i] = FgsImageCreate();
FgsImageSetSize(m_image[i], _IMG_WID, _IMG_HEI) ;
//设置指纹图象的显示上下文
FgsSetSDC(m_sdc[i], m_image[i]);
}
FgsAttachWnd(m_sdc[0], m_picBox.m_hWnd);
FgsAttachWnd(m_sdc[1], m_picBox2.m_hWnd);
FgsFieldSetSize(m_relyMap, _IMG_WID, _IMG_HEI) ;
FgsFieldSetSize(m_mask, _IMG_WID, _IMG_HEI);
FgsFieldSetSize(m_oriMap, _IMG_WID, _IMG_HEI);
FgsFieldSetSize(m_imgNorm, _IMG_WID, _IMG_HEI);
FgsImageSetSize(m_imgBin, _IMG_WID, _IMG_HEI);
FgsFieldSetSize(m_freqMap, _IMG_WID, _IMG_HEI);
size_t sze = _IMG_HEI * _IMG_WID * sizeof(FgsFloat) *10;
m_buffer = malloc(sze);
// ::SetWindowPos(m_picBox.m_hWnd,NULL,0,0,256 * 2,256 * 2,SWP_NOMOVE);
//创建高波核组
m_gaborBank = FgsGaborBankCreate();
return TRUE; // return TRUE unless you set the focus to a control
}
void CEnhanceDlg::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 CEnhanceDlg::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 CEnhanceDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CEnhanceDlg::OnOK()
{
CFileDialog dlg(TRUE,0,0,OFN_HIDEREADONLY,"BMP文件(*.bmp)|*.bmp|");
dlg.DoModal();
m_strFileName =dlg.GetPathName() ;
if (m_strFileName.IsEmpty()) return;
if (FgsOK==FgsImageImport(m_image[0], (const FgsString)m_strFileName.GetBuffer(m_strFileName.GetLength()))){
m_fileName1 = dlg.GetFileName();
FgsFloat peakHeight=0.0,freq;
//step 1
// WriteLog("1 规范化图像...");
FgsNormalize(m_image[0], m_imgNorm);
//step 2
// WriteLog("2 提取方向场...");
FgsRetrieveOriMap(m_imgNorm, m_oriMap, m_relyMap, 0.3f, (FgsFloat*)m_buffer);
//step 3
// WriteLog("3 提取频率场...");
peakHeight = FgsMeasureMedianFreq(m_imgNorm, m_oriMap, &freq, m_buffer);
//step 4
// WriteLog("4 提取有效指纹区...");
FgsRetrieveMask(m_imgNorm, m_oriMap, m_mask, peakHeight * 0.18f, m_buffer);
//step 5
// WriteLog("5 增强图像...");
FgsEnhanceByGabor(m_imgNorm, m_oriMap,m_mask,freq , m_gaborBank, m_buffer);
//step 6
// WriteLog("6 图像二值化...");
FgsBinarize(m_imgNorm, m_imgBin);
// FgsBinarize(m_imgBin, m_imgBin);
// WriteLog("7 图像细化...");
FgsSlenderize(m_imgBin,8, m_oriMap);
//step 7
// WriteLog("8 提取特征点...");
FgsExtractMinutia(m_minutia[0], m_imgBin, m_oriMap, m_mask, m_relyMap);
FgsMinutia minu;
m_lstMinuSet1.ResetContent();
CString s; FgsPoint p;
FgsInt ang;
m_minuCount.Format("%d", FgsMinutiaSetGetCount(m_minutia[0]));
for (int i=0; i < FgsMinutiaSetGetCount(m_minutia[0]);i++){
minu = FgsMinutiaSetGetItem(m_minutia[0], i);
p = FgsMinutiaGetPosition(minu);
ang = (int)floor(FgsMinutiaGetDirection(minu) * 180 /MY_PI+0.5);
s.Format("%d %d %d", p.x ,p.y , ang);
m_lstMinuSet1.AddString(s);
}
FgsShowImage(m_sdc[0], m_image[0]);
UpdateData(FALSE);
}
}
void CEnhanceDlg::OnDestroy()
{
FgsFieldDestroy(m_oriMap);
FgsFieldDestroy(m_mask);
FgsImageDestroy(m_imgBin);
// FgsImageDestroy(m_imgBin1);
// FgsImageDestroy(m_imgBina);
// FgsImageDestroy(m_imgBinb);
FgsFieldDestroy(m_relyMap);
FgsFieldDestroy(m_imgNorm);
FgsFieldDestroy(m_freqMap);
for (int i=0 ; i < 2; i++){
FgsImageDestroy(m_image[i]);
FgsMinutiaSetDestroy(m_minutia[i]);
if (m_sdc[i]) FgsDestroySDC(m_sdc[i]);
}
if (m_gaborBank) FgsGaborBankDestroy(m_gaborBank);
if (m_buffer) free(m_buffer);
if (m_star1){
FgsDestroyStar(m_star1);
}
if (m_star2){
FgsDestroyStar(m_star2);
}
CDialog::OnDestroy();
}
void PrintImage(const HWND hWnd, const FgsImage image){
FgsByte *pImg = (FgsByte *)FgsImageGetBuffer(image);
FgsInt w = FgsImageGetWidth(image);
FgsInt h=FgsImageGetHeight(image);
HDC hDc =::GetDC(hWnd);
CDC dc;
dc.Attach(hDc);
CRect rect;
::GetClientRect(hWnd, &rect);
dc.Rectangle(&rect);
FgsByte b;
POINT p;
for(int i=0 ; i< w; i++){
for (int j=0; j<h; j++){
p.x =i; p.y = rect.Height() - (j + 10);
if (pImg[i + j * w] == BIN_ONE){
b =255;
}
else{
b=0;
}
dc.SetPixel(p, RGB(b,b,b));
}
}
dc.Detach();
::ReleaseDC(hWnd, hDc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -