Ejemplo n.º 1
0
        private async void ProcessCameraCapture(ImageAnalyzer e)
        {
            if (e == null)
            {
                this.cameraControl.RestartAutoCaptureCycle();
                return;
            }

            this.recognitionPersistence.PersisteRecognitionResults(e);

            this.imageFromCameraWithFaces.DataContext = e;
            this.imageFromCameraWithFaces.Visibility  = Visibility.Visible;



            e.FaceRecognitionCompleted += async(s, args) =>
            {
                try
                {
                    ImageAnalyzer results = s as ImageAnalyzer;


                    if (results != null && results.DetectedFaces != null)
                    {
                        foreach (Face detectedFace in results.DetectedFaces)
                        {
                            IdentifiedPerson faceIdIdentification = null;
                            if (results.IdentifiedPersons != null && results.IdentifiedPersons.Count <IdentifiedPerson>() > 0)
                            {
                                faceIdIdentification = results.IdentifiedPersons.FirstOrDefault(p => p.FaceId == detectedFace.FaceId);
                            }

                            string message = string.Empty;
                            if (faceIdIdentification != null)
                            {
                                // We able identify this person. Say his name
                                message = SpeechContants.GeneralGreetigMessage(faceIdIdentification.Person.Name);
                                await speech.Read(message);
                            }
                            else
                            {
                                HSFace face = new HSFace(detectedFace.FaceId, "", detectedFace.FaceAttributes);
                                if (face.Age > 0)
                                {
                                    // Unknown person!
                                    message = String.Format(SpeechContants.UnknownVisitorDetailMessage, face.Gender, face.Age);
                                    await speech.ReadSsml(message);
                                }
                            }
                        }
                    }

                    //Update visitors statistic
                    Task.Run(async() => { CalculateVisitorsStatistic(results); });

                    this.photoCaptureBalloonHost.Opacity = 1;

                    int    photoDisplayDuration = 10;
                    double decrementPerSecond   = 100.0 / photoDisplayDuration;
                    for (double i = 100; i >= 0; i -= decrementPerSecond)
                    {
                        this.resultDisplayTimerUI.Value = i;
                        await Task.Delay(1000);
                    }

                    this.photoCaptureBalloonHost.Opacity      = 0;
                    this.imageFromCameraWithFaces.DataContext = null;
                }
                finally
                {
                    this.cameraControl.RestartAutoCaptureCycle();
                }
            };
        }