Move the sources to trunk
[opencv] / otherlibs / GestRec / FindHandCtl.h
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*/#if !defined(_GESTURE_RECOGNIZER_H_)\r
41 #define _GESTURE_RECOGNIZER_H_\r
42 \r
43 #if _MSC_VER > 1000\r
44 #pragma once\r
45 #endif // _MSC_VER > 1000\r
46 \r
47 #pragma warning(disable:4786)\r
48 \r
49 \r
50 #if defined(GESTREC_EXPORTS)\r
51 #define DLL_EXPORT __declspec(dllexport)\r
52 #else\r
53 #define DLL_EXPORT\r
54 #endif\r
55 \r
56 // FindHandCtl.h : Declaration of the CFindHandCtrl ActiveX Control class.\r
57 \r
58 /////////////////////////////////////////////////////////////////////////////\r
59 // CFindHandCtrl : See FindHandCtl.cpp for implementation.\r
60 \r
61 #define GR_NOTHING 0\r
62 #define GR_TRAIN 1\r
63 #define GR_RECOGNIZE 2\r
64 #define GR_RESEACH 1\r
65 #define GR_LINE\r
66 //#define GR_CONTOUR\r
67 //#define GR_IMPROVING     // improving of the initial hand mask by the using previous result hand mask\r
68 \r
69 #include "cv.h"\r
70 \r
71 #include <vector>\r
72 using namespace std;\r
73 \r
74 typedef vector<CvHuMoments> feature_vector;\r
75 typedef vector<float> fvector;\r
76 typedef struct _gr_pose : public fvector\r
77 {\r
78     __int64 time;\r
79     CvHuMoments pose;\r
80 } gr_pose;\r
81 \r
82 class DLL_EXPORT CFindHandCtrl\r
83 {\r
84 // Constructor\r
85 public:\r
86         CFindHandCtrl();\r
87         ~CFindHandCtrl();\r
88 \r
89 // Overrides\r
90         // ClassWizard generated virtual function overrides\r
91         //{{AFX_VIRTUAL(CFindHandCtrl)\r
92         public:\r
93 /*      virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);*/\r
94         //}}AFX_VIRTUAL\r
95 \r
96 // Implementation\r
97 public:\r
98 \r
99         /* Some user stuff*/\r
100         vector<feature_vector> m_features;\r
101         feature_vector m_avgs;\r
102     vector<string> m_gestureNames;\r
103         vector<fvector> m_covMatrices;\r
104     vector<bool> m_isCovMatCalculated;\r
105         long m_gestureCode;\r
106 \r
107     vector<IplImage*> m_dgMasks;\r
108     vector<gr_pose> m_geomParams;\r
109 \r
110         long m_minPointCount;\r
111         CvPoint3D32f* m_pointCloudBuffer;\r
112         long m_pointCount;\r
113         long m_handImage;\r
114         long m_errNo;\r
115         string m_errString;\r
116         long m_rawImage;\r
117         long m_task;\r
118         string m_path;\r
119         BOOL m_dynamicGesture;\r
120         string m_dGestureName;\r
121     string GetGestureName();\r
122     void SetGestureName(std::string name);\r
123     BOOL m_dynGestureFixed;\r
124     BOOL m_saveDynGest;\r
125                 \r
126         long GetGestureCode();\r
127         void SetGestureCode(long nNewValue);\r
128         long GetRecognizedCode();\r
129         void SetRecognizedCode(long nNewValue);\r
130         BOOL FitLine();\r
131         BOOL FindHand(_int64 _time, BOOL ForCenterOnly);\r
132         BOOL LoadGestures(LPCTSTR FileName);\r
133         BOOL SaveGestures(LPCTSTR FileName);\r
134         void UpdateDynGest();\r
135 \r
136 public:\r
137         CvMemStorage* m_storage;\r
138         void StoreDynGesture(IplImage* mask_rez, __int64 _time);\r
139         string GetRecognizedName();\r
140         string m_recognizedGesture;\r
141         int m_segThresh;\r
142         int m_trainFrameCount;\r
143         IplImage* m_mask;\r
144         void ClearGesture(string name);\r
145     BOOL IsGestureFixed() {return m_dynGestureFixed; }\r
146     void ReleaseFixedGesture() { m_dynGestureFixed = FALSE; ClearDynGest(); }\r
147         \r
148         void SetTask(long task);\r
149         BOOL m_staticGesture;\r
150         float m_center[3];\r
151         IplImage* m_disparityImage;\r
152         IplImage* m_outputImage;\r
153         IplImage* m_inputImage;\r
154         float m_line[6];\r
155         void SetPointBuffer(CvPoint3D32f* buffer);\r
156         //int m_dgFrameCount;\r
157     BOOL m_dgFrameFound;\r
158         BOOL _FindHand(_int64 _time, BOOL ForCenterOnly);\r
159         BOOL _RectifyInputMask(BOOL ForCenterOnly);\r
160         void CalculateCovarianceMatrix();\r
161 \r
162         int m_maskImprovigFlag;   // flag for the initial mask improving (0 for default) \r
163         int m_convexDefCount;     // counter of the convexity defects  \r
164         vector<float> m_DefectsDepth; \r
165 \r
166 private:\r
167         long m_time;\r
168         void ClearDynGest();\r
169         int m_dgFrameThreshold;\r
170         string m_num;\r
171     BOOL InitModulePath();\r
172         FILE* m_dgHandle;\r
173         void SaveDynGestures();\r
174 \r
175         float* m_linePre;\r
176         IplImage* m_maskPre;  // pointer to the previous initial hand mask \r
177         IplImage* m_resPre;   // pointer to the previous result hand mask \r
178         \r
179         int m_gestureIndex;\r
180         string Recognize(IplImage* image);\r
181 \r
182         string LogClassification();  //  logical classification of the static gestures\r
183 \r
184         long m_recognizedCode;\r
185         CvHuMoments CalculateHuMoments(IplImage* image);\r
186 };\r
187 \r
188 //{{AFX_INSERT_LOCATION}}\r
189 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.\r
190 \r
191 #endif // !defined(_GESTURE_RECOGNIZER_H_)\r