Intel RealSense Camera (F200): Face–Alerts

Adding to this set of posts, I thought I’d retreat from any complexity that I’d introduced in the last post and build out another console application that used the SDK’s ability to fire ‘alerts’ around facial events.

From the point of view of the SDK, an ‘alert’ is an event of type;

    public enum AlertType
    {
      ALERT_NEW_FACE_DETECTED = 1,
      ALERT_FACE_OUT_OF_FOV = 2,
      ALERT_FACE_BACK_TO_FOV = 3,
      ALERT_FACE_OCCLUDED = 4,
      ALERT_FACE_NO_LONGER_OCCLUDED = 5,
      ALERT_FACE_LOST = 6,
    }

and so the facial detection module (PXCMFaceModule) can be asked via its configuration type (PXCMFaceConfiguration) to either EnableAlert() with a specific alert or to EnableAllAlerts() to switch them all on.

That allows me to write simple console code like this;

namespace ConsoleApplication1
{
  using System;
  using System.Collections.Generic;
  using System.Linq;

  class PXCMStatusException : Exception
  {
    public PXCMStatusException(pxcmStatus status)
    {
      this.Status = status;
    }
    public pxcmStatus Status { get; private set; }
  }
  static class PXCMStatusExtensions
  {
    public static void ThrowOnFail(this pxcmStatus status)
    {
      if (!status.Succeeded())
      {
        throw new PXCMStatusException(status);
      }
    }
    public static bool Succeeded(this pxcmStatus status)
    {
      return (status == pxcmStatus.PXCM_STATUS_NO_ERROR);
    }
  }
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hit a key to end...");

      using (PXCMSenseManager senseManager = PXCMSenseManager.CreateInstance())
      {
        senseManager.EnableFace();

        var face = senseManager.QueryFace();

        using (var config = face.CreateActiveConfiguration())
        {
          config.EnableAllAlerts();

          config.SubscribeAlert(alert =>
          {
            Console.WriteLine("An alert has arrived from face {0} with detail {1}", alert.faceId, alert.label);
          });

          config.ApplyChanges().ThrowOnFail();
        }
        senseManager.Init();

        senseManager.StreamFrames(false);

        Console.ReadKey();

        face.Dispose();
      }
     }
  }
}

and then swing my ugly mug back and forth in front of the screen to drive the output like this;

consoleFaceCapture

and so it’s pretty easy to build some kind of embedded kiosk with the RealSense that can tell you whether there’s one (or more) human faces in front of the kiosk.

Naturally, it can also go much further as in my previous post where I was displaying the location data from those faces. In the next post, I’ll look into whether we can recognise those faces which seems to me to open/widen the door to a tonne of scenarios;

  • the automatic photo booth to automatically frame the subjects, know when they are smiling without having to ask Smile
  • the automatic security system that lets you through those locked doors at work purely based on your face
  • the automatic car park system which knows how long you’ve stayed because it recognises you from when you left (and perhaps can even tell you where the heck you left your car)
  • the automatic computer logon system which stops asking you for a password (oh, wait…. Winking smile)
  • etc.