📄 hmmdemo.cpp
字号:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/// HMMDemo.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "HMMDemo.h"
#include "MainFrm.h"
#include "HMMDemoDoc.h"
#include "HMMDemoView.h"
#include "FaceBase.h"
#include "ContEHMM.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHMMDemoApp
BEGIN_MESSAGE_MAP(CHMMDemoApp, CWinApp)
//{{AFX_MSG_MAP(CHMMDemoApp)
ON_COMMAND(ID_SAVE_CONFIG, OnSaveConfig)
ON_COMMAND(ID_LOAD_CONFIG, OnLoadConfig)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHMMDemoApp construction
CHMMDemoApp::CHMMDemoApp()
{
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CHMMDemoApp object
CHMMDemoApp theApp;
CStringArray maskFileNameArray;
CString GetLastDirectory(CString originalDirectory)
{
CString copyDirectory(originalDirectory);
int lastPos = copyDirectory.ReverseFind('\\'); //反向查找1
copyDirectory = copyDirectory.Left(lastPos );
int secondLastPos = copyDirectory.ReverseFind('\\'); //反向查找2
return originalDirectory.Mid(secondLastPos+1, lastPos- secondLastPos-1 );
}
/////////////////////////////////////////////////////////////////////////////
// CHMMDemoApp initialization
BOOL CHMMDemoApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CHMMDemoDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CHMMDemoView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
m_dlgHMMParams = new CHMMParams;
m_dlgSamplingParams = new CSamplingParams;
m_dlgMiscParams = new CMiscParams;
//****************Load Settings (stored in registry)*************************************/
CString states_string;
int numbers[8]; //maximum superstates is 7
//read number of HMM states
states_string = GetProfileString( "Settings\\HMM", "NumStates", "5 3 6 6 6 3" );
//parse string
sscanf( states_string, "%d %d %d %d %d %d %d %d",
&numbers[0], &numbers[1], &numbers[2], &numbers[3],
&numbers[4], &numbers[5], &numbers[6], &numbers[7] );
m_dlgHMMParams->m_States[0] = numbers[0];
for( int i = 0 ; i < m_dlgHMMParams->m_States[0] ; i++ )
{
m_dlgHMMParams->m_States[ i + 1 ] = numbers[i+1] ;
}
//read number of mixtures
m_dlgHMMParams->m_NumMix = GetProfileInt("Settings\\HMM", "NumMix", 3 );
//read sampling parameters (dctSize, obsSize, delta)
m_dlgSamplingParams->m_dctSize.width = GetProfileInt("Settings\\Sampling", "WindowWidth", 12 );
m_dlgSamplingParams->m_dctSize.height = GetProfileInt("Settings\\Sampling", "WindowHeight", 12 );
m_dlgSamplingParams->m_obsSize.width = GetProfileInt("Settings\\Sampling", "DCTCoeffX", 3 );
m_dlgSamplingParams->m_obsSize.height = GetProfileInt("Settings\\Sampling", "DCTCoeffY", 3 );
m_dlgSamplingParams->m_delta.width = GetProfileInt("Settings\\Sampling", "DeltaX", 4 );
m_dlgSamplingParams->m_delta.height = GetProfileInt("Settings\\Sampling", "DeltaY", 4 );
//read scaling params
m_dlgMiscParams->m_useWidth = GetProfileInt("Settings\\Scaling", "UseFixedWidth", 0 );
m_dlgMiscParams->m_FixedWidth = GetProfileInt("Settings\\Scaling", "FixedWidth", 0 );
m_dlgMiscParams->m_useHeight = GetProfileInt("Settings\\Scaling", "UseFixedHeight", 0 );
m_dlgMiscParams->m_FixedHeight = GetProfileInt("Settings\\Scaling", "FixedHeight", 0 );
m_dlgMiscParams->m_SuppressIntensity = GetProfileInt("Settings\\Scaling", "SuppressIntensity", 1 );
//*******************************End Loading Settings *************************************/
return TRUE;
}
void CHMMDemoApp::SaveSettings()
{
//****************Save Settings into registry)*************************************/
CString states_string;
//write number of states
states_string.Format("%d", m_dlgHMMParams->m_States[0] );
for( int i = 0 ; i < m_dlgHMMParams->m_States[0] ; i++ )
{
CString add;
add.Format(" %d", m_dlgHMMParams->m_States[ i + 1 ] );
states_string+= add;
}
//write number of HMM states
WriteProfileString( "Settings\\HMM", "NumStates", states_string );
//write number of mixtures
WriteProfileInt("Settings\\HMM", "NumMix", m_dlgHMMParams->m_NumMix );
//write sampling parameters (dctSize, obsSize, delta)
WriteProfileInt("Settings\\Sampling", "WindowWidth" , m_dlgSamplingParams->m_dctSize.width );
WriteProfileInt("Settings\\Sampling", "WindowHeight", m_dlgSamplingParams->m_dctSize.height );
WriteProfileInt("Settings\\Sampling", "DCTCoeffX", m_dlgSamplingParams->m_obsSize.width );
WriteProfileInt("Settings\\Sampling", "DCTCoeffY", m_dlgSamplingParams->m_obsSize.height );
WriteProfileInt("Settings\\Sampling", "DeltaX", m_dlgSamplingParams->m_delta.width );
WriteProfileInt("Settings\\Sampling", "DeltaY", m_dlgSamplingParams->m_delta.height );
//*******************************End saving Settings *************************************/
//write scaling params
WriteProfileInt("Settings\\Scaling", "UseFixedWidth" , m_dlgMiscParams->m_useWidth );
WriteProfileInt("Settings\\Scaling", "FixedWidth", m_dlgMiscParams->m_FixedWidth );
WriteProfileInt("Settings\\Scaling", "UseFixedHeight", m_dlgMiscParams->m_useHeight);
WriteProfileInt("Settings\\Scaling", "FixedHeight", m_dlgMiscParams->m_FixedHeight );
WriteProfileInt("Settings\\Scaling", "SuppressIntensity", m_dlgMiscParams->m_SuppressIntensity );
}
/////////////////////////////////////////////////////////////////////////////
// CHMMDemoApp message handlers
// App command to run the dialog
void CHMMDemoApp::OnFileOpen()
{
CFileDialog dlg( TRUE, 0, 0, OFN_ALLOWMULTISELECT | OFN_ENABLESIZING |
OFN_EXPLORER | OFN_FILEMUSTEXIST,
"Image Files (*.bmp;*.jpg;*.jpeg)|*.bmp;*.jpg;*.jpeg|"
"Face Base Files (*.txt)|*.txt|"
"All Files (*.*)|*.*||", 0 );
int buf_size = 1 << 15;
char* buffer = (char*)malloc(buf_size + 100);
dlg.m_ofn.lpstrFile = buffer;
buffer[0] = '\0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -