private async void ProcessCurrentVideoFrame(ThreadPoolTimer timer) { if (this.currentState != ScenarioState.Streaming) { return; } if (!frameProcessingSemaphore.Wait(0)) { return; } try { const BitmapPixelFormat InputPixelFormat1 = BitmapPixelFormat.Nv12; using (VideoFrame previewFrame = new VideoFrame(InputPixelFormat1, (int)this.videoProperties.Width, (int)this.videoProperties.Height)) { var valor = await this.mediaCapture.GetPreviewFrameAsync(previewFrame); if (FaceDetector.IsBitmapPixelFormatSupported(previewFrame.SoftwareBitmap.BitmapPixelFormat)) { var previewFrameSize = new Windows.Foundation.Size(previewFrame.SoftwareBitmap.PixelWidth, previewFrame.SoftwareBitmap.PixelHeight); var ignored = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { var caraNuevaValor = ""; this.SetupVisualization(previewFrameSize, faces); //this.imagenCompletar.Source = bitmpatSRC; //bitmpatSRC.SetBitmapAsync(previewFrameBMO); }); faces = await this.faceTracker.ProcessNextFrameAsync(previewFrame); if (faces.Count != 0 && IdentidadEncontrada == "") { string nombre = ""; int contador = 0; foreach (var caraEncontrad in faces) { var cara = caraEncontrad.FaceBox.ToString(); nombre = await ObtenerIdentidad(); contador += 1; IdentidadEncontrada = nombre; identidades.Identidad(new GenericEventArgs <string>(IdentidadEncontrada)); } } } else { throw new System.NotSupportedException("PixelFormat '" + InputPixelFormat.ToString() + "' is not supported by FaceDetector"); } } } catch (Exception ex) { var ignored = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { //this.rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage); }); } finally { frameProcessingSemaphore.Release(); } }
private async void ProcessCurrentVideoFrame(ThreadPoolTimer timer) { if (this.currentState != ScenarioState.Streaming) { return; } if (!frameProcessingSemaphore.Wait(0)) { return; } try { const BitmapPixelFormat InputPixelFormat1 = BitmapPixelFormat.Nv12; using (VideoFrame previewFrame = new VideoFrame(InputPixelFormat1, (int)this.videoProperties.Width, (int)this.videoProperties.Height)) { var valor = await this.mediaCapture.GetPreviewFrameAsync(previewFrame); faces = await this.faceTracker.ProcessNextFrameAsync(previewFrame); if (FaceDetector.IsBitmapPixelFormatSupported(previewFrame.SoftwareBitmap.BitmapPixelFormat)) { var previewFrameSize = new Windows.Foundation.Size(previewFrame.SoftwareBitmap.PixelWidth, previewFrame.SoftwareBitmap.PixelHeight); await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { this.SetupVisualization(previewFrameSize, faces); }); if (faces.Count != 0) { string nombre = ""; foreach (var caraEncontrad in faces) { if (IdentidadEncontrada == "") { nombre = await App5.ObtenerIdentidad.ObtenerIdentidadAPI(valor, videoProperties, mediaCapture); if (nombre != "") { IdentidadEncontrada = nombre; await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { txtIdentificando.Visibility = Visibility.Collapsed; RectIdentificando.Visibility = Visibility.Collapsed; }); AgregarCaraALista(IdentidadEncontrada); } else { nombre = "No se encontro identidad"; await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { IdentidadEncontrada = string.Empty; txtIdentificando.Visibility = Visibility.Visible; RectIdentificando.Visibility = Visibility.Visible; }); } } } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { txtResult.Text = nombre; imagenCamaraWeb.Source = imageSourceCW; }); } else { string nombre = string.Empty; int contador = 0; IdentidadEncontrada = string.Empty; } } else { throw new System.NotSupportedException("PixelFormat '" + InputPixelFormat.ToString() + "' is not supported by FaceDetector"); } } } catch (Exception ex) { var ignored = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { txtResultServicio.Text = ex.Message.ToString(); //this.rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage); }); } finally { frameProcessingSemaphore.Release(); } }