Luxand FaceSDK – Gender and Expression Recognition

The SDK recognizes the gender of faces and their expressions. It recognizes if a smile is present and if the eyes are open or closed. To accomplish this, first you must to detect facial features in an image, and then pass these features to the FSDK_DetectFacialAttributeUsingFeatures function, specifying the "Gender" or the "Expression" attribute.

  FSDK_DetectFacialAttributeUsingFeatures Function

Detects an attribute of a face, and returns the Values of a particular attribute, and Confidences in these Values.

Each facial attribute has a number of Values, and each Value has an associated Confidence. A Value is a string, and a Confidence is a float from 0 to 1, which represents confidence level of this particular value of the attribute.

The following attribute names are supported:

"Gender" – to detect the gender of a face. The attribute has "Male" and "Female" values.

"Expression" – to detect the expression of a face. The attribute has "Smile" and "EyesOpen" values.

The Values and their Confidences are returned in a string of the following format:

"Value1=Confidence1[;Value2=Confidence2[;…]]"

For example, when calling the function with the "Gender" attribute, the following string may be returned:

"Male=0.95721;Female=0.04279"

It means that the subject has male gender with a confidence of 95.7%, and female gender with a confidence of 4.3%.

When calling the function with the "Expression" attribute, the following string may be returned:

"Smile=0.987;EyesOpen=0.9952"

It means that the subject smiles with a confidence of 98.7%, and the eyes are open with a confidence of 99.5%.

You may use several attributes in a single function call separated by ";". For example, if AttributeName is "Gender; Expression", the result may be the following: "Male=0.95721;Female=0.04279;Smile=0.987;EyesOpen=0.9952".

You may use the FSDK_GetValueConfidence to parse the returned string and retrieve the Confidences for individual Values.

C++ Syntax:

int FSDK_DetectFacialAttributeUsingFeatures(HImage Image, const FSDK_Features * FacialFeatures, const char * AttributeName, char * AttributeValues, long long MaxSizeInBytes);

Delphi Syntax:

function FSDK_DetectFacialAttributeUsingFeatures(Image: HImage; FacialFeatures: PFSDK_Features; AttributeName, AttributeValues: PAnsiChar; MaxSizeInBytes: int64): integer;

C# Syntax:

int DetectFacialAttributeUsingFeatures(int Image, ref TPoint [] FacialFeatures, string AttributeName, out string AttributeValues, long MaxSizeInBytes);

VB Syntax:

Function FSDKVB_DetectFacialAttributeUsingFeatures(ByVal Image As Long, ByRef FacialFeatures As TPoint, ByVal AttributeName As String, ByRef AttributeValues As String, ByVal MaxSizeInBytes As Currency) As Long

Java and Android Syntax:

int FSDK.DetectFacialAttributeUsingFeatures(int Image, FSDK_Features FacialFeatures, String AttributeName, String AttributeValues[], long MaxSizeInBytes);

Parameters:

Image – HImage handle in which to detect the attribute.

FacialFeatures – pointer to the FSDK_Features array containing facial feature coordinates.

AttributeName – name of the attribute. You may specify several attributes separated by ";".

AttributeValues – pointer to the null-terminated string that will receive the attribute Values and their Confidences.

MaxSizeInBytes – amount of memory allocated for the output string.

Return Value:

Returns FSDKE_OK if successful. Returns FSDKE_INSUFFICIENT_BUFFER_SIZE if there is not enough room to store the output string; however, the output string still fills up all the space available.

  FSDK_GetValueConfidence Function

Parses the string returned by FSDK_DetectFacialAttributeUsingFeatures or FSDK_GetTrackerFacialAttribute, and returns the Confidence in an individual Value.

C++ Syntax:

int FSDK_GetValueConfidence(const char * AttributeValues, const char * Value, float * Confidence);

Delphi Syntax:

function FSDK_GetValueConfidence(AttributeValues, Value: PAnsiChar; Confidence: PSingle): integer;

C# Syntax:

int GetValueConfidence(string AttributeValues, string Value, ref float Confidence);

VB Syntax:

Function FSDKVB_GetValueConfidence(ByVal AttributeValues As String, ByVal Value As String, ByRef Confidence As Single) As Long

Java and Android Syntax:

int FSDK_GetValueConfidence(String AttributeValues, String Value, float Confidence[]);

Parameters:

AttributeValues – pointer to the null-terminated string containing the attribute Values and their Confidences.

Value – pointer to the null-terminated string containing the desired Value.

Confidence – pointer to the float variable to store the Confidence in a Value.

Return Value:

Returns FSDKE_OK if successful.

Example

char AttributeValues[1024];
FSDK_DetectFacialAttributeUsingFeatures(image, features, "Gender", AttributeValues, sizeof(AttributeValues));
float ConfidenceMale = 0.0f;
float ConfidenceFemale = 0.0f;
FSDK_GetValueConfidence(AttributeValues, "Male", &ConfidenceMale);
FSDK_GetValueConfidence(AttributeValues, "Female", &ConfidenceFemale);

 

Next chapterWorking with Cameras

Contents