Update the changelog
[opencv] / apps / StereoGR / DynGestServer.h
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of Intel Corporation may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/// DynGestServer.h: interface for the CDynGestServer class.
41 //
42 //////////////////////////////////////////////////////////////////////
43
44 #if !defined(AFX_DYNGESTSERVER_H__8C7A165D_57D3_4AB9_B764_08E5C86DFC3B__INCLUDED_)
45 #define AFX_DYNGESTSERVER_H__8C7A165D_57D3_4AB9_B764_08E5C86DFC3B__INCLUDED_
46
47 #if _MSC_VER > 1000
48 #pragma once
49 #endif // _MSC_VER > 1000
50
51 #include "CV.h"
52 #include "cvaux.h"
53 #include <vector>  
54 #include "FindHandCtl.h"
55
56 using namespace std;
57
58 //this is definition of class which will work with dynamic gestures,
59 // including accumulating data, training HMMs and recognition
60 class CDynGesture
61 {
62 public:
63         BOOL LoadFromFile( const char* filename );
64         void CreateHMM();
65         int GetSeqNumber();
66
67     CvEHMM* GetHMM() { return m_hmm; } 
68
69     CDynGesture( int num_states, int num_mix );
70     virtual ~CDynGesture();
71     void AddSequence( float* vectors, int seq_size, int vect_size );
72         BOOL AddParams( vector<_gr_pose>& input_vect );
73     void Train();
74     BOOL LoadHMM(const char* filename);
75     BOOL SaveHMM(const char* filename);
76     void  SetName( const char* name ) { m_name = name; }
77     CString GetName() { return m_name; }
78
79         void ExtractObservations();
80     
81     BOOL SaveParams(const char* path);
82     BOOL LoadParams(const char* path);
83
84     BOOL LoadSequence( const char* filename );
85     void DestroyHMM();
86
87
88 protected:
89     vector< vector<gr_pose> >  m_Params;
90         enum { OT_VELOCITY, OT_VELOCITY_ORIENTATION }       m_obsType;
91
92     vector<Cv1DObsInfo*> m_Sequences;
93     CvEHMM*              m_hmm;
94     CString              m_name;
95     int                  m_vect_size;
96
97     void CleanSequences();
98
99
100 public:
101         void DeleteHMM();
102         CvImgObsInfo** GetSequences();
103     BOOL                 m_trained;
104
105     int m_num_states;
106     int m_num_mix; 
107
108 };
109     
110
111 class CDynGestServer  
112 {
113 public:
114         void DeleteHMMInfo();
115
116     void CleanAll();
117
118     BOOL SaveGestureBase( const char *filename );
119         BOOL LoadGestureBase( const char* filename );
120         int RecognizeDynGesture( CDynGesture* gesture, float* likelihood );
121         void TrainAllGestures();
122         CDynGestServer();
123         virtual ~CDynGestServer();
124
125     int GetNumGestures() { return m_gestures.size(); }
126     CDynGesture* FindGesture( const char* name );
127     CDynGesture* AddGesture( const char* name );
128     BOOL AddGesture( CDynGesture* new_gest );
129     BOOL RemoveGesture( const char* name );
130     
131
132     CDynGesture* GetGesture( int i ) { return m_gestures[i]; }   
133     void SetHMMParams( int num_state, int num_mix );
134
135
136
137 protected:
138         BOOL m_fullTrained;
139     vector<CDynGesture*> m_gestures;
140     int m_num_states;
141     int m_num_mix;
142
143     CString m_loaded_base;
144         
145 };
146
147 #endif // !defined(AFX_DYNGESTSERVER_H__8C7A165D_57D3_4AB9_B764_08E5C86DFC3B__INCLUDED_)