public async Task InitializeAsync()
        {
            try
            {
                IsLoading = true;

                if (FaceService == null)
                {
                    FaceService = await FaceServiceHelper.CreateNewFaceServiceAsync();
                }

                var personGroupResult = await FaceService.ListPersonGroupsAsync();

                personGroupResult.OrderBy(pg => pg.Name);
                personGroupResult.ForEach(pg => PersonGroups.Add(pg));

                IsLoading = false;
            }
            catch (FaceAPIException ex)//Handle API-Exception
            {
                await MessageDialogHelper.MessageDialogAsync(ex.ErrorMessage);
            }
            catch (Exception ex)
            {
                await MessageDialogHelper.MessageDialogAsync(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes face detection on the preview stream, from https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/scene-analysis-for-media-capture
        /// </summary>
        /// <returns></returns>
        public async Task InitializeFaceDetection()
        {
            // Load the face service client to to face recognition with Cognitive Services
            if (FaceService == null)
            {
                FaceService = await FaceServiceHelper.CreateNewFaceServiceAsync();
            }

            // Create the definition, which will contain some initialization settings
            var definition = new FaceDetectionEffectDefinition();

            // To ensure preview smoothness, do not delay incoming samples
            definition.SynchronousDetectionEnabled = false;

            // In this scenario, choose detection speed over accuracy
            definition.DetectionMode = FaceDetectionMode.HighPerformance;

            // Add the effect to the preview stream
            _faceDetectionEffect = (FaceDetectionEffect)await _mediaCapture.AddVideoEffectAsync(definition, MediaStreamType.VideoPreview);

            // TODO: Chance to a good frequency to save Cognitive Services API calls
            // Choose the shortest interval between detection events
            //_faceDetectionEffect.DesiredDetectionInterval = TimeSpan.FromMilliseconds(33);
            // Currently we offline detect faces every 3 seconds to save API calls
            _faceDetectionEffect.DesiredDetectionInterval = TimeSpan.FromMilliseconds(3000);

            // Start detecting faces
            _faceDetectionEffect.Enabled = true;

            // Register for face detection events
            _faceDetectionEffect.FaceDetected += FaceDetectionEffect_FaceDetected;

            _isDetecting = true;
        }
        public async Task InitializeAsync()
        {
            try
            {
                if (FaceService == null)
                {
                    FaceService = await FaceServiceHelper.CreateNewFaceServiceAsync();
                }

                //Load all facegroups
                _personGroups = await FaceService.ListPersonGroupsAsync();
            }
            catch (FaceAPIException ex)//Handle API-Exception
            {
                await MessageDialogHelper.MessageDialogAsync(ex.ErrorMessage);
            }
            catch (Exception ex)
            {
                await MessageDialogHelper.MessageDialogAsync(ex.Message);
            }

            startLoop();
        }
Exemplo n.º 4
0
        public async Task InitializeAsync()
        {
            try
            {
                IsLoading = true;

                if (FaceService == null)
                {
                    FaceService = await FaceServiceHelper.CreateNewFaceServiceAsync();
                }

                await LoadGroupsAsync();

                IsLoading = false;
            }
            catch (FaceAPIException ex)//Handle API-Exception
            {
                await MessageDialogHelper.MessageDialogAsync(ex.ErrorMessage);
            }
            catch (Exception ex)
            {
                await MessageDialogHelper.MessageDialogAsync(ex.Message);
            }
        }