Luxand FaceSDK – Face Detection

You can use the FSDK_DetectFace function to detect a frontal face in an image. The function returns the position of the face in the image. The performance and reliability of face detection is controlled by the FSDK_SetFaceDetectionParameters and FSDK_SetFaceDetectionThreshold functions.

Typical parameters for face detection are:

·        To detect faces from a webcam in real time, call:

FSDK_SetFaceDetectionParameters(false, false, 100);

·        To reliably detect faces in digital camera photos, call

FSDK_SetFaceDetectionParameters(true, false, 500);

  Data types

Luxand FaceSDK introduces the TFacePosition data type that stores the information about the position of the face. The xc and yc fields specifies the X and Y coordinates of the center of the face, w specifies the width of the face, and angle specifies the in-plane rotation angle of the face in degrees.

C++ Declaration:

typedef struct {
    int xc, yc, w;
    int padding;
    double angle;
} TFacePosition;

C# Declaration:

public struct TFacePosition {
    public int xc, yc, w;
    public double angle;
}

Delphi Declaration:

TFacePosition = record
   xc, yc, w: integer;
   padding: integer;
   angle: double;
end;
PFacePosition = ^TFacePosition;

VB Declaration:

Type TFacePosition
   xc As Long
   yc As Long
   w As Long
   padding As Long
   angle As Double
End Type

Java Declaration:

The class TFacePosition contains the following fields:

   public int xc, yc, w;
   public double angle;

The class TFaces encapsulates an array of TFacePosition classses. It has the following properties:

   public TFacePosition faces[];
   int maxFaces;

  FSDK_DetectFace Function

Detects a frontal face in an image and stores information about the face position into the TFacePosition structure.

C++ Syntax:

int FSDK_DetectFace(HImage Image, TFacePosition* FacePosition);

Delphi Syntax:

function FSDK_DetectFace(Image: HImage; FacePosition: PFacePosition): integer;

C# Syntax:

int FSDK.DetectFace(int Image, ref FSDK.TFacePosition FacePosition);

VB Syntax:

Function FSDKVB_DetectFace(ByVal Image As Long, ByRef FacePosition As TFacePosition) As Long

Java Syntax:

int FSDK.DetectFace(HImage Image, TFacePosition.ByReference FacePosition);

Android Syntax:

int FSDK.DetectFace(HImage Image, TFacePosition FacePosition);

CImage Syntax:

FSDK.TFacePosition FSDK.CImage.DetectFace();

Parameters:

Image – handle of the image to detect the face in.

FacePosition – pointer to the TFacePosition structure to store information about the face position.

Return Value:

Returns FSDKE_OK if successful. If a face is not found, the function returns the FSDKE_FACE_NOT_FOUND code. If the input image is too small (less than 20x20 pixels), the functions returns FSDKE_IMAGE_TOO_SMALL.

Example

int img1;
TFacePosition FacePosition;

FSDK_Initialize("");
FSDK_LoadImageFromFile(&img1, "test.jpg");
FSDK_DetectFace(img1, &FacePosition);

printf("face position: %d %d %d", FacePosition.xc, FacePosition.yc, FacePosition.angle);

  FSDK_DetectMultipleFaces Function

Detects multiple faces in an image.

C++ Syntax:

int FSDK_DetectMultipleFaces(HImage Image, int* DetectedCount, TFacePosition* FaceArray, int MaxSizeInBytes);

Delphi Syntax:

function FSDK_DetectMultipleFaces(Image: HImage; DetectedCount: PInteger; FaceArray: PFacePositionArray; MaxSizeInBytes: integer): integer;

C# Syntax:

int FSDK.DetectMultipleFaces(int Image, ref int DetectedCount, out FSDK.TFacePosition[] FaceArray, int MaxSizeInBytes);

VB Syntax:

Function FSDKVB_DetectMultipleFaces(ByVal Image As Long, ByRef DetectedCount As Long, ByRef FaceArray As TFacePosition, ByVal MaxSizeInBytes As Long) As Long

Java and Android Syntax:

int FSDK.DetectMultipleFaces(HImage Image, TFaces FaceArray);

CImage Syntax:

FSDK.TFacePosition[] FSDK.CImage.DetectMultipleFaces();

Parameters:

Image – handle of the image to detect faces in.

DetectedCount – count of the faces found in the image.

FaceArray – pointer to the array of TFacePosition structure to store the information about the detected faces.

MaxSizeInBytes – size of the FaceArray buffer in bytes. The function will not store more than MaxSize bytes in the buffer.

Return Value:

Returns FSDKE_OK if successful. If no faces are found, the function returns the FSDKE_FACE_NOT_FOUND code. If the input image is too small (less than 20x20 pixels), the functions returns FSDKE_IMAGE_TOO_SMALL.

Example

int img1;
int DetectedCount;
TFacePosition FaceArray[50];

FSDK_Initialize("");
FSDK_LoadImageFromFile(&img1, "test.jpg");
FSDK_DetectMultipleFaces(img1, &DetectedCount , FaceArray, sizeof(FaceArray));

for (i = 0; i < DetectedCount; i++) {
printf("face position: %d %d %d\n", FaceArray[i].xc, FaceArray[i].yc, FaceArray[i].angle);
}

  FSDK_SetFaceDetectionParameters Function

Allows setting a number of face detection parameters to control the performance and reliability of face detector.

The function allows configuring the following parameters: HandleArbitraryRotations, DetermineFaceRotationAngle and InternalResizeWidth.

HandleArbitraryRotations, DetermineFaceRotationAngle can be TRUE or FALSE, while InternalResizeWidth is an integer.

C++ Syntax:

int FSDK_SetFaceDetectionParameters(bool HandleArbitraryRotations, bool DetermineFaceRotationAngle, int InternalResizeWidth);

Delphi Syntax:

function FSDK_SetFaceDetectionParameters(HandleArbitraryRotations: boolean; DetermineFaceRotationAngle: boolean; InternalResizeWidth: integer): integer;

C# Syntax:

int FSDK.SetFaceDetectionParameters(bool HandleArbitraryRotations, bool DetermineFaceRotationAngle, int InternalResizeWidth);

VB Syntax:

Function FSDKVB_SetFaceDetectionParameters(ByVal HandleArbitraryRotations As Boolean, ByVal DetermineFaceRotationAngle As Boolean, ByVal InternalResizeWidth As Long) As Long

Java and Android Syntax:

int FSDK.SetFaceDetectionParameters(boolean HandleArbitraryRotations, boolean DetermineFaceRotationAngle, int InternalResizeWidth);

Parameters:

HandleArbitraryRotations – extends default in-plane face rotation angle from -15..15 degrees to -30..30 degrees.

TRUE: extended in-plane rotation support is enabled at the cost of detection speed (3 times performance hit).

FALSE: default fast detection -15..15 degrees.

DetermineFaceRotationAngle – enables or disables the detection of in-plane face rotation angle.

TRUE: detects in-plane rotation angle when detecting faces. The angle is recorded into the Angle field of the TFacePosition structure (TFacePosition is a structure returned by FSDK_DetectFace and FSDK_DetectMultipleFaces).

FALSE: disables the detection of rotation angle.

Note: Enabling face rotation angle detection slows down the detection process slightly. Set this parameter to TRUE if you are planning to call FSDK_DetectFacialFeatures or FSDK_DetectFacialFeaturesInRegion.

InternalResizeWidth– controls the detection speed by setting the size of the image the detection functions will work with. Choose higher value to increase detection quality, or lower value to improve the performance.

Note: By default, all images are internally resized to the width of 384 pixels. 384 pixels are a reasonable compromise between performance and detection quality. While large images are down-sized, the smaller ones are up-sized to the specified Resize Width in order to maintain constant detection speed.

Choosing the right value for InternalResizeWidth

Choosing the correct value for the InternalResizeWidth parameter is essential for the correct operation of face detection functions of the SDK. The face detection functions can only detect faces as small as 20x20 pixels. Even if the source image is a large 1000x1000 dots one, the face on that image can be as small as 100x100 pixels. If you set InternalResizeWidth to 200, then the source image will be resized to 200x200 pixels, thus the face will only occupy 20x20 pixels. This is still enough for the SDK functions to work. If, however, you set InternalResizeWidth to 100, then the original image will become 100x100 pixels, and the face on it will only occupy 10x10 dots, which is NOT enough for the SDK functions to work with.

Be extra careful when changing the default value of InternalResizeWidth. For example, webcam images can be usually detected with InternalResizeWidth set to 100, while images from multi-megapixel digital cameras require values of at least 384 or 512 pixels to work with.

Return Value:

Returns FSDKE_OK if successful.

  FSDK_SetFaceDetectionThreshold Function

Sets a threshold value for face detection. The default value is 5. The lowest possible value is 1.

The function allows adjusting the sensitivity of the detection. If the threshold value is set to a higher value, the detector will only recognize faces with sharp, clearly defined details, thus reducing the number of false positive detections. Setting the threshold lower allows detecting more faces with less clearly defined features at the expense of increased number of false positives.

C++ Syntax:

int FSDK_SetFaceDetectionThreshold(int Threshold);

Delphi Syntax:

function FSDK_SetFaceDetectionThreshold(Threshold: integer): integer;

C# Syntax:

int FSDK.SetFaceDetectionThreshold(int Threshold);

VB Syntax:

Function FSDKVB_SetFaceDetectionThreshold(ByVal Threshold As Long) As Long

Java and Android Syntax :

int FSDK.SetFaceDetectionThreshold(int Threshold);

Parameters:

Threshold– Threshold value.

Return Value:

Returns FSDKE_OK if successful.

 

Next chapterFacial Feature Detection

Contents