Esempio n. 1
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;
        }
Esempio n. 2
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;
        }