Face Recognition [F200]

Top  Previous  Next

The general concept of face recognition is to measure similarity between two faces, one from the current image, and the other one from some references in a recognition database. The measurement is performed on all references in the database. A user is considered recognized if the score of the most matched reference passes certain threshold, and the recognition result is simply the user identifier that is associated with the reference. Thus for any face recognition, the application must perform one or a combination of the following recognition database operations:

Create/Delete Database: Create a recognition database and release it after use. The RecognitionConfiguration interface supports creating multiple recognition databases. You can switch among them. The face recognition is done on the current active recognition database.

The algorithm creates a default active storage if none is defined.

Load/Save Database: You can save the database to the disk,  and load it later. The RecognitionModuleData interface provides member functions to export the recognition database, and the RecognitionConfiguration interface to import one. Save the database buffer to a file and load it from a file with proper security measurement to protect user privacy.
Register/Unregister Users: Register a user face to the database, using the RegisterUser function. The user becomes one of the references in the database. It is recommended to register multiple faces (in different poses) of the same user to the database to improve recognition robustness. You can unregister a user via the UnregisterUser function, if there is a better reference. Besides explicit registration, the RecognitionConfiguration interface also introduces a continuous registration mode where the recognition algorithm automatically determines if a user should be registered to the database, or not.
Recognize Current Face: Use the QueryUserID function to perform recognition of the current face against the active recognition database.

Configuring Face Recognition

To configure face recognition, use the RecognitionConfiguration interface, as shown in Example 50.

C++ Example 50: Configure Face Recognition

// cfg is a PXCFaceConfiguration instance

PXCFaceConfiguration::RecognitionConfiguration *rcfg=cfg->QueryRecognition();

 

// Enable face recognition

rcfg->Enable();

 

// Create a recognition database

PXCFaceConfiguration::RecognitionConfiguration::RecognitionStorageDesc desc={};

desc.maxUsers=10;

rcfg->CreateStorage(L"MyDB", &desc);

rcfg->UseStorage(L"MyDB");

 

// Set the registeration mode

rcfg->SetRegistrationMode(PXCFaceConfiguration::RecognitionConfiguration::REGISTRATION_MODE_CONTINUOUS);

 

// Make it effective

cfg->ApplyChanges();

C# Example 50: Configure Face Recognition

// cfg is a PXCMFaceConfiguration instance

PXCMFaceConfiguration.RecognitionConfiguration rcfg=cfg.QueryRecognition();

 

// Enable face recognition

rcfg.Enable();

 

// Create a recognition database

PXCMFaceConfiguration.RecognitionConfiguration.RecognitionStorageDesc desc=new PXCMFaceConfiguration.RecognitionConfiguration.RecognitionStorageDesc();

desc.maxUsers=10;

rcfg.CreateStorage("MyDB", desc);

rcfg.UseStorage("MyDB");

 

// Set the registeration mode

rcfg.SetRegistrationMode(PXCMFaceConfiguration.RecognitionConfiguration.RecognitionRegistrationMode.REGISTRATION_MODE_CONTINUOUS);

 

// Make it effective

cfg.ApplyChanges();

Java Example 50: Configure Face Recognition

// cfg is a PXCMFaceConfiguration instance

PXCMFaceConfiguration.RecognitionConfiguration rcfg=cfg.QueryRecognition();

 

// Enable face recognition

rcfg.Enable();

 

// Create a recognition database

PXCMFaceConfiguration.RecognitionConfiguration.RecognitionStorageDesc desc=new PXCMFaceConfiguration.RecognitionConfiguration.RecognitionStorageDesc();

desc.maxUsers=10;

rcfg.CreateStorage("MyDB", desc);

rcfg.UseStorage("MyDB");

 

// Set the registeration mode

rcfg.SetRegistrationMode(PXCMFaceConfiguration.RecognitionConfiguration.RecognitionRegistrationMode.REGISTRATION_MODE_CONTINUOUS);

 

// Make it effective

cfg.ApplyChanges();

Recognizing a Face

When you complete configuration, perform the remaining face recognition operations using the RecognitionData interface, as shown in Example 51.

C++ Example 51: Face Recognition Operation

// fdata is a PXCFaceData instance

pxcI32 nfaces=fdata->QueryNumberOfDetectedFaces();

for (pxcI32 i=0;i<nfaces;i++) {

   // Retrieve the recognition data instance

   PXCFaceData::Face *face=fdata->QueryFaceByIndex(i);

   PXCFaceData::RecognitionData *rdata=fdata->QueryRecognition();

 

   // recognize the current face?

   pxcI32 uid=rdata->QueryUserID();

   if (uid>=0) {

       // do something with the recognized user.

       ....

   }

}

C# Example 51: Face Recognition Operation

// fdata is a PXCMFaceData instance

Int32 nfaces=fdata.QueryNumberOfDetectedFaces();

for (Int32 i=0;i<nfaces;i++) {

   // Retrieve the recognition data instance

   PXCMFaceData.Face face=fdata.QueryFaceByIndex(i);

   PXCMFaceData.RecognitionData rdata=fdata.QueryRecognition();

 

   // recognize the current face?

   Int32 uid=rdata.QueryUserID();

   if (uid>=0) {

       // do something with the recognized user.

       ....

   }

}

Java Example 51: Face Recognition Operation

// fdata is a PXCMFaceData instance

int nfaces=fdata.QueryNumberOfDetectedFaces();

for (int i=0;i<nfaces;i++) {

   // Retrieve the recognition data instance

   PXCMFaceData.Face face=fdata.QueryFaceByIndex(i);

   PXCMFaceData.RecognitionData rdata=fdata.QueryRecognition();

 

   // recognize the current face?

   int uid=rdata.QueryUserID();

   if (uid>=0) {

       // do something with the recognized user.

       ....

   }

}

Loading/Saving Recognition Database

Example 52 illustrates how to load/save the recognition database.

C++ Example 52: Load/Save Face Recognition Database

// rdata is a PXCFaceData::RecognitionData instance

// rcfg is a PXCFaceConfiguration::RecognitionConfiguration instance

 

// allocate the buffer to save the database

PXCFaceData::RecognitionModuleData *rmd=rdata->QueryRecognitionModule();

pxcI32 nbytes=rmd->QueryDatabaseSize();

pxcBYTE *buffer=new pxcBYTE[nbytes];

 

// retrieve the database buffer

rmd->QueryDatabaseBuffer(buffer);

 

// Save the buffer to a file. Apply industry standard encryption to protect privacy.

....

 

// Now load the database buffer back.

rcfg->SetDatabaseBuffer(buffer,nbytes);

 

// Clean up

delete[] buffer;

C# Example 52: Load/Save Recognition Database

// rdata is a PXCMFaceData.RecognitionData instance

// rcfg is a PXCMFaceConfiguration.RecognitionConfiguration instance

 

// allocate the buffer to save the database

PXCMFaceData.RecognitionModuleData rmd=rdata.QueryRecognitionModule();

Int32 nbytes=rmd.QueryDatabaseSize();

Byte[] buffer=new Byte[nbytes];

 

// retrieve the database buffer

rmd.QueryDatabaseBuffer(buffer);

 

// Save the buffer to a file. Apply industry standard encryption to protect privacy.

....

 

// Now load the database buffer back.

rcfg.SetDatabaseBuffer(buffer);

Java Example 52: Load/Save Recognition Database

// rdata is a PXCMFaceData.RecognitionData instance

// rcfg is a PXCMFaceConfiguration.RecognitionConfiguration instance

 

// allocate the buffer to save the database

PXCMFaceData.RecognitionModuleData rmd=rdata.QueryRecognitionModule();

int nbytes=rmd.QueryDatabaseSize();

byte[] buffer=new byte[nbytes];

 

// retrieve the database buffer

rmd.QueryDatabaseBuffer(buffer);

 

// Save the buffer to a file. Apply industry standard encryption to protect privacy.

....

 

// Now load the database buffer back.

rcfg.SetDatabaseBuffer(buffer);