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()); }); }
/// <summary> /// Triggered when webcam feed loads both for the first time and every time page is navigated to. /// If no WebcamHelper has been created, it creates one. Otherwise, simply restarts webcam preview feed on page. /// </summary> private async void WebcamFeed_Loaded(object sender, RoutedEventArgs e) { if (webcam == null || !webcam.IsInitialized()) { // Initialize Webcam Helper webcam = new WebcamHelper(); await webcam.InitializeCameraAsync(); // Set source of WebcamFeed on MainPage.xaml WebcamFeed.Source = webcam.mediaCapture; // Check to make sure MediaCapture isn't null before attempting to start preview. Will be null if no camera is attached. if (WebcamFeed.Source != null) { // Start the live feed await webcam.StartCameraPreview(); } } else if (webcam.IsInitialized()) { WebcamFeed.Source = webcam.mediaCapture; // Check to make sure MediaCapture isn't null before attempting to start preview. Will be null if no camera is attached. if (WebcamFeed.Source != null) { await webcam.StartCameraPreview(); } } }
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; }