private async Task <bool> Init(IProgress <ManualRecogProgress> progress)
        {
            var initialized = true;

            _progress = progress;
            if (_camCts == null)
            {
                _camCts = new CancellationTokenSource();
            }

            if (_camEnumerator == null)
            {
                _camEnumerator = _captureService.CaptureFrames(_camCts.Token).GetAsyncEnumerator(_camCts.Token);
            }

            if (!_algService.Alghorithm.ManualRecog)
            {
                initialized = await _algService.Alghorithm.StartManualFaceRecog();
            }

            return(initialized);
        }
Пример #2
0
        private async Task StartInitFaceStep()
        {
            _camCts = new CancellationTokenSource();
            var  camEnumerator = _captureService.CaptureFrames(_camCts.Token).GetAsyncEnumerator(_camCts.Token);
            Task?stepEndTask   = null;

            while (await camEnumerator.MoveNextAsync())
            {
                using var frame = camEnumerator.Current;
                Application.Current.Dispatcher.Invoke(() => _vm.CallOnFrameChanged(frame.ToBitmapImage()));

                var rects = _faceDetection.DetectFrontalThenProfileFaces(frame);

                if (_startStep)
                {
                    if (rects.Length == 1)
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            _vm.HideOverlay();
                            _vm.StepStarted = true;
                        });

                        stepEndTask = await _profileInitService.InitFace(_authenticationService.User, camEnumerator,
                                                                         _camCts.Token);

                        _startStep = false;
                    }
                    else
                    {
                        if (!_stepCompleted)
                        {
                            Application.Current.Dispatcher.Invoke(() =>
                                                                  _vm.ShowOverlay(rects.Length > 1 ? "More than 1 face detected" : "Face not detected"));
                        }
                    }
                }


                if (rects.Length == 1)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        _vm.HideOverlay();
                        _vm.CallOnFaceDetected(rects.First());
                    });
                }
                else
                {
                    if (!_stepCompleted)
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            _vm.ShowOverlay(rects.Length > 1 ? "More than 1 face detected" : "Face not detected");
                            _vm.CallOnNoFaceDetected();
                        });
                    }
                }
            }

            if (stepEndTask != null)
            {
                await stepEndTask;
            }
        }