public async Task<ImageAnalyzer> TakeAutoCapturePhoto() { var image = await CapturePhotoAsync(); this.autoCaptureState = AutoCaptureState.ShowingCapturedPhoto; this.OnAutoCaptureStateChanged(this.autoCaptureState); return image; }
private void OnAutoCaptureStateChanged(AutoCaptureState state) { if (this.AutoCaptureStateChanged != null) { this.AutoCaptureStateChanged(this, state); } }
public async Task <ImageAnalyzer> TakeAutoCapturePhoto() { var image = await CaptureFrameAsync(new CurrentFrameModel()); this.autoCaptureState = AutoCaptureState.ShowingCapturedPhoto; this.OnAutoCaptureStateChanged(this.autoCaptureState); return(image); }
private async void CameraControl_AutoCaptureStateChanged(object sender, AutoCaptureState e) { switch (e) { case AutoCaptureState.WaitingForFaces: this.cameraGuideBallon.Opacity = 1; this.cameraGuideText.Text = "Пожалуйста, встаньте перед камерой!"; await speech.Read(this.cameraGuideText.Text); this.cameraGuideHost.Opacity = 1; break; case AutoCaptureState.WaitingForStillFaces: this.cameraGuideText.Text = "Пожалуйста, не двигайтесь..."; break; case AutoCaptureState.ShowingCountdownForCapture: this.cameraGuideText.Text = ""; this.cameraGuideBallon.Opacity = 0; this.cameraGuideCountdownHost.Opacity = 1; this.countDownTextBlock.Text = "3"; await Task.Delay(350); this.countDownTextBlock.Text = "2"; await Task.Delay(350); this.countDownTextBlock.Text = "1"; await Task.Delay(350); this.cameraGuideCountdownHost.Opacity = 0; this.ProcessCameraCapture(await this.cameraControl.TakeAutoCapturePhoto()); break; case AutoCaptureState.ShowingCapturedPhoto: this.cameraGuideHost.Opacity = 0; break; default: break; } }
private async void CameraControl_AutoCaptureStateChanged(object sender, AutoCaptureState e) { switch (e) { case AutoCaptureState.WaitingForFaces: this.cameraGuideBallon.Opacity = 1; this.cameraGuideText.Text = "Step in front of the camera to start!"; this.cameraGuideHost.Opacity = 1; break; case AutoCaptureState.WaitingForStillFaces: this.cameraGuideText.Text = "Hold still..."; break; case AutoCaptureState.ShowingCountdownForCapture: this.cameraGuideText.Text = ""; this.cameraGuideBallon.Opacity = 0; this.cameraGuideCountdownHost.Opacity = 1; this.countDownTextBlock.Text = "3"; await Task.Delay(750); this.countDownTextBlock.Text = "2"; await Task.Delay(750); this.countDownTextBlock.Text = "1"; await Task.Delay(750); this.cameraGuideCountdownHost.Opacity = 0; this.ProcessCameraCapture(await this.cameraControl.TakeAutoCapturePhoto()); break; case AutoCaptureState.ShowingCapturedPhoto: this.cameraGuideHost.Opacity = 0; break; default: break; } }
private async void CameraControl_AutoCaptureStateChanged(object sender, AutoCaptureState e) { switch (e) { case AutoCaptureState.WaitingForFaces: this.cameraGuideBallon.Opacity = 1; this.cameraGuideText.Text = AppResourcesHelper.GetString("AutomaticPhotoCapturePage_Start.Text"); this.cameraGuideHost.Opacity = 1; break; case AutoCaptureState.WaitingForStillFaces: this.cameraGuideText.Text = AppResourcesHelper.GetString("AutomaticPhotoCapturePage_Hold"); break; case AutoCaptureState.ShowingCountdownForCapture: this.cameraGuideText.Text = ""; this.cameraGuideBallon.Opacity = 0; this.cameraGuideCountdownHost.Opacity = 1; this.countDownTextBlock.Text = "3"; await Task.Delay(750); this.countDownTextBlock.Text = "2"; await Task.Delay(750); this.countDownTextBlock.Text = "1"; await Task.Delay(750); this.cameraGuideCountdownHost.Opacity = 0; this.ProcessCameraCapture(await this.cameraControl.TakeAutoCapturePhoto()); break; case AutoCaptureState.ShowingCapturedPhoto: this.cameraGuideHost.Opacity = 0; break; default: break; } }
public void RestartAutoCaptureCycle() { this.autoCaptureState = AutoCaptureState.WaitingForFaces; this.OnAutoCaptureStateChanged(this.autoCaptureState); }
private async void UpdateAutoCaptureState(IEnumerable <DetectedFace> detectedFaces) { const int IntervalBeforeCheckingForStill = 500; const int IntervalWithoutFacesBeforeRevertingToWaitingForFaces = 3; if (!detectedFaces.Any()) { if (this.autoCaptureState == AutoCaptureState.WaitingForStillFaces && (DateTime.Now - this.lastTimeWhenAFaceWasDetected).TotalSeconds > IntervalWithoutFacesBeforeRevertingToWaitingForFaces) { this.autoCaptureState = AutoCaptureState.WaitingForFaces; await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.OnAutoCaptureStateChanged(this.autoCaptureState); }); } return; } this.lastTimeWhenAFaceWasDetected = DateTime.Now; switch (this.autoCaptureState) { case AutoCaptureState.WaitingForFaces: // We were waiting for faces and got some... go to the "waiting for still" state this.detectedFacesFromPreviousFrame = detectedFaces; this.timeSinceWaitingForStill = DateTime.Now; this.autoCaptureState = AutoCaptureState.WaitingForStillFaces; await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.OnAutoCaptureStateChanged(this.autoCaptureState); }); break; case AutoCaptureState.WaitingForStillFaces: // See if we have been waiting for still faces long enough if ((DateTime.Now - this.timeSinceWaitingForStill).TotalMilliseconds >= IntervalBeforeCheckingForStill) { // See if the faces are still enough if (this.AreFacesStill(this.detectedFacesFromPreviousFrame, detectedFaces)) { this.autoCaptureState = AutoCaptureState.ShowingCountdownForCapture; await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.OnAutoCaptureStateChanged(this.autoCaptureState); }); } else { // Faces moved too much, update the baseline and keep waiting this.timeSinceWaitingForStill = DateTime.Now; this.detectedFacesFromPreviousFrame = detectedFaces; } } break; case AutoCaptureState.ShowingCountdownForCapture: break; case AutoCaptureState.ShowingCapturedPhoto: break; default: break; } }
public void RestartAutoCaptureCycle() { CameraControlButtonClick(this, new RoutedEventArgs()); this.autoCaptureState = AutoCaptureState.WaitingForFaces; this.OnAutoCaptureStateChanged(this.autoCaptureState); }
private async void UpdateAutoCaptureState(IEnumerable <DetectedFace> detectedFaces) { const int IntervalBeforeCheckingForStill = 500; const int IntervalWithoutFacesBeforeRevertingToWaitingForFaces = 3; if (!detectedFaces.Any()) { if (this.autoCaptureState == AutoCaptureState.WaitingForStillFaces && (DateTime.Now - this.lastTimeWhenAFaceWasDetected).TotalSeconds > IntervalWithoutFacesBeforeRevertingToWaitingForFaces) { this.autoCaptureState = AutoCaptureState.WaitingForFaces; await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.OnAutoCaptureStateChanged(this.autoCaptureState); }); } return; } this.lastTimeWhenAFaceWasDetected = DateTime.Now; switch (this.autoCaptureState) { case AutoCaptureState.WaitingForFaces: // We were waiting for faces and got some... go to the "waiting for still" state this.detectedFacesFromPreviousFrame = detectedFaces; this.timeSinceWaitingForStill = DateTime.Now; this.autoCaptureState = AutoCaptureState.WaitingForStillFaces; await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.OnAutoCaptureStateChanged(this.autoCaptureState); }); break; case AutoCaptureState.WaitingForStillFaces: // See if we have been waiting for still faces long enough if ((DateTime.Now - this.timeSinceWaitingForStill).TotalMilliseconds >= IntervalBeforeCheckingForStill) { // See if the faces are still enough if (this.AreFacesStill(this.detectedFacesFromPreviousFrame, detectedFaces)) { this.autoCaptureState = AutoCaptureState.ShowingCountdownForCapture; await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.OnAutoCaptureStateChanged(this.autoCaptureState); // CAPTURE THE PHOTO DUDE!!!! //this.TakeAutoCapturePhoto(); this.CameraControlButtonClick(this, new RoutedEventArgs()); //// AFTER 10s RESET //var delay = Task.Delay(10000).ContinueWith(async _ => //{ // await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => // { // this.CameraControlButtonClick(this, new RoutedEventArgs()); // this.RestartAutoCaptureCycle(); // }); //}); }); } else { // Faces moved too much, update the baseline and keep waiting this.timeSinceWaitingForStill = DateTime.Now; this.detectedFacesFromPreviousFrame = detectedFaces; } } break; case AutoCaptureState.ShowingCountdownForCapture: break; case AutoCaptureState.ShowingCapturedPhoto: break; default: break; } }
private void OnAutoCaptureStateChanged(AutoCaptureState state) { this.AutoCaptureStateChanged?.Invoke(this, state); }
private async void UpdateAutoCaptureState(IEnumerable <DetectedFace> detectedFaces) { const int IntervalBeforeCheckingForStill = 500; const int IntervalWithoutFacesBeforeRevertingToWaitingForFaces = 3; if (!detectedFaces.Any()) { if (this.autoCaptureState == AutoCaptureState.WaitingForStillFaces && (DateTime.Now - this.lastTimeWhenAFaceWasDetected).TotalSeconds > IntervalWithoutFacesBeforeRevertingToWaitingForFaces) { this.autoCaptureState = AutoCaptureState.WaitingForFaces; await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.OnAutoCaptureStateChanged(this.autoCaptureState); }); } return; } this.lastTimeWhenAFaceWasDetected = DateTime.Now; switch (this.autoCaptureState) { case AutoCaptureState.WaitingForFaces: this.detectedFacesFromPreviousFrame = detectedFaces; this.timeSinceWaitingForStill = DateTime.Now; this.autoCaptureState = AutoCaptureState.WaitingForStillFaces; await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.OnAutoCaptureStateChanged(this.autoCaptureState); }); break; case AutoCaptureState.WaitingForStillFaces: if ((DateTime.Now - this.timeSinceWaitingForStill).TotalMilliseconds >= IntervalBeforeCheckingForStill) { if (this.AreFacesStill(this.detectedFacesFromPreviousFrame, detectedFaces)) { this.autoCaptureState = AutoCaptureState.ShowingCountdownForCapture; await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.OnAutoCaptureStateChanged(this.autoCaptureState); }); } else { this.timeSinceWaitingForStill = DateTime.Now; this.detectedFacesFromPreviousFrame = detectedFaces; } } break; case AutoCaptureState.ShowingCountdownForCapture: break; case AutoCaptureState.ShowingCapturedPhoto: break; default: break; } }