示例#1
0
        private async void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {
            if (LiveFeedPanel.Visibility == Visibility.Visible)
            {
                StorageFile file = await webcam.CapturePhoto();

                if (null != file)
                {
                    await PersonFaceCmds.updateToBlob(file);
                }

                personFaceProgressRing.IsActive         = false;
                appbarFaceRefreshButton.IsEnabled       = true;
                appbarFaceAddFromCameraButton.IsEnabled = true;
                appbarFaceAddFromFileButton.IsEnabled   = true;
            }
            else
            {
                if (null != photoFile)
                {
                    await PersonFaceCmds.updateToBlob(photoFile);
                }

                personFaceProgressRing.IsActive = false;
                //appbarDeleteFaceButton.IsEnabled = true;
                appbarFaceRefreshButton.IsEnabled       = true;
                appbarFaceAddFromCameraButton.IsEnabled = true;
                appbarFaceAddFromFileButton.IsEnabled   = true;
            }
            AppBarButtonPersonFaceRefresh_Click(null, null);
            appBarTrainButton_Click(null, null);
        }
示例#2
0
        /// <summary>
        /// Triggered when the Capture Photo button is clicked by the user
        /// </summary>
        private async void Capture_Click(object sender, RoutedEventArgs e)
        {
            // Hide the capture photo button
            CaptureButton.Visibility = Visibility.Collapsed;

            // Capture current frame from webcam, store it in temporary storage and set the source of a BitmapImage to said photo
            currentIdPhotoFile = await webcam.CapturePhoto();

            var photoStream = await currentIdPhotoFile.OpenAsync(FileAccessMode.ReadWrite);

            BitmapImage idPhotoImage = new BitmapImage();
            await idPhotoImage.SetSourceAsync(photoStream);


            // Set the soruce of the photo control the new BitmapImage and make the photo control visible
            IdPhotoControl.Source     = idPhotoImage;
            IdPhotoControl.Visibility = Visibility.Visible;

            // Collapse the webcam feed or disabled feed grid. Make the enter user name grid visible.
            WebcamFeed.Visibility       = Visibility.Collapsed;
            DisabledFeedGrid.Visibility = Visibility.Collapsed;

            UserNameGrid.Visibility = Visibility.Visible;


            // Dispose photo stream
            photoStream.Dispose();
        }
示例#3
0
        private async void Timer_Tick(object sender, object e)
        {
            if (livetemperature() >= 23)
            {
                TestPostMessage(livetemperature().ToString());
                //Take photo and save into Intrusos
                if (webcam == null || !webcam.IsInitialized())
                {
                    // Initialize Webcam Helper
                    webcam = new WebcamHelper();
                    await webcam.InitializeCameraAsync();
                }
                currentIdPhotoFile = await webcam.CapturePhoto();

                // Create or open the folder in which the Whitelist is stored
                StorageFolder whitelistFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync(GeneralConstants.WhiteListFolderName, CreationCollisionOption.OpenIfExists);

                // Create a folder to store this specific user's photos
                StorageFolder currentFolder = await whitelistFolder.CreateFolderAsync("Intrusos", CreationCollisionOption.OpenIfExists);

                // Move the already captured photo the user's folder
                await currentIdPhotoFile.MoveAsync(currentFolder);
            }
            await Task.Run(async() => { await AzureIoTHub.SendTemperatureAsync(livetemperature()); });
        }
示例#4
0
        public async Task CapturePhoto()
        {
            await webcam.InitializeCameraAsync();

            if (!webcam.IsInitialized())
            {
                Debug.WriteLine("Not initialied");
            }
            StorageFile image = await webcam.CapturePhoto();

            try
            {
                // Oxford determines whether or not the visitor is on the Whitelist and returns true if so
                recognizedVisitors = await OxfordFaceAPIHelper.IsFaceInWhitelist(image);
            }
            catch (FaceRecognitionException fe)
            {
                switch (fe.ExceptionType)
                {
                // Fails and catches as a FaceRecognitionException if no face is detected in the image
                case FaceRecognitionExceptionType.NoFaceDetected:
                    Debug.WriteLine("WARNING: No face detected in this image.");
                    break;
                }
            }
            catch (FaceAPIException faceAPIEx)
            {
                Debug.WriteLine("FaceAPIException in IsFaceInWhitelist(): " + faceAPIEx.ErrorMessage);
            }
            catch
            {
                // General error. This can happen if there are no visitors authorized in the whitelist
                Debug.WriteLine("WARNING: Oxford just threw a general expception.");
            }

            if (recognizedVisitors.Count > 0)
            {
                // If everything went well and a visitor was recognized, unlock the door:
                Ledpin.Write(GpioPinValue.Low);
            }
            else
            {
                // Create or open the folder in which the Whitelist is stored
                StorageFolder folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("Banned", CreationCollisionOption.OpenIfExists);

                // Move the already captured photo the user's folder
                await image.MoveAsync(folder);

                var model = new Models.Database.Ban()
                {
                    Image = image.Name,
                    Time  = DateTime.Now
                };
                Ledpin.Write(GpioPinValue.High);
                database.InsertModel <Models.Database.Ban>(model);
            }
            isCapturing = false;
        }
示例#5
0
        private async Task CaptureAndAnalysis()
        {
            currentIdPhotoFile = await webcam.CapturePhoto();

            var photoStream = await currentIdPhotoFile.OpenAsync(FileAccessMode.ReadWrite);

            this.EmotionsColumnSeries.ItemsSource = null;
            this.EmotionsColumnSeries.ItemsSource = await emoFacesViewModel.GetEmotionsWithFaces(photoStream.AsStream());

            photoStream.Dispose();
        }
        /// <summary>
        /// Triggered when the user clicks the add photo button located in the app bar
        /// </summary>
        private async void AddButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            // Captures photo from current webcam stream
            StorageFile imageFile = await webcam.CapturePhoto();

            // Moves the captured file to the current user's ID image folder
            await imageFile.MoveAsync(currentUser.ImageFolder);

            // Update photo grid
            PopulatePhotoGrid();
            // Add to Oxford
            OxfordFaceAPIHelper.AddImageToWhitelist(imageFile, currentUser.Name);
        }
示例#7
0
        private async Task DoorbellPressed()
        {
            StorageFile file = null;

            if (webcam.IsInitialized())
            {
                // Stores current frame from webcam feed in a temporary folder
                file = await webcam.CapturePhoto();

                FaceQuery(file);
            }
            else
            {
                if (!webcam.IsInitialized())
                {
                    // The webcam has not been fully initialized for whatever reason:
                    Debug.WriteLine("Unable to analyze visitor at door as the camera failed to initlialize properly.");
                    await speech.Read(SpeechContants.NoCameraMessage);
                }
            }
            doorbellJustPressed = false;
            //FaceQuery(file);
        }
示例#8
0
        private async Task <StorageFile> TakePhoto()
        {
            // Confirms that webcam has been properly initialized and oxford is ready to go
            if (webcam.IsInitialized())
            {
                try
                {
                    // Stores current frame from webcam feed in a temporary folder
                    StorageFile image = await webcam.CapturePhoto();

                    return(image);
                }
                catch
                {
                    // General error. This can happen if there are no visitors authorized in the whitelist
                    Debug.WriteLine("WARNING: Oxford just threw a general expception.");
                }
            }
            else
            {
                if (!webcam.IsInitialized())
                {
                    // The webcam has not been fully initialized for whatever reason:
                    Debug.WriteLine("Unable to analyze visitor at door as the camera failed to initlialize properly.");
                    await speech.Read("No camera available");
                }

                /*
                 * if (!initializedOxford)
                 * {
                 *  // Oxford is still initializing:
                 *  Debug.WriteLine("Unable to analyze visitor at door as Oxford Facial Recogntion is still initializing.");
                 * }*/
            }
            return(null);
        }
示例#9
0
        /// <summary>
        /// Called when user hits physical or vitual doorbell buttons. Captures photo of current webcam view and sends it to Oxford for facial recognition processing.
        /// </summary>
        private async Task DoorbellPressed()
        {
            // Display analysing visitors grid to inform user that doorbell press was registered
            AnalysingVisitorGrid.Visibility = Visibility.Visible;

            // List to store visitors recognized by Oxford Face API
            // Count will be greater than 0 if there is an authorized visitor at the door
            List <string> recognizedVisitors = new List <string>();

            // Confirms that webcam has been properly initialized and oxford is ready to go
            if (webcam.IsInitialized() && initializedOxford)
            {
                // Stores current frame from webcam feed in a temporary folder
                StorageFile image = await webcam.CapturePhoto();

                try
                {
                    // Oxford determines whether or not the visitor is on the Whitelist and returns true if so
                    recognizedVisitors = await OxfordFaceAPIHelper.IsFaceInWhitelist(image);
                }
                catch (FaceRecognitionException fe)
                {
                    switch (fe.ExceptionType)
                    {
                    // Fails and catches as a FaceRecognitionException if no face is detected in the image
                    case FaceRecognitionExceptionType.NoFaceDetected:
                        Debug.WriteLine("WARNING: No face detected in this image.");
                        break;
                    }
                }
                catch (FaceAPIException faceAPIEx)
                {
                    Debug.WriteLine("FaceAPIException in IsFaceInWhitelist(): " + faceAPIEx.ErrorMessage);
                }
                catch
                {
                    // General error. This can happen if there are no visitors authorized in the whitelist
                    Debug.WriteLine("WARNING: Oxford just threw a general expception.");
                }

                if (recognizedVisitors.Count > 0)
                {
                    // If everything went well and a visitor was recognized, unlock the door:
                    AuthenticateUser(recognizedVisitors[0]);
                }
                else
                {
                    // Otherwise, inform user that they were not recognized by the system
                    await speech.Read(SpeechContants.VisitorNotRecognizedMessage);
                }
            }
            else
            {
                if (!webcam.IsInitialized())
                {
                    // The webcam has not been fully initialized for whatever reason:
                    Debug.WriteLine("Unable to analyze visitor at door as the camera failed to initlialize properly.");
                    await speech.Read(SpeechContants.NoCameraMessage);
                }

                if (!initializedOxford)
                {
                    // Oxford is still initializing:
                    Debug.WriteLine("Unable to analyze visitor at door as Oxford Facial Recogntion is still initializing.");
                }
            }

            doorbellJustPressed             = false;
            AnalysingVisitorGrid.Visibility = Visibility.Collapsed;
        }
示例#10
0
        public async void PerformClickActionCaptureImage()
        {
            progressBar.Visibility = Visibility.Visible;

            // Capture current frame from webcam, store it in temporary storage and set the source of a BitmapImage to said photo
            currentIdPhotoFile = await webcam.CapturePhoto();

            var photoStream = await currentIdPhotoFile.OpenAsync(FileAccessMode.ReadWrite);

            BitmapImage idPhotoImage = new BitmapImage();
            await idPhotoImage.SetSourceAsync(photoStream);


            #region Before Convert in Byte[] and then in stream
            var reader = new DataReader(photoStream.GetInputStreamAt(0));
            var bytes  = new byte[photoStream.Size];
            await reader.LoadAsync((uint)photoStream.Size);

            reader.ReadBytes(bytes);

            var stream = new MemoryStream(bytes);

            #endregion

            // Set the soruce of the photo control the new BitmapImage and make the photo control visible
            IdPhotoControl.Source     = idPhotoImage;
            IdPhotoControl.Visibility = Visibility.Visible;

            // Collapse the webcam feed or disabled feed grid. Make the enter user name grid visible.
            WebcamFeed.Visibility       = Visibility.Collapsed;
            DisabledFeedGrid.Visibility = Visibility.Collapsed;


            string subscriptionKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            EmotionServiceClient emotionServiceClient = new EmotionServiceClient(subscriptionKey);

            try
            {
                Emotion[] emotionResult;
                emotionResult = await emotionServiceClient.RecognizeAsync(stream);

                if (emotionResult != null)
                {
                    string score = "Happiness: " + emotionResult[0].Scores.Happiness.ToString("0.0000") + "\n";
                    score += "Fear: " + emotionResult[0].Scores.Fear.ToString("0.0000") + "\n";
                    score += "Anger: " + emotionResult[0].Scores.Anger.ToString("0.0000") + "\n";
                    score += "Contempt: " + emotionResult[0].Scores.Contempt.ToString("0.0000") + "\n";
                    score += "Disgust: " + emotionResult[0].Scores.Disgust.ToString("0.0000") + "\n";
                    score += "Neutral: " + emotionResult[0].Scores.Neutral.ToString("0.0000") + "\n";
                    score += "Sadness: " + emotionResult[0].Scores.Sadness.ToString("0.0000") + "\n";
                    score += "Surprise: " + emotionResult[0].Scores.Surprise.ToString("0.0000") + "\n";


                    txtText.Text = score;// "Happiness: " +emotionResult[0].Scores.Happiness.ToString()+"\n";

                    if (emotionResult[0].Scores.Happiness >= 0.85)
                    {
                        Send("111");
                    }
                    else if (emotionResult[0].Scores.Happiness >= 0.50 && emotionResult[0].Scores.Happiness < 0.85)
                    {
                        Send("001");
                    }
                    else if (emotionResult[0].Scores.Happiness > 0.25 && emotionResult[0].Scores.Happiness < 0.50)
                    {
                        Send("100");
                    }
                    else
                    {
                        Send("110");
                    }
                }
            }
            catch (Exception exception)
            {
            }

            // Dispose photo stream
            photoStream.Dispose();
            progressBar.Visibility = Visibility.Collapsed;
        }