Created
March 17, 2017 22:28
-
-
Save TakahiroMiyaura/3daa8fd2ddf963341e8da9571ca56645 to your computer and use it in GitHub Desktop.
HoloLensで顔検出やってみました。 ref: http://qiita.com/miyaura/items/85f53b13c71983e8ced2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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