Skip to content

Instantly share code, notes, and snippets.

@TakahiroMiyaura
Created March 17, 2017 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakahiroMiyaura/3daa8fd2ddf963341e8da9571ca56645 to your computer and use it in GitHub Desktop.
Save TakahiroMiyaura/3daa8fd2ddf963341e8da9571ca56645 to your computer and use it in GitHub Desktop.
HoloLensで顔検出やってみました。 ref: http://qiita.com/miyaura/items/85f53b13c71983e8ced2
// Copyright(c) 2017 Takahiro Miyaura
// Released under the MIT license
// http://opensource.org/licenses/mit-license.php
public override void DetectFace()
{
AppCallbacks.Instance.InvokeOnUIThread(async () =>
{
var properties =
_capture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as
VideoEncodingProperties;
if (properties == null)
return;
//coution! face detect is only supported 'BitmapPixelFormat.Gray8'.
var videoFrame = new VideoFrame(BitmapPixelFormat.Gray8, (int) properties.Width, (int) properties.Height);
this.FrameSizeWidth = (int) properties.Width;
this.FrameSizeHeight = (int) properties.Height;
var previewFrame = await _capture.GetPreviewFrameAsync(videoFrame);
var detector = await FaceDetector.CreateAsync();
var detectFaces = await detector.DetectFacesAsync(previewFrame.SoftwareBitmap);
var faceInformations = detectFaces.Select(x => new FaceInformation
{
X = x.FaceBox.X,
Y = x.FaceBox.Y,
Width = x.FaceBox.Width,
Height = x.FaceBox.Height
}).ToList();
AppCallbacks.Instance.InvokeOnAppThread(() => { OnDetected(faceInformations); }, false);
}, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment