#include <face_recognizer.h>
Public Types | |
enum | Metrics { EUCLIDEAN, MAHALANOBIS, MAHALANOBISCOSINE } |
Public Member Functions | |
virtual unsigned long | addFace (cv::Mat &color_image, cv::Mat &depth_image, cv::Rect &face_bounding_box, cv::Rect &head_bounding_box, std::string label, std::vector< cv::Mat > &face_images, std::vector< cv::Mat > &face_depthmaps) |
virtual unsigned long | deleteFace (int index, std::vector< cv::Mat > &face_images, std::vector< cv::Mat > &face_depthmaps) |
virtual unsigned long | deleteFaces (std::string label, std::vector< cv::Mat > &face_images, std::vector< cv::Mat > &face_depthmaps) |
FaceRecognizer (void) | |
Constructor. | |
virtual unsigned long | init (std::string data_directory, int norm_size, bool norm_illumination, bool norm_align, bool norm_extreme_illumination, int metric, bool debug, std::vector< std::string > &identification_labels_to_recognize, int subs_meth, int feature_dim, bool use_unknown_thresh, bool use_depth) |
virtual unsigned long | initTraining (std::string data_directory, int norm_size, bool norm_illumination, bool norm_align, bool norm_extreme_illumination, bool debug, std::vector< cv::Mat > &face_images, std::vector< cv::Mat > &face_depthmaps, bool use_depth) |
virtual unsigned long | loadRecognitionModel (std::vector< std::string > &identification_labels_to_recognize) |
virtual unsigned long | saveRecognitionModel () |
virtual unsigned long | saveTrainingData (std::vector< cv::Mat > &face_images, std::vector< cv::Mat > &face_depthmaps) |
virtual unsigned long | saveTrainingData (std::vector< cv::Mat > &face_images) |
virtual unsigned long | trainRecognitionModel (std::vector< std::string > &identification_labels_to_train) |
virtual unsigned long | updateFaceLabel (int index, std::string new_label) |
virtual unsigned long | updateFaceLabels (std::string old_label, std::string new_label) |
~FaceRecognizer (void) | |
Destructor. | |
Protected Member Functions | |
void | assertDirectories (boost::filesystem::path &data_directory) |
virtual unsigned long | convertAndResize (cv::Mat &img, cv::Mat &resized, cv::Rect &face, cv::Size new_size) |
virtual unsigned long | loadTrainingData (std::vector< cv::Mat > &face_images, std::vector< std::string > &identification_labels_to_train) |
virtual unsigned long | loadTrainingData (std::vector< cv::Mat > &face_images, std::vector< cv::Mat > &face_depthmaps, std::vector< std::string > &identification_labels_to_train) |
virtual unsigned long | recognizeFace (cv::Mat &color_image, std::vector< cv::Rect > &face_coordinates, std::vector< std::string > &identification_labels) |
virtual unsigned long | recognizeFace (cv::Mat &color_image, cv::Mat &depth_image, std::vector< cv::Rect > &face_coordinates, std::vector< std::string > &identification_labels) |
unsigned long | trainFaceRecognition (ipa_PeopleDetector::FaceRecognizerBaseClass *eff, std::vector< cv::Mat > &data, std::vector< int > &labels) |
Protected Attributes | |
std::vector< int > | depth_num_labels |
Number of classes for depth training data. | |
std::vector< std::string > | depth_str_labels |
Vector for class label strings for depth training data. | |
std::vector< std::string > | depth_str_labels_unique |
Vector for class unique label strings for depth training data. | |
std::vector< bool > | dm_exist |
vector indicating if depth map exists for corresponding color image | |
ipa_PeopleDetector::FaceRecognizerBaseClass * | eff_color |
FaceRecognizer for color images. | |
ipa_PeopleDetector::FaceRecognizerBaseClass * | eff_depth |
FaceRecognizer for depth maps. | |
FaceNormalizer | face_normalizer_ |
Face normalizer object. | |
cv::Mat | m_average_image |
Trained average Image. | |
std::vector< std::string > | m_current_label_set |
A vector containing all different labels from the training session exactly once, order of appearance matters! (m_current_label_set[i] stores the corresponding name to the average face coordinates in the face subspace in m_face_class_average_projections.rows(i)) | |
boost::filesystem::path | m_data_directory |
folder that contains the training data | |
boost::mutex | m_data_mutex |
secures the internal data variables against usage during training | |
bool | m_debug |
enables some debug outputs | |
bool | m_depth_mode |
flag indicates if depth maps are ignored or used for classification | |
cv::Mat | m_eigenvalues |
Eigenvalues. | |
std::vector< cv::Mat > | m_eigenvectors |
Eigenvectors (spanning the face space) | |
IplImage ** | m_eigenvectors_ipl |
Eigenvalues stored in IplImage format (to avoid conversion each time the function is called) | |
int | m_eigenvectors_per_person |
Number of eigenvectors per person to identify -> controls the total number of eigenvectors. | |
cv::Mat | m_face_class_average_projections |
The average factors of the eigenvector decomposition from each face class; The average factors from each face class originating from the eigenvector decomposition. | |
cv::SVM | m_face_classifier |
classifier for the identity of a person | |
std::vector< std::string > | m_face_labels |
A vector containing the corresponding labels to each face image projection in m_projected_training_faces (m_face_labels[i] stores the corresponding name to the face representation in the face subspace in m_projected_training_faces.rows(i)) | |
int | m_feature_dim |
Dimension of features that is computed when using Eigenfaces,2D-PCA, 2D-LDA. | |
std::vector< int > | m_label_num |
int | m_metric |
metric for nearest neighbor search in face space: 0 = Euklidean, 1 = Mahalanobis, 2 = Mahalanobis Cosine | |
int | m_norm_size |
Desired width and height of the Eigenfaces (=eigenvectors). | |
cv::Mat | m_projected_training_faces |
Projected training faces (coefficients for the eigenvectors of the face subspace) | |
int | m_rec_method |
flag for recognition method | |
ipa_PeopleDetector::Method | m_subs_meth |
recognition method | |
double | m_threshold_facespace |
Threshold to facespace. | |
double | m_threshold_unknown |
Threshold to detect unknown faces. | |
bool | m_use_unknown_thresh |
flag indicates if unknown threshold is used |
Definition at line 87 of file face_recognizer.h.
Definition at line 165 of file face_recognizer.h.
Destructor.
Definition at line 92 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::addFace | ( | cv::Mat & | color_image, |
cv::Mat & | depth_image, | ||
cv::Rect & | face_bounding_box, | ||
cv::Rect & | head_bounding_box, | ||
std::string | label, | ||
std::vector< cv::Mat > & | face_images, | ||
std::vector< cv::Mat > & | face_depthmaps | ||
) | [virtual] |
Function to add a new face The function adds a new face to the trained images. The labels are stored internally in m_face_labels. The face_images are stored externally to avoid waste of memory.
color_image | Color image containing the face |
face_bounding_box | Rectangular bounding box of the detected face |
label | Label of the new face |
face_images | Vector containing all trained images |
Definition at line 202 of file face_recognizer.cpp.
void ipa_PeopleDetector::FaceRecognizer::assertDirectories | ( | boost::filesystem::path & | data_directory | ) | [protected] |
Function can be used to verify the existence of the data directory and created if it does not exist. Assertion of the data directory
[in] | data_directory | Path to top level directory with training data |
Definition at line 919 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::convertAndResize | ( | cv::Mat & | img, |
cv::Mat & | resized, | ||
cv::Rect & | face, | ||
cv::Size | new_size | ||
) | [protected, virtual] |
Function to find the closest face class The function calculates the distance of each sample image to the trained face class
eigen_vector_weights | The weights of corresponding eigenvectors of projected test face |
face_label | Label of closest face, or 'Unknown' if the face is unknown |
number_eigenvectors | Number of eigenvalues |
Definition at line 588 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::deleteFace | ( | int | index, |
std::vector< cv::Mat > & | face_images, | ||
std::vector< cv::Mat > & | face_depthmaps | ||
) | [virtual] |
Deletes the database entry with the provided index.
index | The index of the database entry which shall be deleted |
face_images | Vector containing all trained images |
Definition at line 260 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::deleteFaces | ( | std::string | label, |
std::vector< cv::Mat > & | face_images, | ||
std::vector< cv::Mat > & | face_depthmaps | ||
) | [virtual] |
Deletes all database entries with the provided label.
label | The label of the database entries which shall be deleted |
face_images | Vector containing all trained images |
Definition at line 246 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::init | ( | std::string | data_directory, |
int | norm_size, | ||
bool | norm_illumination, | ||
bool | norm_align, | ||
bool | norm_extreme_illumination, | ||
int | metric, | ||
bool | debug, | ||
std::vector< std::string > & | identification_labels_to_recognize, | ||
int | subs_meth, | ||
int | feature_dim, | ||
bool | use_unknown_thresh, | ||
bool | use_depth | ||
) | [virtual] |
Initialization function. Parameters: see class member explanations.
data_directory | The directory for data files |
identification_labels_to_recognize | A list of labels of persons that shall be recognized |
Definition at line 102 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::initTraining | ( | std::string | data_directory, |
int | norm_size, | ||
bool | norm_illumination, | ||
bool | norm_align, | ||
bool | norm_extreme_illumination, | ||
bool | debug, | ||
std::vector< cv::Mat > & | face_images, | ||
std::vector< cv::Mat > & | face_depthmaps, | ||
bool | use_depth | ||
) | [virtual] |
Initialization function for training purposes (only for capturing images, not the training of recognition models). Parameters: see class member explanations.
data_directory | The directory for data files |
face_images | A list of images of persons that shall be recognized which will be loaded by the function. |
Definition at line 173 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::loadRecognitionModel | ( | std::vector< std::string > & | identification_labels_to_recognize | ) | [virtual] |
Loads a model for the recognition of a given set of faces.
identification_labels_to_recognize | List of labels whose corresponding faces shall be available for recognition |
Implements ipa_PeopleDetector::AbstractFaceRecognizer.
Definition at line 368 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::loadTrainingData | ( | std::vector< cv::Mat > & | face_images, |
std::vector< std::string > & | identification_labels_to_train | ||
) | [protected, virtual] |
Loads the training data for the persons specified in identification_labels_to_train
face_images | A vector containing all training images |
identification_indices_to_train | List of labels whose corresponding faces shall be trained. If empty, all available data is used and this list is filled with the labels. |
Definition at line 713 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::loadTrainingData | ( | std::vector< cv::Mat > & | face_images, |
std::vector< cv::Mat > & | face_depthmaps, | ||
std::vector< std::string > & | identification_labels_to_train | ||
) | [protected, virtual] |
Definition at line 807 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::recognizeFace | ( | cv::Mat & | color_image, |
std::vector< cv::Rect > & | face_coordinates, | ||
std::vector< std::string > & | identification_labels | ||
) | [protected, virtual] |
Function to Recognize faces The function recognize the faces
color_image | source color image |
face_coordinates | Bounding boxes of detected faces (input parameter) |
identification_labels | Vector of labels of classified faces, vector indices correspond with bounding boxes in face_coordinates |
Implements ipa_PeopleDetector::AbstractFaceRecognizer.
Definition at line 474 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::recognizeFace | ( | cv::Mat & | color_image, |
cv::Mat & | depth_image, | ||
std::vector< cv::Rect > & | face_coordinates, | ||
std::vector< std::string > & | identification_labels | ||
) | [protected, virtual] |
Implements ipa_PeopleDetector::AbstractFaceRecognizer.
Definition at line 528 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::saveRecognitionModel | ( | ) | [virtual] |
Saves the currently trained model for the recognition of a given set of faces.
Implements ipa_PeopleDetector::AbstractFaceRecognizer.
Definition at line 323 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::saveTrainingData | ( | std::vector< cv::Mat > & | face_images, |
std::vector< cv::Mat > & | face_depthmaps | ||
) | [virtual] |
Saves the training data
face_images | A vector containing all training images |
Definition at line 645 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::saveTrainingData | ( | std::vector< cv::Mat > & | face_images | ) | [virtual] |
Definition at line 598 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::trainFaceRecognition | ( | ipa_PeopleDetector::FaceRecognizerBaseClass * | eff, |
std::vector< cv::Mat > & | data, | ||
std::vector< int > & | labels | ||
) | [protected] |
Definition at line 267 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::trainRecognitionModel | ( | std::vector< std::string > & | identification_labels_to_train | ) | [virtual] |
Trains a model for the recognition of a given set of faces.
identification_indices_to_train | List of labels whose corresponding faces shall be trained. If empty, all available data is used and this list is filled with the labels. |
Implements ipa_PeopleDetector::AbstractFaceRecognizer.
Definition at line 287 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::updateFaceLabel | ( | int | index, |
std::string | new_label | ||
) | [virtual] |
Updates the label of a single face in the database.
index | The index of the face in the database whose label shall be replaced by the new label |
new_label | The new label |
Definition at line 240 of file face_recognizer.cpp.
unsigned long ipa_PeopleDetector::FaceRecognizer::updateFaceLabels | ( | std::string | old_label, |
std::string | new_label | ||
) | [virtual] |
Updates the labels of a stored person.
old_label | The label in the database which shall be replaced by the new label |
new_label | The new label |
Definition at line 230 of file face_recognizer.cpp.
std::vector<int> ipa_PeopleDetector::FaceRecognizer::depth_num_labels [protected] |
Number of classes for depth training data.
Definition at line 204 of file face_recognizer.h.
std::vector<std::string> ipa_PeopleDetector::FaceRecognizer::depth_str_labels [protected] |
Vector for class label strings for depth training data.
Definition at line 202 of file face_recognizer.h.
std::vector<std::string> ipa_PeopleDetector::FaceRecognizer::depth_str_labels_unique [protected] |
Vector for class unique label strings for depth training data.
Definition at line 203 of file face_recognizer.h.
std::vector<bool> ipa_PeopleDetector::FaceRecognizer::dm_exist [protected] |
vector indicating if depth map exists for corresponding color image
Definition at line 212 of file face_recognizer.h.
ipa_PeopleDetector::FaceRecognizerBaseClass* ipa_PeopleDetector::FaceRecognizer::eff_color [protected] |
FaceRecognizer for color images.
Definition at line 209 of file face_recognizer.h.
ipa_PeopleDetector::FaceRecognizerBaseClass* ipa_PeopleDetector::FaceRecognizer::eff_depth [protected] |
FaceRecognizer for depth maps.
Definition at line 208 of file face_recognizer.h.
Face normalizer object.
Definition at line 206 of file face_recognizer.h.
cv::Mat ipa_PeopleDetector::FaceRecognizer::m_average_image [protected] |
Trained average Image.
Definition at line 224 of file face_recognizer.h.
std::vector<std::string> ipa_PeopleDetector::FaceRecognizer::m_current_label_set [protected] |
A vector containing all different labels from the training session exactly once, order of appearance matters! (m_current_label_set[i] stores the corresponding name to the average face coordinates in the face subspace in m_face_class_average_projections.rows(i))
Definition at line 228 of file face_recognizer.h.
boost::filesystem::path ipa_PeopleDetector::FaceRecognizer::m_data_directory [protected] |
folder that contains the training data
Definition at line 230 of file face_recognizer.h.
boost::mutex ipa_PeopleDetector::FaceRecognizer::m_data_mutex [protected] |
secures the internal data variables against usage during training
Definition at line 233 of file face_recognizer.h.
bool ipa_PeopleDetector::FaceRecognizer::m_debug [protected] |
enables some debug outputs
Definition at line 241 of file face_recognizer.h.
bool ipa_PeopleDetector::FaceRecognizer::m_depth_mode [protected] |
flag indicates if depth maps are ignored or used for classification
Definition at line 213 of file face_recognizer.h.
cv::Mat ipa_PeopleDetector::FaceRecognizer::m_eigenvalues [protected] |
Eigenvalues.
Definition at line 223 of file face_recognizer.h.
std::vector<cv::Mat> ipa_PeopleDetector::FaceRecognizer::m_eigenvectors [protected] |
Eigenvectors (spanning the face space)
Definition at line 221 of file face_recognizer.h.
IplImage** ipa_PeopleDetector::FaceRecognizer::m_eigenvectors_ipl [protected] |
Eigenvalues stored in IplImage format (to avoid conversion each time the function is called)
Definition at line 222 of file face_recognizer.h.
int ipa_PeopleDetector::FaceRecognizer::m_eigenvectors_per_person [protected] |
Number of eigenvectors per person to identify -> controls the total number of eigenvectors.
Definition at line 237 of file face_recognizer.h.
cv::Mat ipa_PeopleDetector::FaceRecognizer::m_face_class_average_projections [protected] |
The average factors of the eigenvector decomposition from each face class; The average factors from each face class originating from the eigenvector decomposition.
Definition at line 227 of file face_recognizer.h.
cv::SVM ipa_PeopleDetector::FaceRecognizer::m_face_classifier [protected] |
classifier for the identity of a person
Definition at line 229 of file face_recognizer.h.
std::vector<std::string> ipa_PeopleDetector::FaceRecognizer::m_face_labels [protected] |
A vector containing the corresponding labels to each face image projection in m_projected_training_faces (m_face_labels[i] stores the corresponding name to the face representation in the face subspace in m_projected_training_faces.rows(i))
Definition at line 226 of file face_recognizer.h.
int ipa_PeopleDetector::FaceRecognizer::m_feature_dim [protected] |
Dimension of features that is computed when using Eigenfaces,2D-PCA, 2D-LDA.
Definition at line 243 of file face_recognizer.h.
std::vector<int> ipa_PeopleDetector::FaceRecognizer::m_label_num [protected] |
Definition at line 210 of file face_recognizer.h.
int ipa_PeopleDetector::FaceRecognizer::m_metric [protected] |
metric for nearest neighbor search in face space: 0 = Euklidean, 1 = Mahalanobis, 2 = Mahalanobis Cosine
Definition at line 240 of file face_recognizer.h.
int ipa_PeopleDetector::FaceRecognizer::m_norm_size [protected] |
Desired width and height of the Eigenfaces (=eigenvectors).
Definition at line 236 of file face_recognizer.h.
cv::Mat ipa_PeopleDetector::FaceRecognizer::m_projected_training_faces [protected] |
Projected training faces (coefficients for the eigenvectors of the face subspace)
Definition at line 225 of file face_recognizer.h.
int ipa_PeopleDetector::FaceRecognizer::m_rec_method [protected] |
flag for recognition method
Definition at line 211 of file face_recognizer.h.
recognition method
Definition at line 214 of file face_recognizer.h.
double ipa_PeopleDetector::FaceRecognizer::m_threshold_facespace [protected] |
Threshold to facespace.
Definition at line 238 of file face_recognizer.h.
double ipa_PeopleDetector::FaceRecognizer::m_threshold_unknown [protected] |
Threshold to detect unknown faces.
Definition at line 239 of file face_recognizer.h.
bool ipa_PeopleDetector::FaceRecognizer::m_use_unknown_thresh [protected] |
flag indicates if unknown threshold is used
Definition at line 215 of file face_recognizer.h.