[94] | 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 "FaceBank.h" |
---|
| 18 | #include "highgui.h" |
---|
| 19 | #include "tinyxml.h" |
---|
| 20 | |
---|
| 21 | #include <vector> |
---|
| 22 | |
---|
| 23 | #ifdef WIN32 |
---|
| 24 | #include <string> |
---|
| 25 | #define snprintf _snprintf |
---|
| 26 | #endif |
---|
| 27 | |
---|
| 28 | using namespace std; |
---|
| 29 | |
---|
| 30 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 31 | |
---|
| 32 | FaceBank::FaceBank(unsigned int FaceWidth, unsigned int FaceHeight, float ErrorThresh, float NewImageThresh, Classifier *c) : |
---|
| 33 | m_FaceWidth(FaceWidth), |
---|
| 34 | m_FaceHeight(FaceHeight), |
---|
| 35 | m_ErrorThresh(ErrorThresh), |
---|
| 36 | m_NewImageThresh(NewImageThresh), |
---|
| 37 | m_Classifier(c) |
---|
| 38 | { |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | FaceBank::~FaceBank() |
---|
| 42 | { |
---|
| 43 | Clear(); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | void FaceBank::Clear() |
---|
| 47 | { |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | float FaceBank::Suggest(Image face, unsigned int ID) |
---|
| 51 | { |
---|
| 52 | // Subtract the mean as an attempt to deal with global lighting changes |
---|
| 53 | face.SubMean(); |
---|
| 54 | |
---|
| 55 | m_Classifier->AddFeature(ID,face.Scale(m_FaceWidth,m_FaceHeight).RGB2GRAY().ToFloatVector()); |
---|
| 56 | //m_FaceMap[ID]=face; |
---|
| 57 | |
---|
| 58 | return 1; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | float FaceBank::Identify(Image face, unsigned int &ID, int &imagenum) |
---|
| 62 | { |
---|
| 63 | // Subtract the mean as an attempt to deal with global lighting changes |
---|
| 64 | face.SubMean(); |
---|
| 65 | |
---|
| 66 | float error; |
---|
| 67 | ID = m_Classifier->Classify(face.Scale(m_FaceWidth,m_FaceHeight).RGB2GRAY().ToFloatVector(),error); |
---|
| 68 | |
---|
| 69 | // if the error is less than the threshold, return the id |
---|
| 70 | if (error<m_ErrorThresh) |
---|
| 71 | { |
---|
| 72 | return 1-error; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | cerr<<"unrecognised face"<<endl; |
---|
| 76 | ID=-1; |
---|
| 77 | return 0; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | void FaceBank::Save(const std::string &filename) const |
---|
| 81 | { |
---|
| 82 | |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | void FaceBank::Load(const std::string &filename) |
---|
| 86 | { |
---|
| 87 | |
---|
| 88 | } |
---|