[英]Knowing when MediaCapture is previewing
I'm making a simple photo app using MediaCapture . 我正在使用MediaCapture制作一个简单的照片应用程序。 I want the app to automatically start a countdown as soon as the webcam has finished initiating and is showing the preview.. Everything is working great, except the countdown is starting before the camera preview appears.
我希望该应用程序在网络摄像头启动完成并显示预览后立即自动开始倒计时。一切工作正常,除了倒计时在显示照相机预览之前开始。 Here is the gist of my code...
这是我代码的要点...
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
previewElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
startCountdown();
xaml: XAML:
<CaptureElement x:Name="previewElement" Visibility="Visible" FlowDirection="RightToLeft"/>
Is there a way I can check when the camera has fully initiated and the preview is showing an image? 有什么方法可以检查相机是否已完全启动并且预览是否正在显示图像?
On my search for an answer I stumbled across effects and discovered MediaCapture has builtin face detection . 在寻找答案时,我偶然发现了各种效果,并发现MediaCapture具有内置的面部检测功能 。 When a face is detected it's safe to say the camera is initiated.
当检测到面部时,可以肯定地说相机已启动。
//setup face detection
var definition = new FaceDetectionEffectDefinition();
definition.SynchronousDetectionEnabled = false;
definition.DetectionMode = FaceDetectionMode.HighPerformance;
faceDetection = (FaceDetectionEffect)await mediaCapture.AddVideoEffectAsync(definition, MediaStreamType.Photo);
faceDetection.DesiredDetectionInterval = TimeSpan.FromMilliseconds(33);
faceDetection.FaceDetected += FaceDetection_FaceDetected;
faceDetection.Enabled = true;
...
private async void FaceDetection_FaceDetected(FaceDetectionEffect sender, FaceDetectedEventArgs args) {
if(args.ResultFrame.DetectedFaces.Count() > 0) {
Debug.WriteLine(string.Format("Detected {0} faces", args.ResultFrame.DetectedFaces.Count()));
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => HighlightDetectedFaces(args.ResultFrame.DetectedFaces));
if (!countdownStarted)
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => startCountdown());
}
}
Though it's not an answer to my question, it's a solution to my problem. 尽管这不是我的问题的答案,但这是我的问题的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.