Update the changelog
[opencv] / apps / HMMDemo / FaceBase.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*/// FaceBase.h: interface for the CFaceBase class.
41 //
42 //////////////////////////////////////////////////////////////////////
43
44 #if !defined(AFX_FACEBASE_H__76CC3F61_D0C7_4CF8_8479_84950282D632__INCLUDED_)
45 #define AFX_FACEBASE_H__76CC3F61_D0C7_4CF8_8479_84950282D632__INCLUDED_
46
47 #if _MSC_VER > 1000
48 #pragma once
49 #endif // _MSC_VER > 1000
50
51 #include "ContEHMM.h"   
52 #define TRAIN_ALL 1
53 #define TRAIN_UNTRAINED 2
54
55 class CPersonImage;
56 class CPerson;
57 class CFaceBase;
58           
59 typedef  CList<CPersonImage*,CPersonImage*> CPersonImgList;
60 typedef CList<CPerson*,CPerson*> CPersonList;
61
62 class CFaceBase  
63 {
64 public:
65         int RecognizeOtherBase(CFaceBase* other );
66         int RecognizePerson(CImage& image, CRect roi, int* three_first );
67     int RecognizeBatch(CStringList* image_list);
68
69         void TrainAll( int flag );
70         void TrainPerson( int index, bool loaded );
71         CFaceBase();
72         virtual ~CFaceBase();
73
74     void     SetFileName( const CString& filename );
75     const CString&  GetFileName() { return m_filename; }
76     void     SetName( const CString& name );
77     const CString&  GetName() { return m_basename; }
78     bool     Load();
79     void     Unload();
80     bool     Save();
81     CPerson* AddPerson( const char* name, const char* folder, bool import_data );
82     void     RemovePerson( POSITION pos );
83     CPersonList& GetPersonList() { return m_base; };
84     void     SetImageSize( CSize size );
85     CSize    GetImageSize() { return m_baseImgSize; };
86     void     SetModified( bool modified = true ) { m_modified = modified; }
87     bool     IsModified() { return m_modified; }
88     void     Draw( int index, CImage& img, SIZE win_size, int y_pos,
89                    SIZE pic_size, SIZE delta );
90     CPerson* GetPerson( int index );
91     CPerson* FindPersonByName( const CString& name );
92     int      GetPersonIndex( CPerson* person );
93     CImage&  GetTrainedImage() { return m_trained_image; }
94     int      GetTrainedIndex() { return m_trained_index; }
95     void     SetTrainedIndex( int index ) { m_trained_index = index; }
96     void     UpdateTrainedImage();
97     void     SetBaseView( CWnd* view ) { m_base_view = view; }
98     CWnd*    GetBaseView() { return m_base_view; }
99     void     DeleteHMMInfo();
100
101     int  SetParams( //sampling params
102                     CvSize dctSize, 
103                     CvSize obsSize, 
104                     CvSize delta,
105                     //HMM params
106                     int* states, int mix,
107                     //image scaling params
108                     BOOL use_width, int width,
109                     BOOL use_height, int height,
110                     BOOL suppress_intens,
111                     BOOL leave_hmm_alive = FALSE);
112
113
114     //hmm params 
115     int m_stnum[32];
116     int m_mixnum[128];
117     
118     CvSize m_delta;
119     CvSize m_obsSize;
120     CvSize m_dctSize;
121
122     BOOL m_useWidth; 
123     BOOL m_useHeight; 
124     int m_scaleWidth; 
125     int m_scaleHeight;
126
127     BOOL m_suppress_intensity;
128
129 protected:
130     CSize    m_baseImgSize;
131     CString  m_filename;
132     CString  m_basename;
133     CPersonList m_base;
134     bool     m_modified;
135     int      m_trained_index;
136     CImage   m_trained_image;
137     CWnd*    m_base_view;
138
139     bool     GetPersonFolder( const char* root_folder, int root_folder_len,
140                               const char* person_folder, char* folder );
141     void     GetPersonSubFolder( const char* folder, char* subfolder );
142     void     GetRootFolder( char* root_folder, int* root_path_len );
143 };
144
145
146 class CPerson  
147 {
148 public:
149         void ClearHMM();
150         CContEHMM& GetHMM();
151         CPerson( CFaceBase* parent );
152     virtual ~CPerson();
153
154     void     SetName( const CString& name );
155     const CString& GetName() { return m_name; }
156     void     SetFolder( const CString& folder );
157     void     GenerateFileName( const char* base, char* filename );
158     const CString& GetFolder() { return m_folder; }
159     void     AddImage( const char* filename, CImage* import_image, CRect roi );
160     void     RemoveImage( POSITION pos );
161     void     MoveToTop( POSITION pos );
162     bool     Load();
163     void     Unload();
164     bool     Save();
165     void     LoadRest();
166     void     UnloadRest();
167     CPersonImgList& GetImgList() { return m_imgs; }
168     void     SetModified( bool modified = true )
169     {
170         m_modified = modified;
171         if( modified )
172             m_trained = false;
173     }
174     bool     IsModified() { return m_modified; }
175     CFaceBase*  GetParentBase() { return m_parent; }
176     void     TrainHMM();
177     bool     IsTrained() { return m_trained; };
178     void     DeleteHMMInfo();
179
180
181 protected:
182     CString  m_name;
183     CString  m_folder;
184     CPersonImgList  m_imgs;
185     CContEHMM m_hmm;
186     CFaceBase* m_parent;
187
188     bool     m_trained;
189
190
191     bool     m_modified;
192
193     bool     GetPersonFullImageName( const char* root, int root_len,
194                                      const char* image, char* full_image_name );
195     void     ExtractPersonImageName( const char* full_image_name, char* image );
196 };
197
198
199 class CPersonImage
200 {
201 public:
202     
203     CPersonImage();
204     virtual ~CPersonImage();
205     bool     Save();
206     bool     Load();
207     void     Unload();
208     void     SetFileName( const CString& filename );
209     void     SetRoiInFile( CRect r );
210     CRect    GetRoiInFile() { return m_roi_in_file; }
211     const CString& GetFileName() { return m_filename; }
212     void     SetModified( bool modified = true ) { m_modified = modified; }
213     bool     IsModified() { return m_modified; }
214     void     CalcRect( SIZE win_size, POINT pos, SIZE base_size,
215                        CRect& src_rect, CRect& dst_rect );
216     void     Draw( CImage& img, SIZE win_size, POINT pos, SIZE pic_size );
217     CImage&  GetImage() { return m_img; }
218
219 protected:
220     CString  m_filename;
221     CImage   m_img;
222     CRect    m_roi_in_file;
223     bool     m_modified;
224 };
225
226 void ConvertNameToFolder( const char* name, char* folder );
227
228 #endif // !defined(AFX_FACEBASE_H__76CC3F61_D0C7_4CF8_8479_84950282D632__INCLUDED_)