Luxand FaceSDK v8.3 Developer's Guide

Multi-Core Support

The following FaceSDK functions use multiple CPU cores, thus speeding up the calculations:

FSDK_DetectEyes
FSDK_DetectEyesInRegion
FSDK_DetectFace
FSDK_DetectMultipleFaces
FSDK_DetectFacialFeatures
FSDK_DetectFacialFeaturesInRegion
FSDK_GetFaceTemplate
FSDK_GetFaceTemplateInRegion
FSDK_GetFaceTemplateUsingFeatures
FSDK_GetFaceTemplateUsingEyes
FSDK_FeedFrame
FSDK_TrackerMatchFaces

By default, these functions use all available processor cores. To get the number of processor cores used, call the FSDK_GetNumThreads function. To limit the number of processor cores used, call the FSDK_SetNumThreads function. Calling FSDK_SetNumThreads(1) will disable multi-core support.

Note that each of these functions forks into a number of threads on each call. It is not recommended to use nested parallelism when calling these functions; if you need nested parallelism, you may limit the number of threads with the FSDK_SetNumThreads function. For example, if your application runs in several threads, and each thread executes FSDK_DetectFace (which uses all available cores), this is acceptable; however, if each thread forks into several threads, each executing FSDK_DetectFace, this could potentially reach the limit of resources available.

It is safe to use extensions for parallel computation (like OpenMP) with the above FaceSDK functions, if they are executed from a single thread. For example, the following C++ sample code is acceptable:

#pragma omp parallel for
for (int i = 0; i < 100; i++)
    FSDK_DetectFace(...);

However, if your application forks into multiple threads, it is not recommended to execute the above FaceSDK functions within OpenMP statements in such threads. If you must, consider limiting the number of cores used by FaceSDK with the FSDK_SetNumThreads function.


FSDK_GetNumThreads Function

Retrieves the number of processor cores used by FaceSDK.

C++ Syntax:

int FSDK_GetNumThreads(int * Num);

Delphi Syntax:

function FSDK_GetNumThreads(Num: PInteger): integer;

C# Syntax:

int FSDK.GetNumThreads(ref int Num);

Java and Android Syntax:

int FSDK.GetNumThreads(int Num[]);

Parameters:

Num is the pointer to an integer value to receive the number of threads used by FaceSDK.

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.GetNumThreads() -> int

Return Value:

The number of processor cores used by FaceSDK.


FSDK_SetNumThreads Function

Sets the number of processor cores to be used by FaceSDK. If you set the number of cores to 1, support for multiple cores will be disabled, and the SDK will use only a single processor core.

C++ Syntax:

int FSDK_SetNumThreads(int Num);

Delphi Syntax:

function FSDK_SetNumThreads(Num: integer): integer;

C# Syntax:

int FSDK.SetNumThreads(int Num);

Java and Android Syntax:

int FSDK.SetNumThreads(int Num);

Parameters:

Num - the number of cores to be used by FaceSDK.

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.SetNumThreads(num: int)

Return Value:

None.


Performance Optimization Guide

Optimizing for High-Throughput Scenarios

When processing large numbers of images or video streams, consider these strategies to maximize throughput:

Thread configuration for batch processing (C++, OpenMP):

// For batch image processing across multiple threads:
// Limit FaceSDK to 1-2 cores per call to allow parallel processing
int totalCores;
FSDK_GetNumThreads(&totalCores);

// Use half the cores for FaceSDK, leaving the rest for your application threads
FSDK_SetNumThreads(totalCores / 2);

// Now process images in parallel using your own thread pool
#pragma omp parallel for
for (int i = 0; i < imageCount; i++) {
    HImage img;
    FSDK_LoadImageFromFile(&img, filenames[i]);
    FSDK_FaceTemplate tmpl;
    int err = FSDK_GetFaceTemplate(img, &tmpl);
    if (err == FSDKE_OK) {
        // Store template...
    }
    FSDK_FreeImage(img);
}

Tuning Face Detection for Different Scenarios

Use FSDK_SetFaceDetectionParameters to optimize detection for your specific use case:

Webcam / real-time detection (prioritize speed):

// Fast detection for real-time video at close range
FSDK_SetFaceDetectionParameters(false, false, 128);
FSDK_SetNumThreads(1);  // Single-threaded for lowest latency per frame

High-resolution photo processing (prioritize accuracy):

// Thorough detection for high-res images
FSDK_SetFaceDetectionParameters(true, true, 512);
// Use all available cores for maximum throughput
int numCores;
FSDK_GetNumThreads(&numCores);
FSDK_SetNumThreads(numCores);

Thermal / infrared camera images:

// Thermal cameras produce lower-contrast images
// Use lower detection threshold and higher resolution
FSDK_SetFaceDetectionParameters(false, false, 384);
FSDK_SetFaceDetectionThreshold(3);  // Lower threshold for low-contrast images

Performance Tips

  • Single-threaded per call is faster for real-time video — set FSDK_SetNumThreads(1) when processing one frame at a time, as thread overhead can exceed the parallelism benefit for a single operation.
  • Multi-threaded is faster for batch processing — use all cores when processing many images in a single FaceSDK call or when each call processes a large image.
  • Reduce InternalResizeWidth for speed — lower values (e.g., 128) detect faces faster but may miss faces that are small relative to the image. Use higher values (e.g., 512) only when detecting distant or small faces.
  • Free images promptly — call FSDK_FreeImage as soon as processing is complete to keep memory usage low during batch operations.
  • Avoid nested parallelism — do not use OpenMP or other parallelism inside threads that already call multi-core FaceSDK functions. Instead, limit FaceSDK threads with FSDK_SetNumThreads and manage parallelism at the application level.