Exemple #1
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

            var capturedPhoto = await lowLagCapture.CaptureAsync();

            var softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;

            softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
            var source = new SoftwareBitmapSource();
            await source.SetBitmapAsync(softwareBitmap);

            VideoFrame           videoFrame           = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap);
            ObtenerIdentidadONNX obtenerIdentidadONNX = new ObtenerIdentidadONNX();
            var nombre = await obtenerIdentidadONNX.ObtenerIdentidadOnnX(videoFrame, _session);

            List <Empleados> EmpAutorizados = new List <Empleados>();

            EmpAutorizados.Add(new Empleados()
            {
                Nombre = "Visco"
            });
            EmpAutorizados.Add(new Empleados()
            {
                Nombre = "Reitano"
            });

            var buscarEmpleado = EmpAutorizados.Find(x => x.Nombre == nombre);

            if (buscarEmpleado != null)
            {
                brush = new SolidColorBrush(Windows.UI.Colors.Green);
            }
            else
            {
                brush  = new SolidColorBrush(Windows.UI.Colors.Red);
                nombre = "No Autorizado";
            }
            if (nombre != "")
            {
                var      iniciarFichajeController = new Controller.IniciarFichaje();
                DateTime utcDate = DateTime.UtcNow;

                var fotosCapttupleLocal = await iniciarFichajeController.TomarFoto(source, utcDate.ToString(), nombre, softwareBitmap, brush);

                fotosCapttuple.Add(fotosCapttupleLocal);

                tuples.Add(new Tuple <FotosCapttuple>(fotosCapttupleLocal));
            }


            await lowLagCapture.FinishAsync();
        }
Exemple #2
0
        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 = "";
                            ObtenerIdentidadONNX obtenerIdentidadONNX = new ObtenerIdentidadONNX();
                            foreach (var caraEncontrad in faces)
                            {
                                if (IdentidadEncontrada == "")
                                {
                                    nombre = await obtenerIdentidadONNX.ObtenerIdentidadOnnX(previewFrame, _session);

                                    //  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();
            }
        }