Home Community Blog Buy Now

Misty Community Forum

Face recognition

how can i use face recognition in .NET enviormnet?

Welcome @aryehlevklein, & thanks for the question!

There are three main components to using face recognition in a C# skill:

  • Registering a listener for face recognition events
  • Invoking the command to start face recognition
  • Declaring a callback function for handling face recognition event data

Here’s an example taken from the InteractiveMistySkill sample from the .NET SDK repo on GitHub:

To start face recognition, we issue a StartFaceRecognition command in the OnStart method:


Now Misty is actively attempting to detect & recognize faces, but you still need to register a listener for face rec event messages in order to receive that data and handle it in your skill code.

So, in the OnStart method, we register a listener for face rec events by calling on the method below. Note that keepAlive here (third argument) is set to false; you can set this to true in order to keep Misty looking for faces after the first face rec callback triggers, or you can re-register for face rec events inside your face rec callback function.

_misty.RegisterFaceRecognitionEvent(FaceRecCallback, 0, false, null, null, null);

The last step is to define the callback function for handling face recognition event message (in this case we called that function FaceRecCallback, but you can name it whatever you like). In the InteractiveMistySkill sample, we define the FaceRecCallback function outside the OnStart method. It looks like this:

private void FaceRecCallback(IFaceRecognitionEvent faceRecEvent)
	if (faceRecEvent.Label == "unknown person")
		AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
		ImageDetails randomImage = _imageList[_randomGenerator.Next(0, _imageList.Count - 1)];
		_misty.DisplayImage(randomImage.Name, 1, null);
		_misty.PlayAudio(randomAudio.Name, 100, null);
		_misty.DisplayImage("e_EcstacyStarryEyed.jpg", 1, null);
		_misty.PlayAudio("sEcstacy.wav", 100, null);

	if (!_misty.Wait(5000)) { return; }
	_misty.DisplayImage("e_ContentLeft.jpg", 1, null);
	if (!_misty.Wait(5000)) { return; }
	_misty.RegisterFaceRecognitionEvent(FaceRecCallback, 0, false, null, null, null);

In this callback, we have Misty play a random sound and display a random image when she sees an unknown person. If she sees someone she knows, she’ll show her “Ecstacy” eyes and play a happy sound. Then we wait a few seconds, change Misty’s eyes to e_ContentLeft.jpg, and re-register for face recognition events.

There are other examples of registering event listeners in the developer documentation. The .NET SDK docs are still a work in progress; please feel free to post other questions you have here and we’ll answer as quickly as we can :slight_smile:

1 Like

ok thank you very much, was very helpfull! :grinning: :grinning:

1 Like