1 | // Copyright (C) 2009 foam |
---|
2 | // |
---|
3 | // This program is free software; you can redistribute it and/or modify |
---|
4 | // it under the terms of the GNU General Public License as published by |
---|
5 | // the Free Software Foundation; either version 2 of the License, or |
---|
6 | // (at your option) any later version. |
---|
7 | // |
---|
8 | // This program is distributed in the hope that it will be useful, |
---|
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | // GNU General Public License for more details. |
---|
12 | // |
---|
13 | // You should have received a copy of the GNU General Public License |
---|
14 | // along with this program; if not, write to the Free Software |
---|
15 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
16 | |
---|
17 | #include <iostream> |
---|
18 | #include <map> |
---|
19 | #include <vector> |
---|
20 | #include <assert.h> |
---|
21 | #include "cv.h" |
---|
22 | #include "Classifier.h" |
---|
23 | #include "Image.h" |
---|
24 | |
---|
25 | #ifndef FACE_BANK |
---|
26 | #define FACE_BANK |
---|
27 | |
---|
28 | class FaceBank |
---|
29 | { |
---|
30 | public: |
---|
31 | // FaceWidth and FaceHeight are the size for the internal stored image of the face for |
---|
32 | // comparison, ErrorThresh is the threshold at which a face will be considered as recognised, |
---|
33 | // NewImageThresh is a threshold greater than which a suggested face will be stored as |
---|
34 | // a new image. |
---|
35 | FaceBank(unsigned int FaceWidth, unsigned int FaceHeight, float ErrorThresh, float NewImageThresh, Classifier *c); |
---|
36 | ~FaceBank(); |
---|
37 | |
---|
38 | void Clear(); |
---|
39 | |
---|
40 | void SetErrorThresh(float s) { m_ErrorThresh=s; } |
---|
41 | void SetNewImageThresh(float s) { m_NewImageThresh=s; } |
---|
42 | |
---|
43 | // Learn this face, the face may be a false positive, so we'll discard the |
---|
44 | // suggestion if we've seen it before, and the error is greater than ErrorThresh |
---|
45 | float Suggest(Image face, unsigned int ID); |
---|
46 | |
---|
47 | // Gives the id, given a face, and returns the confidence |
---|
48 | float Identify(Image face, unsigned int &ID, int &imagenum); |
---|
49 | |
---|
50 | std::map<unsigned int, Image> &GetFaceMap() { return m_FaceMap; } |
---|
51 | |
---|
52 | unsigned int GetFaceWidth() { return m_FaceWidth; } |
---|
53 | unsigned int GetFaceHeight() { return m_FaceHeight; } |
---|
54 | |
---|
55 | void Save(const std::string &filename) const; |
---|
56 | void Load(const std::string &filename); |
---|
57 | |
---|
58 | Classifier *GetClassifier() { return m_Classifier; } |
---|
59 | |
---|
60 | private: |
---|
61 | |
---|
62 | unsigned int m_FaceWidth; |
---|
63 | unsigned int m_FaceHeight; |
---|
64 | float m_ErrorThresh; |
---|
65 | float m_NewImageThresh; |
---|
66 | |
---|
67 | std::map<unsigned int, Image> m_FaceMap; |
---|
68 | |
---|
69 | Classifier *m_Classifier; |
---|
70 | }; |
---|
71 | |
---|
72 | #endif |
---|