/// <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(); }
/// <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); }
/// <summary> /// Called when someone enters room or vitual motion button is pressed. /// Captures photo of current webcam view and sends it to Oxford for facial recognition processing. /// </summary> private async Task SomeoneEntered() { // Announce that an intruder has been detected await speech.Read(SpeechContants.IntruderDetectedMessage); // Display analysing visitors grid to inform user that motion was sensed 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 intruderImage = await webcam.CapturePhoto(); try { // Oxford determines whether or not the visitor is on the Whitelist and returns recongized visitor if so recognizedVisitors = await OxfordFaceAPIHelper.IsFaceInWhitelist(intruderImage); } 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 { // 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, allow the person entry AllowEntry(recognizedVisitors[0]); } else { // Otherwise, inform user that they were not recognized by the system await speech.Read(SpeechContants.NotAllowedEntryMessage); // If the intrudersFolder has not been opened, open it if (intrudersFolder == null) { // Create the intrudersFolder if it doesn't exist; if it already exists, open it. intrudersFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync(GeneralConstants.IntruderFolderName, CreationCollisionOption.OpenIfExists); } // Determine the number of intruders already recorded var intruderSubFolders = await intrudersFolder.GetFoldersAsync(); int intruderCount = intruderSubFolders.Count; // Convert the intruder count integer to string for the subfolder name string subFolderName = "intruder" + intruderCount.ToString(); // Create a subfolder to store this specific intruder's photo StorageFolder currentFolder = await intrudersFolder.CreateFolderAsync(subFolderName, CreationCollisionOption.ReplaceExisting); // Move the already captured photo the intruder's folder await intruderImage.MoveAsync(currentFolder); // Refresh the UI grid of intruders UpdateIntruderVisitors(); } } 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."); } } motionJustSensed = false; AnalysingVisitorGrid.Visibility = Visibility.Collapsed; }