Luxand FaceSDK – Facial Feature Detection
FaceSDK provides the FSDK_DetectFacialFeatures function to detect facial features in an image and the FSDK_DetectEyes function to detect just eye centers in an image. First, these functions detect a frontal face in an image, and then detect its facial features or only eye centers. The FSDK_DetectFacialFeaturesInRegion and FSDK_DetectEyesInRegion functions do not perform the face detection step and detect facial features or eye centers in a region returned by FSDK_DetectFace or FSDK_DetectMultipleFaces.
In the current version of Luxand FaceSDK the performance of FSDK_DetectEyes and FSDK_DetectFacialFeatures is the same, so there is no advantage in calling FSDK_DetectEyes instead of FSDK_DetectFacialFeatures.
The facial features are stored in the FSDK_Features data structure. FSDK_Features is an array data type containing FSDK_FACIAL_FEATURE_COUNT points. The list of facial features recognized by FaceSDK is available in the Detected Facial Features chapter.
Eye centers are saved to FSDK_Features[0] and FSDK_Features[1]. The FSDK_DetectEyes and FSDK_DetectEyesInRegion functions do not change other elements of the FSDK_Features array.
C++ Declaration:
typedef struct { int x,y; } TPoint;
typedef TPoint FSDK_Features [FSDK_FACIAL_FEATURE_COUNT];
C# Declaration:
public struct TPoint {
public int x, y;
}
Delphi Declaration:
TPoint = record
x, y: integer;
end;
FSDK_Features = array[0..FSDK_FACIAL_FEATURE_COUNT - 1] of TPoint;
PFSDK_Features = ^FSDK_Features;
VB Declaration:
Type TPoint
x As Long
y As Long
End Type
Java and Android Declaration:
The class TPoint has the following properties:
public int x, y;
The class FSDK_Features has the following property:
public TPoint features[];
Python Syntax:
class Point(ctypes.Structure):
fields_ = ("x", c_int), ("y", c_int)
Features = Point*FSDK.FSDK_FACIAL_FEATURE_COUNT
FSDK_DetectFacialFeatures Function
Detects a frontal face in an image and detects its facial features.
C++ Syntax:
int FSDK_DetectFacialFeatures(HImage Image, FSDK_Features* FacialFeatures);
Delphi Syntax:
function FSDK_DetectFacialFeatures(Image: HImage; FacialFeatures: PFSDK_Features): integer;
C# Syntax:
int FSDK.DetectFacialFeatures(int Image, out FSDK.TPoint[] FacialFeatures);
VB Syntax:
Function FSDKVB_DetectFacialFeatures(ByVal Image As Long, ByRef FacialFeatures As TPoint) As Long
Java Syntax:
int FSDK.DetectFacialFeatures(HImage Image, FSDK_Features.ByReference FacialFeatures);
Android Syntax:
int FSDK.DetectFacialFeatures(HImage Image, FSDK_Features FacialFeatures);
CImage Syntax:
FSDK.TPoint[] FSDK.CImage.DetectFacialFeatures();
Parameters:
Image - handle of the image facial features should be detected in.
FacialFeatures – pointer to the FSDK_Features array for receiving the detected facial features.
Return Value:
Returns FSDKE_OK if successful.
Example
int img1;
FSDK_Features Features;
FSDK_Initialize("");
FSDK_LoadImageFromFile(&img1, "test.jpg");
FSDK_DetectFacialFeatures(img1, Features);
printf("Left eye location: (%d, %d)\n", Features[FSDKP_LEFT_EYE].x, Features[FSDKP_LEFT_EYE].y);
printf("Right eye location: (%d, %d)\n", Features[FSDKP_RIGHT_EYE].y, Features[FSDKP_RIGHT_EYE].y);
Python Syntax:
def FSDK.DetectFacialFeatures(image: Image) -> Features;
def Image.DetectFacialFeatures(image: Image, facePosition: FacePosition = None, *, confidenceLevels = False) -> Features;
Return Value:
The Features object.
Exception:
FSDK.FaceNotFound
Note:
If facePosition is None the function detects a frontal face in an image and returns its facial features
If facePosition is defined the function detects facial features of a specific face in a region returned by FSDK.DetectFace or FSDK.DetectMultipleFace.
If confidenceLevel is True the returned 'Features' objects contains the confidenceLevel attribute represented by an array of floats that holds confidence levels of each facial feature.
Example
from fsdk import FSDK
FSDK.Initialize()
features = FSDK.Image("test.jpg").DetectFacialFeatures()
print(f”Left eye location: {features[FSDK.FSDKP_LEFT_EYE]}”)
print(f”Right eye location: {features[FSDK.FSDKP_RIGHT_EYE]}”)
Return Value:
The new resized image.
FSDK_DetectFacialFeaturesInRegion Function
Detects facial features in an image region returned by FSDK_DetectFace or FSDK_DetectMultipleFaces. This function can be useful if an approximate face size is known, or to detect facial features of a specific face returned by FSDK_DetectMultipleFaces.
C++ Syntax:
int FSDK_DetectFacialFeaturesInRegion(HImage Image, TFacePosition* FacePosition, FSDK_Features* FacialFeatures);
Delphi Syntax:
function FSDK_DetectFacialFeaturesInRegion(Image: HImage; FacePosition: PFacePosition; FacialFeatures: PFSDK_Features): integer;
C# Syntax:
int FSDK.DetectFacialFeaturesInRegion(int Image, ref FSDK.TFacePosition FacePosition, out FSDK.TPoint[] FacialFeatures);
VB Syntax:
Function FSDKVB_DetectFacialFeaturesInRegion(ByVal Image As Long, ByRef FacePosition As TFacePosition, ByRef FacialFeatures As TPoint) As Long
Java Syntax:
int FSDK.DetectFacialFeaturesInRegion(HImage Image, TFacePosition FacePosition, FSDK_Features.ByReference FacialFeatures);
Android Syntax:
int FSDK.DetectFacialFeaturesInRegion(HImage Image, TFacePosition FacePosition, FSDK_Features FacialFeatures);
CImage Syntax:
FSDK.TPoint[] FSDK.CImage.DetectFacialFeaturesInRegion(ref FSDK.TFacePosition FacePosition);
Parameters:
Image– handle of the image facial features should be detected in.
FacePosition– pointer to the face position structure.
FacialFeatures– pointer to the FSDK_Features array for receiving the detected facial features.
Return Value:
Returns FSDKE_OK if successful.
Example
int i, DetectedCount, img1;
FSDK_Features Features;
TFacePosition FaceArray[50];
FSDK_Initialize("");
FSDK_LoadImageFromFile(&img1, "test.jpg");
FSDK_DetectMultipleFaces(img1, &DetectedCount , FaceArray, sizeof(FaceArray));
for (i = 0; i < DetectedCount; i++) {
FSDK_DetectFacialFeaturesInRegion(img1, FaceArray[i], Features);
printf("Left eye location: (%d, %d)\n", Features[FSDKP_LEFT_EYE].x, Features[FSDKP_LEFT_EYE].y);
printf("Right eye location: (%d, %d)\n", Features[FSDKP_RIGHT_EYE].x, Features[FSDKP_RIGHT_EYE].y);
}
Python Syntax:
def FSDK.DetectFacialFeaturesInRegion(image: Image, facePosition: FacePosition) -> Features;
def Image.DetectFacialFeatures(image: Image, facePosition: FacePosition = None, *, confidenceLevels = False) -> Features;
Return Value:
The Features objects.
Example:
from fsdk import FSDK
FSDK.Initialize()
image = FSDK.Image("test.jpg")
for fpos in image.DetectMultipleFaces():
features = image.DetectFacialFeatures(image, fpos, confidenceLevel = True)
print(”Left eye location:”, features[FSDK.FSDKP_LEFT_EYE], “confidence =”, features.confidenceLevels[FSDK.FSDKP_LEFT_EYE])
print(”Right eye location:”, features[FSDK.FSDKP_RIGHT_EYE], “confidence =”, features.confidenceLevels[FSDK.FSDKP_RIGHT_EYE])
FSDK_DetectEyes Function
Detects a frontal face in an image and detects its eye centers.
C++ Syntax:
int FSDK_DetectEyes(HImage Image, FSDK_Features* FacialFeatures);
Delphi Syntax:
function FSDK_DetectEyes(Image: HImage; FacialFeatures: PFSDK_Features): integer;
C# Syntax:
int FSDK.DetectEyes(int Image, out FSDK.TPoint[] FacialFeatures);
VB Syntax:
Function FSDKVB_DetectEyes (ByVal Image As Long, ByRef FacialFeatures As TPoint) As Long
Java Syntax:
int FSDK.DetectEyes(HImage Image, FSDK_Features.ByReference FacialFeatures);
Android Syntax:
int FSDK.DetectEyes(HImage Image, FSDK_Features FacialFeatures);
CImage Syntax:
FSDK.TPoint[] FSDK.CImage.DetectEyes();
Parameters:
Image– handle of the image eye centers should be detected in.
FacialFeatures– pointer to the FSDK_Features array for receiving the detected eye centers.
Return Value:
Returns FSDKE_OK if successful.
Python Syntax:
class Eyes(Point*2):
""" An array of two 2D coordinates for eyes """
def FSDK.DetectEyes(image: Image) -> Eyes:
def Image.DetectEyes(facePosition: FacePosition = None) -> Eyes;
Return Value:
The Eyes object.
FSDK_DetectEyesInRegion Function
Detects eye centers in an image region returned by FSDK_DetectFace or FSDK_DetectMultipleFaces.
C++ Syntax:
int FSDK_DetectEyesInRegion(HImage Image, TFacePosition* FacePosition, FSDK_Features* FacialFeatures);
Delphi Syntax:
function FSDK_DetectEyesInRegion(Image: HImage; FacePosition: PFacePosition; FacialFeatures: PFSDK_Features): integer;
C# Syntax:
int FSDK.DetectEyesInRegion(int Image, ref FSDK.TFacePosition FacePosition, out FSDK.TPoint[] FacialFeatures);
VB Syntax:
Function FSDKVB_DetectEyesInRegion(ByVal Image As Long, ByRef FacePosition As TFacePosition, ByRef FacialFeatures As TPoint) As Long
Java Syntax:
int FSDK.DetectEyesInRegion(HImage Image, TFacePosition FacePosition, FSDK_Features.ByReference FacialFeatures);
Android Syntax:
int FSDK.DetectEyesInRegion(HImage Image, TFacePosition FacePosition, FSDK_Features FacialFeatures);
CImage Syntax:
FSDK.TPoint[] FSDK.CImage.DetectEyesInRegion(ref FSDK.TFacePosition FacePosition);
Parameters:
Image – handle of the image eye centers should be detected in.
FacePosition – pointer to the face position structure.
FacialFeatures – pointer to the FSDK_Features array for receiving the detected eye centers.
Return Value:
Returns FSDKE_OK if successful.
Python Syntax:
def FSDK.DetectEyesInRegion(image: Image, facePosition: FacePosition) -> Eyes:
def Image.DetectEyes(facePosition: FacePosition = None) -> Eyes;
Return Value:
The Eyes object.