Use the C API provided with the SDK by including the eArgusKit.h
header file into your C files. The following code example shows how to do this, and includes the basic steps for setting up and using a face detector and face recognizer:
#include "eArgusKit.h"
// Detects as many faces as possible in the image 'pBitmap'.
// \param pLicense the SDK license
// \param pBitmap the image description
void detect_faces(const EARLicense* pLicense, const EARBitmap* pBitmap)
{
EARFaceDetectionInitializationConfiguration initConfig;
EARFaceDetectorRef pDetector = EARFaceDetectorCreate(pLicense, kEARFaceDetectionType_MtcnnNormal, &initConfig, 0);
EARFaceDetectionConfiguration config;
EARDetectedFaceArrayRef pFaces;
EARFaceDetectionConfigurationInitWithPreset(&config, kEARFaceDetectionConfigurationPreset_Generic);
pFaces = EARFaceDetectorDetect(pDetector, pBitmap, &config);
for (size_t i = 0; i < EARDetectedFaceArrayGetCount(pFaces); i++) {
const EARDetectedFace* pFace = EARDetectedFaceArrayGetAtIndex(pFaces, i);
// Process the face data
...
}
EARDetectedFaceArrayDestroy(pFaces);
EARFaceDetectorDestroy(pDetector);
}
// Recognizes as many faces as possible out of the set of detected faces
// 'pDetectedFaces'. Expects that the the faces were previously detected in the
// image 'pBitmap'.
// \param pLicense the SDK license
// \param pBitmap the image description
// \param pDetectedFaces the previously detected faces
void recognize_faces(const EARLicense* pLicense, const EARBitmap* pBitmap, EARDetectedFaceArrayRef pDetectedFaces)
{
EARFaceRecognitionModelType FRModel = kEARFaceRecognitionModelType_Regular;
EARRecognitionModelPerformance qType = kEARFaceRecognitionModelPerformance_SpeedOptimized;
EARPersonStoreRef pStore = EARPersonStoreCreate(<path to the store file>, <store file password>);
EARFaceRecognizerRef pRecognizer = EARFaceRecognizerCreate(pLicense, pStore, FRModel, qType, 0);
EARFaceRecognitionConfiguration config;
EARRecognizedFaceArrayRef pFaces;
EARFaceRecognitionConfigurationInitWithPreset(&config, kEARFaceRecognitionConfigurationPreset_Recognize);
pFaces = EARFaceRecognizerRecognizeDetectedFaces(pRecognizer, pDetectedFaces, pBitmap, &config, kEARAllowRecognition);
for (size_t i = 0; i < EARRecognizedFaceArrayGetCount(pFaces); i++) {
const EARRecognizedFace* pFace = EARRecognizedFaceArrayGetAtIndex(pFaces, i);
// Process the face data
...
}
EARRecognizedFaceArrayDestroy(pFaces);
EARFaceRecognizerDestroy(pRecognizer);
EARPersonStoreDestroy(pStore);
}
Note: This sample code does not check for errors. As you should always check for errors in your code, use the EARGetLastError()
function to get the most recent error.
Your code should create the face detector, face recognizer, and person store objects once and reuse them. Do not recreate these objects for every single detection and recognition operation.