Zepeng She
Published © MIT

Face Detection in Windows 10 IoT core with Oxford Project

When someone show in the camera which is run on Raspberry Pi 2 with Windows 10 IoT Core, your phone will get notification that who it is.

IntermediateShowcase (no instructions)9,452
Face Detection in Windows 10 IoT core with Oxford Project

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Camera (generic)
A Generic USB camera
×1
Speaker (Generic)
×1

Software apps and online services

Windows 10 IoT Core
Microsoft Windows 10 IoT Core
Microsoft Azure
Microsoft Azure
Microsoft Project Oxford
Wechat

Story

Read more

Code

CreateFaceDetectionEffectAsync

C#
CreateFaceDetectionEffectAsync
private async Task CreateFaceDetectionEffectAsync()
        {
            // Create the definition, which will contain some initialization settings
            var definition = new FaceDetectionEffectDefinition();

            // To ensure preview smoothness, do not delay incoming samples
            definition.SynchronousDetectionEnabled = false;
            // In this scenario, choose detection speed over accuracy
            definition.DetectionMode = FaceDetectionMode.HighPerformance;

            // Add the effect to the preview stream
            _faceDetectionEffect = (FaceDetectionEffect)await _mediaCapture.AddVideoEffectAsync(definition, MediaStreamType.VideoPreview);

            // Register for face detection events
            _faceDetectionEffect.FaceDetected += FaceDetectionEffect_FaceDetected;

            // Choose the shortest interval between detection events
            _faceDetectionEffect.DesiredDetectionInterval = TimeSpan.FromMilliseconds(33);

            // Start detecting faces
            _faceDetectionEffect.Enabled = true;
        }

FaceDetectionEffect_FaceDetected

C#
When Detected the Face, we will create a face bounding boxes and upload the picture to the azure
private async void FaceDetectionEffect_FaceDetected(FaceDetectionEffect sender, FaceDetectedEventArgs args)
        {
            Debug.WriteLine("Face number: {0}", args.ResultFrame.DetectedFaces.Count);
            

            // Ask the UI thread to render the face bounding boxes
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => HighlightDetectedFaces(args.ResultFrame.DetectedFaces));

            ///检测到人脸,上传到服务器。
            /// 
            

            try
            {
                if (args.ResultFrame.DetectedFaces.Count > faceNumber )
                {
                    faceNumber = args.ResultFrame.DetectedFaces.Count;
                    await SendPhotoAsync();
                }
                else
                {
                    faceNumber = args.ResultFrame.DetectedFaces.Count;
                }


                //
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception when sending a photo: {0}", ex.ToString());
            }
            ;
        }

FaceDetectionButton_Tapped

C#
When the FaceDetection Button pressed, we will create FaceDetectionEffect
private async void FaceDetectionButton_Tapped(object sender, TappedRoutedEventArgs e)
{
    if (_faceDetectionEffect == null || !_faceDetectionEffect.Enabled)
    {
	// Clear any rectangles that may have been left over from a previous instance of the effect
	FacesCanvas.Children.Clear();
	await CreateFaceDetectionEffectAsync();
    }
    else
    {
	await CleanUpFaceDetectionEffectAsync();
    }
    UpdateCaptureControls();
}

FaceDetectionWithIoT

This is the client of this solution, which is the Windows 10 UWP app runs on the Raspberry Pi

FaceDetectionServerSide

Face detection IoT demo is a demo combining Windows 10 IoT Core @RPi2 and Azure and Project Oxford, to implement a scenario that people's face can be captured in the real time video ingested from the camera on RPi2 and be identified through analysis in Azure and Project Oxford. The code is for demo's backend server.

Credits

Zepeng She

Zepeng She

1 project • 11 followers

Comments