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);

  Face Detection Models

Luxand FaceSDK allows you to switch the internal models used for face detection. You may use the switching to load improved face detection models when made available by Luxand or to switch to a thermal face detection model.

Use the FSDK_SetParameter or FSDK_SetParameters function to load a face detection model from a file. When using Tracker API, use the FSDK_SetTrackerParameter or FSDK_SetTrackerMultipleParameters function instead. Set the FaceDetectionModel parameter to specify the file to load a model from. Be sure to check the return value of FSDK_SetParameter or FSDK_SetParameters to confirm the file loaded correctly.

To load a thermal face detection model, set FaceDetectionModel to thermal.bin. Confirm this file is available in the current directory and, if not, specify the full path to the file.

To switch back to the default model (i.e., the model for visual face detection), set FaceDetectionModel to default. See the FaceSDK Parameters section for more information.

  Face Detection on Thermal Images

Luxand FaceSDK allows for the detection of faces on 8-bit grayscale thermal images. You typically receive such images from a thermal camera, with each pixel representing temperature.

To pass the thermal image to FaceSDK, you may need to convert the temperature values of the image (which may be float or 14-bit values, for example) into 8-bit values (from 0 to 255). The absolute temperature itself is not taken into account by FaceSDK when detecting faces, only the relative difference in temperature between facial features and the background.

Typically, you may normalize an image so thate coldest pixel is represented by 0 and the hottest by 255. However, if you have very hot or very cold images in the background, this may lead to faces having a low contrast. Therefore, it is recommended to normalize the image so that 0 would represent the temperature of about 20 degrees Celsius and 255 the temperature of about 40 degrees Celsius (the usual range of temperatures for human faces). After this normalization, any pixels colder than 20 degrees Celsius will have the value 0, and any pixels hotter than 40 degrees Celsius will have the value of 255.

If your thermal camera returns a noisy picture, you may get lower detection rates. In such cases, it is recommended to de-noise the image with a median or a Gaussian filter before passing it to FaceSDK. More information can be found on the links below:
https://en.wikipedia.org/wiki/Median_filter
https://en.wikipedia.org/wiki/Gaussian_blur

Try varying the face detection threshold if you get a high number of false positives or low detection rates on your camera.

FaceSDK itself does not communicate with thermal cameras except when the camera is available as a standard Windows web camera. When working with a thermal camera, you need to use the camera manufacturer’s API to receive images. To pass thermal images to FaceSDK, you may use the FSDK_LoadImageFromBuffer function after converting the images to an 8-bit format (and possibly normalizing the pixel values, as described above).

To detect faces on thermal images, follow these steps:

  • Load a face detection model by setting the FaceDetectionModel with the FSDK_SetParameter or FSDK_SetParameters function. If using Tracker API, use the FSDK_SetTrackerParameter or FSDK_SetTrackerMultipleParameters function instead.
  • Check the return value of the above functions for error to be sure the thermal model was loaded.
  • Set the TrimOutOfScreenFaces and TrimFacesWithUncertainFacialFeatures parameters to False using the same functions.
  • Pass thermal images to FSDK_DetectFaces, FSDK_DetectMultipleFaces or FSDK_FeedFrame (when using Tracker API).

Example:

FSDK_SetParameters("FaceDetectionModel=thermal.bin; TrimOutOfScreenFaces=false; TrimFacesWithUncertainFacialFeatures=false", &err);

Refer to the Thermal sample application to see how faces on thermal images can be detected.

  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.

Other face detection parameters that can also be set using the FSDK_SetParameter or FSDK_SetParameters function.

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

Get in touch

Luxand, Inc.
815 N. Royal St. Suite 202
Alexandria, VA
22314
USA
Freephone:
+1 800 471 5636

Join our newsletter

And always stay informed of the latest company news and events!

Sign up >>

DMCA.com Protection Status