Beispiel #1
0
        /// <summary>
        /// Triggered when the user clicks the delete user button located in the app bar
        /// </summary>
        private async void DeleteButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            await currentUser.ImageFolder.DeleteAsync();

            FaceAPIHelper.RemoveUserFromWhitelist(currentUser.Name);

            await CleanupCameraAsync();

            // Navigate to MainPage
            Frame.GoBack();
        }
Beispiel #2
0
        /// <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 camera.CapturePhoto();

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

            PopulatePhotoGrid();

            FaceAPIHelper.AddImageToWhitelist(imageFile, currentUser.Name);
        }
    // Use this for initialization
    void Start()
    {
        adjuster = GetComponent <UIAdjuster>();
        TextAsset api_access_key = Resources.Load("api_access_key") as TextAsset;

        apiHelper = new FaceAPIHelper(api_access_key.text, PERSON_GROUP_ID);

        currentState = "started";
        shouldUpdate = true;

        if (!Directory.Exists(SAVE_PATH))
        {
            Directory.CreateDirectory(SAVE_PATH);
        }
    }
        /// <summary>
        /// Triggered when the Confirm photo button is clicked by the user. Stores the captured photo to storage and navigates back to MainPage.
        /// </summary>
        private async void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(UserNameBox.Text))
            {
                var           picturesFolder  = ApplicationData.Current.LocalCacheFolder;
                StorageFolder whitelistFolder = await picturesFolder.CreateFolderAsync(GeneralConstants.WhiteListFolderName, CreationCollisionOption.OpenIfExists);

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

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

                FaceAPIHelper.AddUserToWhitelist(UserNameBox.Text, currentFolder);

                await CleanupCameraAsync();

                // Navigate back to MainPage
                this.Frame.GoBack();
            }
        }
        /// <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()
        {
            bool showResult = true;

            // Display analysing visitors grid to inform user that doorbell press was registered
            AnalysingVisitorGrid.Visibility = Visibility.Visible;

            List <string> recognizedVisitors = new List <string>();

            if (this.camera.Initialized && this.initializedFaceApi)
            {
                StorageFile image = await this.camera.CapturePhoto();

                try {
                    recognizedVisitors = await FaceAPIHelper.IsFaceInWhitelist(image);
                }
                catch (FaceRecognitionException e) {
                    MessageDialog diag = new MessageDialog($"The facial recognition failed: {e.ExceptionType}", "Recognition failed");
                    await diag.ShowAsync();

                    showResult = false;
                }
                catch (FaceAPIException e) {
                    if (e.ErrorMessage.Contains("exceeded rate limit"))
                    {
                        MessageDialog diag = new MessageDialog(e.ErrorMessage, "Exceeded Limit");
                        await diag.ShowAsync();

                        showResult = false;
                    }

                    Debug.WriteLine(e);
                }
                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)
                {
                    WelcomeUser(recognizedVisitors[0]);
                }
                else if (showResult)
                {
                    UnknownUser();
                }
            }
            else
            {
                if (!this.camera.Initialized)
                {
                    Debug.WriteLine("Unable to analyze visitor as the camera failed to initlialize properly.");
                }

                if (!this.initializedFaceApi)
                {
                    Debug.WriteLine("Unable to analyze visitor as Facial Recogntion is still initializing.");
                }
            }

            this.doorbellJustPressed        = false;
            AnalysingVisitorGrid.Visibility = Visibility.Collapsed;
        }
        /// <summary>
        /// Called once, when the app is first opened. Initializes Oxford facial recognition.
        /// </summary>
        public async void InitializeFaceApi()
        {
            this.initializedFaceApi = await FaceAPIHelper.Initialize();

            UpdateWhitelistedVisitors();
        }
        private async void btnCapture_Click(object sender, RoutedEventArgs e)
        {
            image2.Visibility = Visibility.Visible;
            image2.Source     = image1.Source;
            image1.Visibility = Visibility.Hidden;

            tempfilename = Helper.SaveTempImageCapture((BitmapSource)image2.Source);
            webcam.Stop();

            //Login
            UserTableDataContext dataContext = new UserTableDataContext();
            var usr = dataContext.Users.SingleOrDefault(x => x.username == this.username);

            ////label.Content = "Please wait...";
            if (usr != null)
            {
                FaceAPIHelper tempImage = new FaceAPIHelper();
                string        result    = await tempImage.UploadOneFace(tempfilename);

                if (String.IsNullOrEmpty(result))
                {
                    tempFaceCollection = tempImage.faceResultCollection;
                }
                else
                {
                    MessageBox.Show(result, "Error", MessageBoxButton.OK);
                    redo();
                    return;
                }


                //Get comparison face for verify
                //CHANGE HERE TO BE DYNAMIC
                string        imagepath = usr.photofile; // dt.Rows[0][0].ToString();
                FaceAPIHelper realImage = new FaceAPIHelper();
                result = await realImage.UploadOneFace(imagepath);

                if (String.IsNullOrEmpty(result))
                {
                    databaseFaceCollection = realImage.faceResultCollection;
                }
                else
                {
                    MessageBox.Show(result, "Error", MessageBoxButton.OK);
                    redo();
                    return;
                }

                //Verify
                string res = await realImage.Verify2Faces(tempFaceCollection, databaseFaceCollection);

                if (res.ToLower().Contains("successful"))
                {
                    MessageBox.Show(res, "Successful", MessageBoxButton.OK);
                    webcam.Stop();

                    MainMenuWIthLights ss = new MainMenuWIthLights(usr);
                    ss.Show();
                    this.Close();
                    return;
                }
                else
                {
                    MessageBox.Show(res, "Error", MessageBoxButton.OK);
                    redo();
                    return;
                }
            }
            else
            {
                MessageBox.Show("User not found", "Error", MessageBoxButton.OK);
                MainWindow mw = new MainWindow();
                mw.Show();
                webcam.Stop();
                this.Close();
            }
        }