Emotion Detection via SenseManager

Top  Previous  Next

To activate the emotion detection algorithm in the PXC[M]SenseManager multimodal pipeline, use the EnableEmotion function. You can implement emotion detection in your application in two ways: using the SenseManager procedural functions or using the SenseManager callback functions.

Emotion Detection Using the SenseManager Procedural Functions

Example 58 shows an example of a typical emotion detection application. The example does the following:

Create an instance of the PXC[M]SenseManager interface.
Activate emotion detection by using the EnableEmotion function.
Initialize the PXC[M]SenseManager pipeline (Init) and loop through the image frames (AcquireFrame and ReleaseFrame). Whenever some emotion result is available, such as a face is detected, the QueryEmotion function returns a valid instance.

Such checking with the QueryEmotion function is optional if you call the AcquireFrame function with ifall=true, which blocks until all modality results are ready for processing.

During streaming, you may call the PauseEmotion function to pause/resume emotion detection under certain conditions.
Clean up the sample.

C++ Example 58: Emotion Detection using the SenseManager Procedural Functions

// Create a SenseManager instance

PXCSenseManager *sm=PXCSenseManager::CreateInstance();

 

// Enable emotion detection

sm->EnableEmotion();

 

// Initialize the pipeline

sm->Init();

 

// Stream data

while (sm->AcquireFrame(true)>=PXC_STATUS_NO_ERROR) {

  // Retrieve the emotion detection results if ready

  PXCEmotion *em2=sm->QueryEmotion();

  if (em2) {

      ...

  }

 

  // Resume next frame processing

  sm->ReleaseFrame();

}

 

// Clean up

sm->Release();

C# Example 58: Emotion Detection using the SenseManager Procedural Functions

// Create a SenseManager instance

PXCMSenseManager sm=PXCMSenseManager.CreateInstance();

 

// Enable emotion detection

sm.EnableEmotion();

 

// Initialize the pipeline

sm.Init();

 

// Stream data

while (sm.AcquireFrame(true)>=pxcmStatus.PXCM_STATUS_NO_ERROR) {

  // Retrieve the emotion detection results if ready

  PXCMEmotion em2=sm.QueryEmotion();

  if (em2!=null) {

     ...

  }

 

  // Resume next frame processing

  sm.ReleaseFrame();

}

 

// Clean up

sm.Dispose();

Java Example 58: Emotion Detection using the SenseManager Procedural Functions

// Create a SenseManager instance

PXCMSenseManager sm=PXCMSenseManager.CreateInstance();

 

// Enable emotion detection

sm.EnableEmotion();

 

// Initialize the pipeline

sm.Init();

 

// Stream data

while (sm.AcquireFrame(true)>=pxcmStatus.PXCM_STATUS_NO_ERROR) {

  // Retrieve the emotion detection results if ready

  PXCMEmotion em2=sm.QueryEmotion();

  if (em2!=null) {

     ...

  }

 

  // Resume next frame processing

  sm.ReleaseFrame();

}

 

// Clean up

sm.close();

Emotion Detection Using the SenseManager Callback Functions

You may also use the PXC[M]SenseManager callback functions. Example 59 shows the emotion detection application using callbacks. The SDK invokes the OnModuleProcessedFrame callback when there is some emotion result for processing.

C++ Example 59: Emotion Detection using the SenseManager Event Functions

class MyHandler: public PXCSenseManager::Handler {

public:

   virtual pxcStatus PXCAPI OnModuleProcessedFrame(pxcUID mid, PXCBase *module, PXCCapture::Sample *sample) {

      // check if the callback is from the emotion module.

      if (mid==PXCEmotion::CUID) {

          PXCEmotion *em=module->QueryInstance<PXCEmotion>();

         ...

      }

      // return NO_ERROR to continue, or any error to abort.

      return PXC_STATUS_NO_ERROR;

   }

};

 

// Create a SenseManager instance

PXCSenseManager *sm=PXCSenseManager.CreateInstance();

 

// Enable emotion detection

sm->EnableEmotion();

 

// Initialize.

MyHandler handler;

sm->Init(&handler);

 

// Streaming data

sm->StreamFrames(true);

 

// Clean up

sm->Release();

C# Example 59: Emotion Detection using the SenseManager Event Functions

pxcmStatus OnModuleProcessedFrame(Int32 mid, PXCMBase module, PXCMCapture.Sample sample) {

  // check if the callback is from the emotion module.

  if (mid==PXCMEmotion.CUID) {

     PXCMEmotion em=module.QueryInstance<PXCMEmotion>();

     ...

  }

  // return NO_ERROR to continue, or any error to abort.

  return pxcmStatus.PXCM_STATUS_NO_ERROR;

}

 

// Create a SenseManager instance

PXCMSenseManager sm=PXCMSenseManager.CreateInstance();

 

// Enable emotion detection

sm.EnableEmotion();

 

// Initialize.

PXCMSenseManager.Handler handler=new PXCMSenseManager.Handler {

   onModuleProcessedFrame=OnModuleProcessedFrame

};

sm.Init(handler);

 

// Streaming data

sm.StreamFrames(true);

 

// Clean up

sm.Dispose();

Java Example 59: Emotion Detection using the SenseManager Event Functions

class MyHandler implements PXCMSenseManager.Handler {

   public pxcmStatus OnModuleProcessedFrame(int mid, PXCMBase module, PXCMCapture.Sample sample) {

      // check if the callback is from the emotion module.

      if (mid==PXCMEmotion.CUID) {

          PXCMEmotion em=(PXCMEmotion)object.QueryInstance(PXCMEmotion.CUID);

          ...

      }

      // return NO_ERROR to continue, or any error to abort.

      return pxcmStatus.PXCM_STATUS_NO_ERROR;

   }

};

 

// Create a SenseManager instance

PXCMSenseManager sm=PXCMSenseManager.CreateInstance();

 

// Enable emotion detection

sm.EnableEmotion();

 

// Initialize.

MyHandler handler=new MyHandler();

sm.Init(handler);

 

// Streaming data

sm.StreamFrames(true);

 

// Clean up

sm.close();