[英]Knowing when MediaCapture is previewing
我正在使用MediaCapture制作一個簡單的照片應用程序。 我希望該應用程序在網絡攝像頭啟動完成並顯示預覽后立即自動開始倒計時。一切工作正常,除了倒計時在顯示照相機預覽之前開始。 這是我代碼的要點...
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
previewElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
startCountdown();
XAML:
<CaptureElement x:Name="previewElement" Visibility="Visible" FlowDirection="RightToLeft"/>
有什么方法可以檢查相機是否已完全啟動並且預覽是否正在顯示圖像?
在尋找答案時,我偶然發現了各種效果,並發現MediaCapture具有內置的面部檢測功能 。 當檢測到面部時,可以肯定地說相機已啟動。
//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());
}
}
盡管這不是我的問題的答案,但這是我的問題的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.