📄 mainfrm.cpp
字号:
if( !iplimage )
{
MessageBox("No image was selected!");
return;
}
cvSetImageROI( iplimage, RectToCvRect( m_sel ));
CImage tofile;
tofile.CopyOf( iplimage );
tofile.Save( filename );
//add other images
CStringList* imageList = camera_view->GetImageList();
if ( imageList && (imageList->GetCount() > 1) )
{
//add batch
POSITION pos = imageList->GetHeadPosition();
imageList->GetNext( pos );
while (pos)
{
CImage img;
img.Load( imageList->GetNext( pos ), 1 );
img.Save( GetFreeFilename( camera_view->GetTestPath(), name ) );
}
}
MessageBox("Images were added to test base");
camera.Start();
}
return;
}
void CMainFrame::OnUpdateRemoveObj(CCmdUI* pCmdUI)
{
CImageBaseView* view = GetImageBaseView();
bool enable = false;
if( view )
{
enable = view->GetActive() >= 0;
}
pCmdUI->Enable( enable );
}
void CMainFrame::OnRemoveObj()
{
CImageBaseView* view = GetImageBaseView();
CHMMDemoDoc* doc = GetHMMDoc();
if( doc && view )
{
int active = view->GetActive();
int person_index = view->GetPersonIndex();
if( active >= 0 )
{
if( doc->RemoveObj( person_index, active ))
{
view->ResetActive();
view->RefreshView();
}
}
}
}
void CMainFrame::OnZoomIn()
{
CImageBaseView* view = GetImageBaseView();
view->Zoom();
}
void CMainFrame::OnZoomOut()
{
CImageBaseView* view = GetImageBaseView();
view->Zoom( false );
}
void CMainFrame::OnChangeBaseParams()
{
CHMMDemoDoc* doc = GetHMMDoc();
if( doc )
{
doc->ChangeBaseParams();
}
}
void CMainFrame::OnTrain()
{
CWaitCursor wait;
//if 1 person selected - train its HMM
//if all base in view - train all untrained persons
CHMMDemoDoc* doc = GetHMMDoc();
CImageBaseView* base_view = GetImageBaseView();
if( doc && base_view )
{
//int view_mode = base_view->GetMode();
CFaceBase& base = doc->GetFaceBase();
if( base_view->GetPersonIndex() >= 0 )
{
base.TrainPerson( base_view->GetPersonIndex(), true );
}
else
base.TrainAll( TRAIN_UNTRAINED );
}
}
void CMainFrame::OnRecognize()
{
CWaitCursor wait;
CHMMDemoView* view = GetCameraView();
CHMMDemoDoc* doc = GetHMMDoc();
CImageBaseView* baseview = GetImageBaseView();
if( doc && view && baseview )
{
CFaceBase& base = doc->GetFaceBase();
CCamera& camera = view->Camera();
camera.Stop();
if (view->GetSelection().IsRectEmpty() )
{
MessageBox( "Specify face region", NULL, MB_ICONERROR );
return;
}
//decide if single recognition or batch mode
CStringList* image_list = view->GetImageList();
if ( image_list && (image_list->GetCount() > 1) )
{
//perform batch recognition
int result = base.RecognizeBatch( image_list );
}
else
{
int ranged[3];
int result = base.RecognizePerson( camera.GetFrame(), view->GetSelection(),
ranged );
if( result == 0 )
{
MessageBox( "Not all persons are trained", NULL, MB_ICONERROR );
}
else
{
CString message = "";
for( int i = 0 ; i < result; i++ )
{
CPerson* person = base.GetPerson( ranged[i]);
message += person->GetName() + "\n";
}
baseview->SwitchMode(ranged[0], false);
MessageBox( (LPCTSTR)message, NULL, MB_ICONEXCLAMATION );
}
}
}
}
void CMainFrame::OnUpdateRecog(CCmdUI* pCmdUI)
{
CHMMDemoView* view = GetCameraView();
CRect rect = view->GetSelection();
pCmdUI->Enable( rect.Width() && rect.Height() );
}
void CMainFrame::OnUpdateTrain(CCmdUI* pCmdUI)
{
CImageBaseView* view = GetImageBaseView();
bool enable = false;
if( view )
{
//int person_index = view->GetPersonIndex();
CHMMDemoDoc* doc = GetHMMDoc();
int num_person = doc->GetFaceBase().GetPersonList().GetCount();
if( doc && num_person >= 0 )
{
enable = true;
//CFaceBase& base = doc->GetFaceBase();
//CPerson* person = base.GetPerson(person_index);
//enable = person && person->GetImgList().GetCount() > 0;
}
}
pCmdUI->Enable( enable );
}
void CMainFrame::OnSelectAll()
{
CHMMDemoView* view = GetCameraView();
if( view )
{
view->SetSelection(0);
}
}
void CMainFrame::OnDelHmm()
{
CHMMDemoDoc* doc = GetHMMDoc();
CImageBaseView* view = GetImageBaseView();
if( doc && view )
{
int person_index = view->GetPersonIndex();
int result = MessageBox( person_index >= 0 ? "Delete HMM info for current person?" :
"Delete HMM info for the whole base?", "",
MB_YESNO | MB_ICONQUESTION );
if( result == IDYES ) doc->DeleteHMMInfo( person_index );
}
}
void CMainFrame::OnUpdateAddTest(CCmdUI* pCmdUI)
{
CImageBaseView* view = GetImageBaseView();
CHMMDemoView* camera_view = GetCameraView();
if( view )
{
int person_index = view->GetPersonIndex();
CString path = camera_view->GetTestPath();
pCmdUI->Enable( (person_index >= 0) && (!path.IsEmpty()) );
}
}
void CMainFrame::OnTestFolder()
{
CHMMDemoView* view = GetCameraView();
char buffer[1024];
BROWSEINFO bi;
bi.hwndOwner = NULL;
bi.pidlRoot =NULL;
bi.pszDisplayName = buffer;
bi.lpszTitle = "Choose directory for test images" ;
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lParam = 0;
LPITEMIDLIST il = SHBrowseForFolder( &bi );
char path[1024];
if ( SHGetPathFromIDList( il, path ) )
if( view )
{
view->SetTestPath( path );
}
}
void CMainFrame::OnRecobase()
{
CImageBaseView* base_view = GetImageBaseView();
CFaceBase& original_base = base_view->GetDocument()->GetFaceBase();
CFileDialog dlg( TRUE, 0, 0, OFN_ENABLESIZING |
OFN_EXPLORER | OFN_FILEMUSTEXIST,
"Face Base Files (*.txt)|*.txt|", 0 );
int buf_size = 1 << 15;
char* buffer = (char*)malloc(buf_size + 100);
dlg.m_ofn.lpstrFile = buffer;
buffer[0] = '\0';
dlg.m_ofn.nMaxFile = buf_size;
int result = dlg.DoModal();
if( result == IDOK )
{
CWaitCursor wait;
CFaceBase base;
base.SetFileName( dlg.GetFileName() );
base.Load();
//recognize
original_base.RecognizeOtherBase( &base );
}
}
void CMainFrame::OnUpdateRecobase(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CImageBaseView* base_view = GetImageBaseView();
CFaceBase& base = base_view->GetDocument()->GetFaceBase();
POSITION pos = base.GetPersonList().GetHeadPosition();
while( pos )
{
CPerson* pers = base.GetPersonList().GetNext(pos);
if( !pers->IsTrained() ) { pCmdUI->Enable(FALSE); return; }
}
pCmdUI->Enable(TRUE);
}
void CMainFrame::OnSettings()
{
CHMMDemoApp* app = (CHMMDemoApp*)AfxGetApp();
app->OnSettings();// TODO: Add your command handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -