Use the Jetson eSDK

Use the C API provided by the eSDK by including the eArgusKit.h header file into your C files. The following code example shows how to do this and includes 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_Normal, &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)
{
   EARPersonStoreRef pStore = EARPersonStoreCreate(<path to the store file>, <store file password>);
   EARFaceRecognizerRef pRecognizer = EARFaceRecognizerCreate(pLicense, pStore, kEARFaceRecognitionModelType_Regular, kEARFaceRecognitionModelPerformance_SpeedOptimized, 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.

Optimize Models Before First Run

TensorRT needs to run model optimization for each specific device the model runs on. This task is CPU- and GPU-intensive so it can take around 5 minutes per model on low power ARM CPUs that the Jetson has.

For a better user experience it is advisable to run the included model_optimizer tool located in the [SDK_ROOT]/bin/aarch64-linux-gnu/ directory before the first run of your application. The tool should be run with exactly one parameter, which is simply the directory containing the models in the .uff format, by default in [SDK_ROOT]/model/.

If this tool is not run the models will still be optimized on the first run of your application however this will significantly delay application startup.

These optimized models are then cached in the same model directory and will be reused in subsequent runs.

See Also