1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\r
5 // By downloading, copying, installing or using the software you agree to this license.
\r
6 // If you do not agree to this license, do not download, install,
\r
7 // copy or use the software.
\r
10 // Intel License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
\r
14 // Third party copyrights are property of their respective owners.
\r
16 // Redistribution and use in source and binary forms, with or without modification,
\r
17 // are permitted provided that the following conditions are met:
\r
19 // * Redistribution's of source code must retain the above copyright notice,
\r
20 // this list of conditions and the following disclaimer.
\r
22 // * Redistribution's in binary form must reproduce the above copyright notice,
\r
23 // this list of conditions and the following disclaimer in the documentation
\r
24 // and/or other materials provided with the distribution.
\r
26 // * The name of Intel Corporation may not be used to endorse or promote products
\r
27 // derived from this software without specific prior written permission.
\r
29 // This software is provided by the copyright holders and contributors "as is" and
\r
30 // any express or implied warranties, including, but not limited to, the implied
\r
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
\r
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
\r
33 // indirect, incidental, special, exemplary, or consequential damages
\r
34 // (including, but not limited to, procurement of substitute goods or services;
\r
35 // loss of use, data, or profits; or business interruption) however caused
\r
36 // and on any theory of liability, whether in contract, strict liability,
\r
37 // or tort (including negligence or otherwise) arising in any way out of
\r
38 // the use of this software, even if advised of the possibility of such damage.
\r
40 //M*/// GestRec.cpp : implementation file
\r
44 #include "stereogr.h"
\r
45 #include "GestMan.h"
\r
48 #define new DEBUG_NEW
\r
50 static char THIS_FILE[] = __FILE__;
\r
53 /////////////////////////////////////////////////////////////////////////////
\r
57 CGestRec::CGestRec(CWnd* pParent /*=NULL*/)
\r
58 : CDialog(CGestRec::IDD, pParent)
\r
60 //{{AFX_DATA_INIT(CGestRec)
\r
61 // NOTE: the ClassWizard will add member initialization here
\r
66 void CGestRec::DoDataExchange(CDataExchange* pDX)
\r
68 CDialog::DoDataExchange(pDX);
\r
69 //{{AFX_DATA_MAP(CGestRec)
\r
70 // NOTE: the ClassWizard will add DDX and DDV calls here
\r
75 BEGIN_MESSAGE_MAP(CGestRec, CDialog)
\r
76 //{{AFX_MSG_MAP(CGestRec)
\r
77 ON_BN_CLICKED(IDC_RTRAIN, OnRtrain)
\r
78 ON_BN_CLICKED(IDC_RRECO, OnRreco)
\r
79 ON_LBN_SELCHANGE(IDC_GESTLIST, OnSelchangeGestlist)
\r
81 ON_BN_CLICKED(IDC_RNOTHING, OnRnothing)
\r
82 ON_BN_CLICKED(IDC_BCLEARGEST, OnBcleargest)
\r
83 ON_BN_CLICKED(IDC_BSAVEGEST, OnBsavegest)
\r
84 ON_BN_CLICKED(IDC_BLOADGEST, OnBloadgest)
\r
88 /////////////////////////////////////////////////////////////////////////////
\r
89 // CGestRec message handlers
\r
91 void CGestRec::OnRtrain()
\r
94 app->m_findHand.SetTask(GR_TRAIN);
\r
97 void CGestRec::OnRreco()
\r
100 app->m_findHand.SetTask(GR_RECOGNIZE);
\r
103 void CGestRec::OnSelchangeGestlist()
\r
106 CListBox* pList = (CListBox*)GetDlgItem(IDC_GESTLIST);
\r
107 int sel = pList->GetCurSel();
\r
108 string buffer("", pList->GetTextLen(sel));
\r
109 pList->GetText(sel, buffer.begin());
\r
110 app->m_findHand.SetGestureName(buffer);
\r
113 BOOL CGestRec::OnInitDialog()
\r
115 CDialog::OnInitDialog();
\r
117 CListBox* pList = (CListBox*)GetDlgItem(IDC_GESTLIST);
\r
118 pList->AddString("Ok");
\r
119 pList->AddString("Open");
\r
120 pList->AddString("Three");
\r
121 pList->AddString("Peace");
\r
122 pList->AddString("Point");
\r
123 pList->AddString("Thumb");
\r
124 pList->SetCurSel(0);
\r
126 CButton* pTrain = (CButton*)GetDlgItem(IDC_RTRAIN);
\r
127 pTrain->SetCheck(1);
\r
129 app->m_findHand.SetTask(GR_TRAIN);
\r
130 string buffer("", pList->GetTextLen(0));
\r
131 pList->GetText(0, buffer.begin());
\r
132 app->m_findHand.SetGestureName(buffer);
\r
134 ShowWindow(SW_SHOW);
\r
136 return TRUE; // return TRUE unless you set the focus to a control
\r
137 // EXCEPTION: OCX Property Pages should return FALSE
\r
140 void CGestRec::OnClose()
\r
143 app->m_findHand.SetTask(GR_NOTHING);
\r
145 CDialog::OnClose();
\r
148 void CGestRec::UpdateStatus()
\r
151 int task = app->m_findHand.m_task;
\r
152 CStatic* pStatus = (CStatic*)GetDlgItem(IDC_GRINFO);
\r
153 CListBox* pList = (CListBox*)GetDlgItem(IDC_GESTLIST);
\r
154 int current = pList->GetCurSel();
\r
155 string recognized = app->m_findHand.GetRecognizedName();
\r
158 pList->GetText(current, info);
\r
159 string str = LPCTSTR(info);
\r
160 app->m_findHand.SetGestureName(str);
\r
165 if(!app->m_findHand.m_isCovMatCalculated[current])
\r
166 info.Format("Collected %d samples for training...", app->m_findHand.m_features[current].size());
\r
168 info.Format("Collected all samples.");
\r
172 if(recognized.empty())
\r
174 info.Format("Not recognized.");
\r
178 info.Format("Recognized as \"%s\".", recognized.c_str());
\r
183 info = "Do nothing";
\r
186 pStatus->SetWindowText(info);
\r
187 pStatus->Invalidate();
\r
188 pStatus->UpdateWindow();
\r
190 pStatus->GetWindowRect(&rect);
\r
191 ScreenToClient(&rect);
\r
192 InvalidateRect(&rect);
\r
194 ASSERT(iplGetErrStatus() >= 0);
\r
197 void CGestRec::OnRnothing()
\r
200 app->m_findHand.SetTask(GR_NOTHING);
\r
203 void CGestRec::OnBcleargest()
\r
205 CListBox* pList = (CListBox*)GetDlgItem(IDC_GESTLIST);
\r
206 int index = pList->GetCurSel();
\r
208 pList->GetText(index, str);
\r
209 string buffer = LPCTSTR(str);
\r
211 app->m_findHand.ClearGesture(buffer);
\r
214 void CGestRec::OnBsavegest()
\r
216 CFileDialog dlg(FALSE, 0, 0, OFN_OVERWRITEPROMPT, "Statis training set (*.pos)|*.pos");
\r
217 if(dlg.DoModal() == IDOK)
\r
220 app->m_findHand.SaveGestures(dlg.GetPathName());
\r
224 void CGestRec::OnBloadgest()
\r
226 CFileDialog dlg(TRUE, 0, 0, 0, "Statis training set (*.pos)|*.pos");
\r
227 if(dlg.DoModal() == IDOK)
\r
230 app->m_findHand.LoadGestures(dlg.GetPathName());
\r