Update the changelog
[opencv] / apps / StereoGR / GestMan.cpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
4 //\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
8 //\r
9 //\r
10 //                        Intel License Agreement\r
11 //                For Open Source Computer Vision Library\r
12 //\r
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.\r
14 // Third party copyrights are property of their respective owners.\r
15 //\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
18 //\r
19 //   * Redistribution's of source code must retain the above copyright notice,\r
20 //     this list of conditions and the following disclaimer.\r
21 //\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
25 //\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
28 //\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
39 //\r
40 //M*/// GestRec.cpp : implementation file\r
41 //\r
42 \r
43 #include "stdafx.h"\r
44 #include "stereogr.h"\r
45 #include "GestMan.h"\r
46 \r
47 #ifdef _DEBUG\r
48 #define new DEBUG_NEW\r
49 #undef THIS_FILE\r
50 static char THIS_FILE[] = __FILE__;\r
51 #endif\r
52 \r
53 /////////////////////////////////////////////////////////////////////////////\r
54 // CGestRec dialog\r
55 \r
56 \r
57 CGestRec::CGestRec(CWnd* pParent /*=NULL*/)\r
58         : CDialog(CGestRec::IDD, pParent)\r
59 {\r
60         //{{AFX_DATA_INIT(CGestRec)\r
61                 // NOTE: the ClassWizard will add member initialization here\r
62         //}}AFX_DATA_INIT\r
63 }\r
64 \r
65 \r
66 void CGestRec::DoDataExchange(CDataExchange* pDX)\r
67 {\r
68         CDialog::DoDataExchange(pDX);\r
69         //{{AFX_DATA_MAP(CGestRec)\r
70                 // NOTE: the ClassWizard will add DDX and DDV calls here\r
71         //}}AFX_DATA_MAP\r
72 }\r
73 \r
74 \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
80         ON_WM_CLOSE()\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
85         //}}AFX_MSG_MAP\r
86 END_MESSAGE_MAP()\r
87 \r
88 /////////////////////////////////////////////////////////////////////////////\r
89 // CGestRec message handlers\r
90 \r
91 void CGestRec::OnRtrain() \r
92 {\r
93     STEREOGRAPP(app);\r
94     app->m_findHand.SetTask(GR_TRAIN);\r
95 }\r
96 \r
97 void CGestRec::OnRreco() \r
98 {\r
99     STEREOGRAPP(app);\r
100     app->m_findHand.SetTask(GR_RECOGNIZE);\r
101 }\r
102 \r
103 void CGestRec::OnSelchangeGestlist() \r
104 {\r
105     STEREOGRAPP(app);\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
111 }\r
112 \r
113 BOOL CGestRec::OnInitDialog() \r
114 {\r
115         CDialog::OnInitDialog();\r
116         \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
125 \r
126     CButton* pTrain = (CButton*)GetDlgItem(IDC_RTRAIN);\r
127     pTrain->SetCheck(1);\r
128     STEREOGRAPP(app);\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
133 \r
134     ShowWindow(SW_SHOW);\r
135 \r
136         return TRUE;  // return TRUE unless you set the focus to a control\r
137                       // EXCEPTION: OCX Property Pages should return FALSE\r
138 }\r
139 \r
140 void CGestRec::OnClose() \r
141 {\r
142     STEREOGRAPP(app);\r
143     app->m_findHand.SetTask(GR_NOTHING);\r
144         \r
145         CDialog::OnClose();\r
146 }\r
147 \r
148 void CGestRec::UpdateStatus()\r
149 {\r
150     STEREOGRAPP(app);\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
156     CString info;\r
157 \r
158     pList->GetText(current, info);\r
159     string str = LPCTSTR(info);\r
160     app->m_findHand.SetGestureName(str);\r
161 \r
162     switch(task)\r
163     {\r
164     case GR_TRAIN:\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
167         else\r
168             info.Format("Collected all samples.");\r
169         break;\r
170 \r
171     case GR_RECOGNIZE:\r
172         if(recognized.empty())\r
173         {\r
174             info.Format("Not recognized.");\r
175         }\r
176         else\r
177         {\r
178             info.Format("Recognized as \"%s\".", recognized.c_str());\r
179         }\r
180         break;\r
181 \r
182     case GR_NOTHING:\r
183         info = "Do nothing";\r
184     }\r
185 \r
186     pStatus->SetWindowText(info);\r
187     pStatus->Invalidate();\r
188     pStatus->UpdateWindow();\r
189     RECT rect;\r
190     pStatus->GetWindowRect(&rect);\r
191     ScreenToClient(&rect);\r
192     InvalidateRect(&rect);\r
193     UpdateWindow();\r
194     ASSERT(iplGetErrStatus() >= 0);\r
195 }\r
196 \r
197 void CGestRec::OnRnothing() \r
198 {\r
199     STEREOGRAPP(app)\r
200     app->m_findHand.SetTask(GR_NOTHING);\r
201 }\r
202 \r
203 void CGestRec::OnBcleargest() \r
204 {\r
205     CListBox* pList = (CListBox*)GetDlgItem(IDC_GESTLIST);\r
206     int index = pList->GetCurSel();\r
207     CString str;\r
208     pList->GetText(index, str);\r
209     string buffer = LPCTSTR(str);\r
210     STEREOGRAPP(app)\r
211     app->m_findHand.ClearGesture(buffer);\r
212 }\r
213 \r
214 void CGestRec::OnBsavegest() \r
215 {\r
216     CFileDialog dlg(FALSE, 0, 0, OFN_OVERWRITEPROMPT, "Statis training set (*.pos)|*.pos");\r
217     if(dlg.DoModal() == IDOK)\r
218     {\r
219         STEREOGRAPP(app)\r
220         app->m_findHand.SaveGestures(dlg.GetPathName());\r
221     }\r
222 }\r
223 \r
224 void CGestRec::OnBloadgest() \r
225 {\r
226     CFileDialog dlg(TRUE, 0, 0, 0, "Statis training set (*.pos)|*.pos");\r
227         if(dlg.DoModal() == IDOK)\r
228     {\r
229         STEREOGRAPP(app)\r
230         app->m_findHand.LoadGestures(dlg.GetPathName());\r
231     }\r
232 }\r