|
visageSDK
|
VisageFaceRecognition class contains a face recognition algorithm capable of measuring similarity between human faces and recognizing a person's identity from frontal facial images (yaw angle approximately from -20 to 20 degrees) by comparing face descriptors. More...
#include <VisageFaceRecognition.h>
Public Member Functions | |
| VisageFaceRecognition (const char *dataPath) | |
| Constructor. More... | |
| ~VisageFaceRecognition () | |
| Destructor. | |
| int | getDescriptorSize () |
| Gets the descriptor's size. More... | |
| int | extractDescriptor (FaceData *facedata, VsImage *image, short *descriptor) |
| Extracts the face descriptor for face recognition from a facial image. More... | |
| float | descriptorsSimilarity (short *first_descriptor, short *second_descriptor) |
| Calculates similarity between two descriptors. More... | |
| int | addDescriptor (VsImage *image, FaceData *facedata, const char *name) |
| Extracts a face descriptor from the input RGB, RGBA or grayscale image and adds it to the gallery. More... | |
| int | addDescriptor (short *descriptor, const char *name) |
| Adds face descriptor to the gallery. More... | |
| int | getDescriptorCount () |
| Gets number of descriptors in the gallery. More... | |
| int | getDescriptorName (char *name, int index) |
| Gets the name of a descriptor at the given index in the gallery. More... | |
| int | replaceDescriptorName (const char *name, int index) |
| Replaces the name of a descriptor at the given index in the gallery with new name. More... | |
| int | removeDescriptor (int index) |
| Removes a descriptor at the given index from the gallery. More... | |
| int | saveGallery (const char *file_name) |
| Save gallery as a binary file. More... | |
| int | loadGallery (const char *file_name) |
| Load gallery from a binary file. More... | |
| void | resetGallery () |
| Clear all face descriptors from the gallery. | |
| int | recognize (short *descriptor, int n, const char **names, float *similarities) |
| Compare a face to all faces in the current gallery and return n names of the most similar faces. More... | |
Public Attributes | |
| bool | is_initialized |
| If the model used in the VisageFaceRecognition is loaded and initialized successfully value of the is_initialized variable is true, otherwise it is false. More... | |
VisageFaceRecognition class contains a face recognition algorithm capable of measuring similarity between human faces and recognizing a person's identity from frontal facial images (yaw angle approximately from -20 to 20 degrees) by comparing face descriptors.
The face descriptor is a condensed representation of a face. It is an array of short values. The dimension of the array is obtained using getDescriptorSize() function, from now on in the text referred to as DESCRIPTOR_SIZE.
To extract descriptors from facial image, method extractDescriptor() is provided.
Similarity between two faces is calculated as distance between their face descriptors and returned as a value between 0 (no similarity) and 1 (maximum similarity) using descriptorsSimilarity().
For a person to be recognized, its identity has to be stored beforehand. Database of stored face descriptors will be referred to as face recognition gallery. For smaller sets of face descriptors (up to several hundred), higher-level API for recognizing person's identity using face recognition gallery is provided. The gallery is an array of face descriptors, with a corresponding array of names, so that the gallery may contain n descriptors and a corresponding name for each descriptor. To perform recognition, the face descriptor extracted from the input image is then compared with face descriptors from the gallery and the similarity between the input face descriptor and all face descriptors from the gallery is calculated in order to find the face(s) from the gallery that are most similar to the input face. The VisageFaceRecognition class includes the following set of functions for manipulating the gallery, including adding, removing, naming descriptors in the gallery as well as loading and saving the gallery to file:
The gallery is stored as a simple txt file and as such it is not intended to be used to save large number of face descriptors. The current implementation of gallery is only a demonstration of how Face Recognition API can be used and it is recommended to implement more efficient solution for scenarios which require large face recognition gallery.
Definition at line 87 of file VisageFaceRecognition.h.
| VisageSDK::VisageFaceRecognition::VisageFaceRecognition | ( | const char * | dataPath | ) |
Constructor.
| dataPath | path to the data file required for face recognition - fr.vino.bin provided in Samples/data/vfr. It is required that fr.vino.xml be present in the same folder. |
| int VisageSDK::VisageFaceRecognition::addDescriptor | ( | short * | descriptor, |
| const char * | name | ||
| ) |
Adds face descriptor to the gallery.
| descriptor | descriptor to be added to the gallery obtained by calling extractDescriptor. |
| name | name of the descriptor. |
| int VisageSDK::VisageFaceRecognition::addDescriptor | ( | VsImage * | image, |
| FaceData * | facedata, | ||
| const char * | name | ||
| ) |
Extracts a face descriptor from the input RGB, RGBA or grayscale image and adds it to the gallery.
| image | VsImage pointer that contains the input RGB, RGBA or grayscale image. The image should contain only one face and this face will be added to the gallery. In case of multiple faces in the image, it is not defined which face would be used. |
| facedata | facial data obtained from VisageTracker or VisageFeaturesDetector. |
| name | name of the face in the image. |
See also: VsImage
| float VisageSDK::VisageFaceRecognition::descriptorsSimilarity | ( | short * | first_descriptor, |
| short * | second_descriptor | ||
| ) |
Calculates similarity between two descriptors.
The function returns a float value between 0 and 1. Two descriptors are equal if the similarity is 1. Two descriptors are completely different if the similarity is 0.
| first_descriptor | pointer to the first descriptor, an array of DESCRIPTOR_SIZE short values. |
| second_descriptor | pointer to the second descriptor, an array of DESCRIPTOR_SIZE short values. |
| int VisageSDK::VisageFaceRecognition::extractDescriptor | ( | FaceData * | facedata, |
| VsImage * | image, | ||
| short * | descriptor | ||
| ) |
Extracts the face descriptor for face recognition from a facial image.
Prior to using this function, it is necessary to process the facial image or video frame using VisageTracker or VisageFeaturesDetector and pass the obtained facial data to this function. An example of use:
| facedata | facial data obtained from VisageTracker or VisageFeaturesDetector. |
| image | VsImage pointer to the input RGB, RGBA or grayscale image. |
| descriptor | pointer to a DESCRIPTOR_SIZE-dimensional array of short. The resulting face descriptor is returned in this array. |
See also: FaceData, VisageTracker, VisageFeaturesDetector
| int VisageSDK::VisageFaceRecognition::getDescriptorCount | ( | ) |
Gets number of descriptors in the gallery.
| int VisageSDK::VisageFaceRecognition::getDescriptorName | ( | char * | name, |
| int | index | ||
| ) |
Gets the name of a descriptor at the given index in the gallery.
| name | buffer into which the name of a descriptor is filled. |
| index | index of descriptor in the gallery. |
| int VisageSDK::VisageFaceRecognition::getDescriptorSize | ( | ) |
Gets the descriptor's size.
The function returns size of an array which should be allocated for storing the descriptor.
| int VisageSDK::VisageFaceRecognition::loadGallery | ( | const char * | file_name | ) |
Load gallery from a binary file.
The entries from the loaded gallery are appended to the current gallery. If it is required to replace existing gallery with the loaded one, call resetGallery() first.
| file_name | name of the file (including path if needed) from which the gallery will be loaded. |
| int VisageSDK::VisageFaceRecognition::recognize | ( | short * | descriptor, |
| int | n, | ||
| const char ** | names, | ||
| float * | similarities | ||
| ) |
Compare a face to all faces in the current gallery and return n names of the most similar faces.
| descriptor | pointer to the face descriptor of the face to be recognized (compared to the gallery). |
| n | number of names and similarities to be returned. |
| names | pointer to an array of char arrays. In this array the function will return names of n faces from the gallery that are most similar to the input image ascending by similarity. |
| similarities | pointer to an array of n floats. The function will return the similarity values for the n most similar faces in this array, corresponding to the names array. The values are sorted, with the largest similarity value first. |
| int VisageSDK::VisageFaceRecognition::removeDescriptor | ( | int | index | ) |
Removes a descriptor at the given index from the gallery.
The remaining descriptors in the gallery above the given index (if any) are shifted down in the gallery array by one place, filling the gap created by removing the descriptor.
| index | index of descriptor in the gallery. |
| int VisageSDK::VisageFaceRecognition::replaceDescriptorName | ( | const char * | name, |
| int | index | ||
| ) |
Replaces the name of a descriptor at the given index in the gallery with new name.
| name | new descriptor name. |
| index | index of descriptor in the gallery. |
| int VisageSDK::VisageFaceRecognition::saveGallery | ( | const char * | file_name | ) |
Save gallery as a binary file.
| file_name | name of the file (including path if needed) into which the gallery will be saved |
| bool VisageSDK::VisageFaceRecognition::is_initialized |
If the model used in the VisageFaceRecognition is loaded and initialized successfully value of the is_initialized variable is true, otherwise it is false.
Make sure the variable is set to true after instantiation and before using other function of VisageFaceRecognition API. An example of use:
Definition at line 113 of file VisageFaceRecognition.h.
1.8.17